@neutrium/formatter - v1.0.1
    Preparing search index...

    Interface ParseCodec<Kind, Spec, Value>

    Defines how one application-specific domain is parsed.

    Register it with !createParser or extensions-parse!Parser.withCodec. Share the specification type with your formatting codec, but import this type from @neutrium/formatter/extensions/parse. The parser must validate the entire input and throw when it cannot return a valid value; the registry does not validate its result.

    import { createParser } from "@neutrium/formatter/parse";
    import { type ParseCodec } from "@neutrium/formatter/extensions/parse";

    const statusParser = {
    kind: "status",
    parse(input) {
    if (input === "Enabled") return true;
    if (input === "Disabled") return false;
    throw new TypeError("Expected Enabled or Disabled");
    },
    } satisfies ParseCodec<"status", { kind: "status" }, boolean>;

    const statuses = createParser({ codecs: [statusParser] });
    statuses.parse("Enabled", { kind: "status" }); // true, inferred as boolean
    statuses.parse("1,234", { kind: "number" }); // "1234" — built-ins remain available
    interface ParseCodec<
        Kind extends string = string,
        Spec extends FormatSpecBase = FormatSpecBase,
        Value = unknown,
    > {
        kind: Kind;
        parse(input: string, spec: Spec, context: FormatContext): Value;
        resolve?(spec: Spec, context: FormatContext): CodecFormatResolution;
    }

    Type Parameters

    • Kind extends string = string

      Literal discriminator selecting this parser.

    • Spec extends FormatSpecBase = FormatSpecBase

      Accepted specification, including domain-specific options.

    • Value = unknown

      Result returned by parsing; it need not be numeric.

    Index
    kind: Kind

    Unique discriminator matched against the specification's kind.