Finite¶
finite validates that a number is finite (not Infinity, -Infinity, or NaN).
It enforces strict numeric validation and rejects any non-number value or non-finite number. If the value is not a number or is not finite, the rule emits a single validation event. Otherwise, it produces no validation output.
Signature¶
Through the API:
.finite()
And internally:
export const finite: ValidationRule
(value: unknown, path: FieldPath) => Promise<ReadonlyArray<JaneEvent>>
Events¶
| Event code | Description |
|---|---|
type.not.valid |
Value is not structurally a number |
number.not.finite |
Number is Infinity, -Infinity, or NaN |
Design rationale¶
- Provides a strict, predictable finite number validation.
- Rejects infinite values and NaN explicitly.
- Rejects non-number values with a clear structural-type diagnostic.
- Never coerces or normalizes — validation is explicit and opt-in.
- Emits exactly one event per failure for clarity and composability.
- Async-compatible and returns a readonly array of
JaneEventobjects.
Invoke¶
finite 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 number, emits
type.not.valid. - If the value is a number but not finite, emits
number.not.finite. - If the value is a finite number → returns an empty result set.
Examples¶
Valid finite number¶
await finite(42, "$");
// → []
Infinity¶
await finite(Infinity, "$");
// → [
// JaneEvent{
// kind: "error",
// code: "number.not.finite",
// path: "$",
// ...
// }
// ]
Non-number value¶
await finite("42", "$");
// → [
// JaneEvent{
// kind: "error",
// code: "type.not.valid",
// path: "$",
// ...
// }
// ]