Optionaloptions: CreateFormatterOptions<readonly []>
Default locale (en-US), application context, and additional codecs.
A formatter with all built-ins and the additional codecs' inferred types.
index!DuplicateFormatError for duplicate kinds, including built-in kinds.
import { createFormatter } from "@neutrium/formatter";
const german = createFormatter({ locale: "de-DE" });
german.format(1234.5, { kind: "number" });
// "1.234,5"
import { createFormatter } from "@neutrium/formatter";
import type { FormatCodec } from "@neutrium/formatter/extensions";
const labelCodec = {
kind: "label",
format(value: string) {
return [{ type: "literal", value }];
},
} satisfies FormatCodec<"label", string>;
const custom = createFormatter({ codecs: [labelCodec] });
custom.format("ready", { kind: "label" });
// "ready"
Creates an independent, strongly typed formatter.
Built-in codecs are always included. Custom codecs are appended in tuple
order and participate in specification, value, rounded metadata, and compiled
capability inference. Use new Formatter({ codecs }) for an isolated registry.
Parsing is configured separately with parse!createParser.
Default locale (en-US), application context, and additional codecs.
A formatter with all built-ins and the additional codecs' inferred types.
index!DuplicateFormatError for duplicate kinds, including built-in kinds.
import { createFormatter } from "@neutrium/formatter";
const german = createFormatter({ locale: "de-DE" });
german.format(1234.5, { kind: "number" });
// "1.234,5"
import { createFormatter } from "@neutrium/formatter";
import type { FormatCodec } from "@neutrium/formatter/extensions";
const labelCodec = {
kind: "label",
format(value: string) {
return [{ type: "literal", value }];
},
} satisfies FormatCodec<"label", string>;
const custom = createFormatter({ codecs: [labelCodec] });
custom.format("ready", { kind: "label" });
// "ready"
Creates an independent, strongly typed formatter.
Built-in codecs are always included. Custom codecs are appended in tuple order and participate in specification, value, rounded metadata, and compiled capability inference. Use
new Formatter({ codecs })for an isolated registry. Parsing is configured separately with parse!createParser.