Skip to content

Parse integer string

parseIntegerString parses strict integer string literals into numeric values.

It rejects floats, scientific notation, leading‑zero formats, and any non‑digit characters. If the value is not a string, does not match the integer literal pattern, or does not produce a valid integer, the rule emits no parse result.

Signature

Through the API:

.parse('integer');

And internally:

export const parseIntegerString: ParseRule<unknown>
(value: unknown, path: FieldPath) => ParseResult<unknown>[]

Events

Event code Description
string.now.integer Parsed string into an integer value.

Design rationale

  • Accepts only canonical integer literals:
  • Optional leading -.
  • Digits only.
  • No whitespace, decimals, separators, or scientific notation.
  • Rejects ambiguous formats such as "01", "1.0", "1e3", " 42 ", or "4_000".
  • Ensures contributors can rely on strict, predictable integer parsing.
  • Produces a single parse step containing the parsed integer and one parseEvent.
  • Never guesses, normalizes, or coerces — parsing is explicit and opt‑in.

Invoke

parseIntegerString runs only when explicitly included in a boundary or pipeline. It is not affected by normalization mode and does not run automatically.

The rule activates when:

  • The value is a string.
  • The string matches the strict integer pattern: /^-?\d+$/.
  • Number(value) produces a valid integer.

Examples

Valid integer strings

parseIntegerString("42", "$");
// → [
//     {
//       path: "$",
//       nextValue: 42,
//       events: [
//         JaneEvent{ kind: "info", code: "string.now.integer", ... }
//       ]
//     }
//   ]

parseIntegerString("-7", "$");
// → [
//     {
//       path: "$",
//       nextValue: -7,
//       events: [ JaneEvent{ code: "string.now.integer", ... } ]
//     }
//   ]

Invalid formats — no parse

parseIntegerString("01", "$");     // → []
parseIntegerString("1.0", "$");    // → []
parseIntegerString("1e3", "$");    // → []
parseIntegerString(" 42 ", "$");   // → []
parseIntegerString("4_000", "$");  // → []

Non‑string value

parseIntegerString(42, "$"); // → []