parseBigInteger
Parses a value into a bigint. This parser uses the validateBigInteger primitive validator to ensure that the input is a bigint primitive. No normalization is performed.
The parser never throws and never mutates input. It returns a structured ParseResult<bigint> describing success or failure.
Signature
function parseBigInteger(
value: unknown,
field?: string
): ParseResult<bigint>
Behavior
- Accepted inputs:
- Bigint primitives (42n, 0n, -7n).
- Rejected inputs
- Number primitives (42).
- Numeric strings ("42").
- Boxed Number objects.
- Objects, arrays, functions.
- Booleans.
nullorundefined.- These produce: "Value must be a bigint"
Returns
A ParseResult<bigint> object:
ok: true: And the bigint when parsing succeeds.ok: false, value: null: And a list of issues when parsing fails.
Examples
parseBigInteger(42n)
// { ok: true, value: 42n, issues: [] }
parseBigInteger("42")
// { ok: false, value: null, issues: ["Value must be a bigint"] }
Notes
- This parser is intentionally strict: no coercion from strings or numbers.
- For integer parsing with coercion, use parseInteger.