JavaScript / TypeScript API

Settings and configuration

Shared runtime settings are exposed through nerdamer.set(...) and nerdamer.get(...). Settings affect subsequent operations, so application code that changes a setting temporarily should restore its previous value when it is finished.

import nerdamer from 'nerdamer';

nerdamer.set('USE_SINGLE_LETTER_VARIABLES', true);
console.log(nerdamer('2ab').text()); // 2*a*b

Several settings can also be changed together:

nerdamer.set({
  ALLOW_IMPLICIT_MULTIPLICATION: false,
  INDEX_BASE: 1
});
Shared state: these settings are not local to a single expression. Changing one affects later calls that use the same runtime. If a setting is changed only temporarily, save its previous value and restore it when the operation is finished.

Notation and indexing

These settings directly change how Nerdamer Notation is interpreted. The Expression syntax page shows them in context.

SettingDefaultEffect
ALLOW_IMPLICIT_MULTIPLICATIONtrueAllows multiplication to be inferred in forms such as 2x, x(9), and (a+b)(c+d). Set it to false when input should require an explicit *.
USE_SINGLE_LETTER_VARIABLESfalseTreats adjacent letters as separate variables when enabled. For example, ab is interpreted as a*b. Registered function names are still recognized as functions.
INDEX_BASE0Controls the public index base used by vector and matrix access. Use 0 for zero-based indexing or 1 for one-based indexing.

Evaluation, substitution, and expression handling

SettingDefaultEffect
EVALUATEfalseEnables numerical evaluation paths used by constants, functions, powers, and other operations that can produce a numerical value.
SUBSTITUTEtrueAllows values stored in the shared variable state to substitute automatically during parsing.
SORT_TERMSfalseSorts expression terms during text conversion. The default avoids the additional sorting work unless ordered output is requested.
ALLOW_RAT_SUBSfalseAllows substitution matching to use non-integer rational multipliers where the substitution routine can support them.
Per-call term ordering: prefer expression.text({ sort: true }) when only one rendered result needs conventional term ordering. That option does not change SORT_TERMS globally. See Text output and public helpers.

Localized error messages

The LANGUAGE setting selects among the error-message catalogs included in the current Nerdamer build. English is the default.

Supported language catalog

LanguageCodeNotes
EnglishengDefault catalog.
SpanishspaSpanish error messages.
FrenchfraFrench error messages.
GermandeuGerman error messages.
PortugueseporPortuguese error messages.
ItalianitaItalian error messages.
DutchnldDutch error messages.
Catalogs must be included at build time: the default browser bundle contains only eng. Setting LANGUAGE does not load another catalog at runtime. A targeted build such as --env language=spa,fra contains English, Spanish, and French; it starts with Spanish selected and allows runtime switching among those included catalogs. To switch freely among every supported language, build with --env language=all. See Language-targeted browser builds.

When the requested catalog is included in the build, set it before running the operation whose errors should use that language:

import nerdamer from 'nerdamer';

const previousLanguage = nerdamer.get('LANGUAGE');

try {
  nerdamer.set('LANGUAGE', 'spa');

  try {
    nerdamer('0^0');
  }
  catch (error) {
    if (error instanceof Error) {
      console.log(error.message);
      // ¡0^0 no está definido!

    }
  }
}
finally {
  nerdamer.set('LANGUAGE', previousLanguage);
}
Error text only: changing LANGUAGE selects an error-message catalog that is already present in the build. It does not load a catalog, translate Nerdamer Notation, translate function names, or translate the JavaScript / TypeScript API.

The language setting is shared just like the other runtime settings. If an application changes it temporarily, restore the previous value when that operation is finished.

Typed parser consumers can also import the supported language type. The Language type describes the supported catalog codes; the selected catalog must still be included in the build:

import type { Language } from 'nerdamer/parser';

const language: Language = 'fra';
nerdamer.set('LANGUAGE', language);

Limits and numeric precision

SettingDefaultEffect
MAX_PRODUCT_AND_SUMMATION_ITERATION10000Limits direct finite iteration performed by sum and product. Larger ranges can remain symbolic instead of being expanded term by term.
MAX_LOOP_ITERATIONS10000Limits completed iterations in Nerdamer Scripting control-flow loops.
MAX_FRAC_INTBigInt(1e60)Caps integer sizes used by exact root extraction paths so very large numerator or denominator values do not trigger impractical work.
LANGUAGE'eng'Selects an error-message catalog that is included in the current build.
PRECISIONcurrent numeric precisionControls the shared arbitrary-precision decimal setting and keeps finite-precision values of pi and e synchronized. PRECISION is handled specially by the root nerdamer.set/get API.

Direct parser access

If you import the parser API directly, the same shared settings can be read and changed with Parser.get(...) and Parser.set(...). Precision uses the parser's dedicated precision methods.

Language catalogs: Parser.set('LANGUAGE', ...) has the same build-time requirement as nerdamer.set('LANGUAGE', ...). The default browser build contains only eng; selecting another language requires a bundle built with that catalog, a comma-separated subset containing it, or language=all.
import { Parser } from 'nerdamer/parser';

Parser.set('INDEX_BASE', 1);
Parser.set('LANGUAGE', 'deu');

const base = Parser.get('INDEX_BASE');
const language = Parser.get('LANGUAGE');

Parser.setPrecision(40);
const precision = Parser.getPrecision();

Reserved settings

The following setting names are present in the current API but do not currently change Nerdamer's behavior. Do not rely on them until they are documented as active settings.

SettingCurrent default
USE_FRACTIONStrue
ALLOW_BIGINTtrue
REWRITE_SQRTtrue
IMMUTABLE_VALUE_SETStrue
INITIALIZE_RULEStrue

Code should not rely on those names changing behavior unless they acquire an active runtime use in a later release.