Parse bigint string¶
parseBigIntString parses canonical decimal bigint literals into actual bigint values.
It enforces a strict digits‑only format with an optional leading minus and rejects any ambiguous or non‑canonical input. If the value is not a string, does not match the bigint literal pattern, or cannot be parsed by BigInt, the rule emits no parse result.
Signature¶
Through the API:
.parse('bigint');
And internally:
export const parseBigIntString: ParseRule<unknown>
= (value: unknown, path: FieldPath) => ParseResult<unknown>[]
Events¶
| Event code | Description |
|---|---|
string.now.bigint |
Parsed string into a bigint value. |
Design rationale¶
- Accepts only canonical decimal bigint literals:
- Optional leading
-. - Digits only
- No whitespace, formatting, or separators
- Rejects ambiguous formats such as
"01"," 123 ","1_000","1n", or"1.0". - Ensures contributors can rely on strict, predictable bigint parsing.
- Produces a single parse step containing the parsed bigint and one
parseEvent. - Never guesses, normalizes, or coerces — parsing is explicit and opt‑in.
Invoke¶
parseBigIntString runs only when explicitly included in a boundary or pipeline. It does not run automatically and all parsing is blocked in strict mode.
The rule activates when:
- The value is a string.
- The string matches the bigint literal pattern:
/^-?\d+$/. BigInt(value)succeeds.
Examples¶
Note
When scan() is enabled, all bigint values are automatically converted to strings for security purposes, so manual conversion is unnecessary.
Valid bigint string¶
const value = "12345678901234567890";
const result = parseBigIntString(value, "$");
// → [
// {
// path: "$",
// nextValue: 12345678901234567890n,
// events: [
// JaneEvent{ kind: "info", code: "string.now.bigint", ... }
// ]
// }
// ]
Negative bigint¶
const result = parseBigIntString("-42", "$");
// → [
// {
// path: "$",
// nextValue: -42n,
// events: [ JaneEvent{ code: "string.now.bigint", ... } ]
// }
// ]
Invalid format — no parse¶
parseBigIntString("01", "$"); // → []
parseBigIntString("1_000", "$"); // → []
parseBigIntString("1n", "$"); // → []
parseBigIntString("1.0", "$"); // → []
Non‑string value¶
parseBigIntString(123, "$"); // → []