Installed parser tuple, used to infer specifications and results.
Creates a parser with exactly the supplied codecs, or an empty registry.
Installed parser tuple, used to infer specifications and results.
Codec tuple, default locale (en-US), and application context.
index!DuplicateFormatError for duplicate codec kinds.
Validates and freezes a specification for repeated parsing.
Later edits to the original specification have no effect. The returned
parse method is bound and safe to pass as a callback. Specifications may
contain primitives, plain records, and arrays; class instances, functions,
and accessors are rejected. A successful compile always provides parse.
Specification to copy and resolve with this parser's defaults.
A frozen parser with spec, successful resolution, and bound parse.
import { formatter } from "@neutrium/formatter";
import { parser } from "@neutrium/formatter/parse";
const thousands = formatter.compileSeries([900, 1200], {
kind: "number", notation: "compact", maximumFractionDigits: 1,
});
const inputs = parser.compile(thousands.spec);
["0.9K", "1.2K"].map(inputs.parse); // ["900", "1200"]
Parses one complete localized string into the selected codec's result type.
Built-in numeric and elapsed-duration parsers return canonical decimal
strings, preserving exact digits while removing presentation padding. Parsing
recovers displayed precision: "1.23M" represents "1230000". Grouping,
affixes, signs, and scales must match the specification. Surrounding whitespace
is tolerated after an exact presentation match is attempted.
Complete localized text, not a string containing an embedded number.
The presentation and locale used to produce or accept the text.
A canonical string for built-ins, or the custom parser's result type.
index!UnknownFormatError if no parser is installed for the kind.
parse!UnsupportedParseError if a presentation is not parseable.
import { parser } from "@neutrium/formatter/parse";
parser.parse("1.234,50", { kind: "number", locale: "de-DE" }); // "1234.5"
parser.parse("12.5%", { kind: "percentage", maximumFractionDigits: 1 }); // "0.125"
try {
parser.parse("12,34.5", { kind: "number" }); // invalid en-US grouping
} catch (error) {
console.error(error instanceof Error ? error.message : String(error));
}
Inspects parsing support, returning a serializable error for a rejected specification.
Check supported before reading success-only fields. Rendering capabilities
are always false; use a formatter's resolve to inspect formatting separately.
Complete specification to inspect.
A successful resolution or the reason parsing is unavailable.
import { parser } from "@neutrium/formatter/parse";
const spec = { kind: "duration", presentation: "localized" } as const;
const result = parser.resolve(spec);
if (!result.supported) {
console.error(`This display cannot be used as an editable duration: ${result.error.message}`);
}
Checks whether a complete specification can be parsed on this runtime. This checks options and available codecs, not the validity of an input string. Use resolve when the failure reason is needed.
Specification to inspect, including required domain options.
false for unknown kinds, invalid options, or unsupported presentations.
Returns an independent parser with one additional codec, preserving locale and context.
Parser for a kind not already installed on this instance.
A new parser whose inferred types include the added codec.
index!DuplicateFormatError if the kind is already registered.
Parses localized text using the codecs installed on this instance.
Most applications should use parse!parser or parse!createParser, which include every built-in parser. Direct construction creates an empty registry unless codecs are supplied. Locale and application context are independent of any formatter instance; compiled specifications carry their bound locale.
Example: Create an isolated number parser