Bigint negative¶
bigintNegative validates that a value is a string representing a strictly negative BigInt.
It enforces strict bigint‑string semantics: the value must be a string, must parse successfully as a BigInt literal, and must be strictly less than 0n. If any condition fails, the rule emits a single validation event. Otherwise, it produces no validation output.
Signature¶
Through the API:
.bigintNegative();
And internally:
export const bigintNegative: ValidationRule
(value: unknown, path: FieldPath) => Promise<ReadonlyArray<JaneEvent>>
Events¶
| Event code | Description |
|---|---|
bigint.not.string |
Value is not a string. |
bigint.not.bigint |
String is not a valid bigint literal. |
bigint.not.negative |
Parsed bigint is greater than or equal to zero. |
Design rationale¶
- Enforces strict bigint‑string validation with no coercion or normalization.
- Rejects non‑string values early with a structural‑type diagnostic.
- Treats empty strings and malformed literals as invalid bigint values.
- Uses JavaScript’s
BigInt()constructor for canonical parsing. - Ensures negativity is explicit: only values < 0n are accepted.
- Emits exactly one event per failure for clarity and composability.
- Pure, total, async‑compatible, and returns a readonly array of
JaneEventobjects. - Preserves the provided path and supports pipeline‑level userMessage overrides.
Invoke¶
bigintNegative runs only when explicitly included in a boundary or pipeline. It does not run automatically.
The rule activates when:
- The value is any JavaScript value.
- If the value is not a string → emits bigint.not.string.
- If the string is empty or cannot be parsed by BigInt → emits bigint.not.bigint.
- If the parsed bigint is greater than or equal to 0n → emits bigint.not.negative.
- Otherwise → returns an empty result set.
Examples¶
Valid — negative bigint string¶
await bigintNegative("-42", "$");
// → []
Invalid — not a string¶
await bigintNegative(123, "$");
// → [
// JaneEvent{
// kind: "error",
// code: "bigint.not.string",
// path: "$",
// ...
// }
// ]
Invalid — malformed bigint literal¶
await bigintNegative("01", "$");
// → [
// JaneEvent{
// kind: "error",
// code: "bigint.not.bigint",
// path: "$",
// ...
// }
// ]
Invalid — bigint is zero or positive¶
await bigintNegative("0", "$");
// → [
// JaneEvent{
// kind: "error",
// code: "bigint.not.negative",
// path: "$",
// ...
// }
// ]
await bigintNegative("42", "$");
// → [
// JaneEvent{
// kind: "error",
// code: "bigint.not.negative",
// path: "$",
// ...
// }
// ]