Number is NaN¶
numberIsNaN is a built‑in scan rule that detects numeric values that resolve to NaN.
When the value is a number and Number.isNaN(raw) returns true, the rule emits a warn‑level number.not.number scan event containing the original value. If the value is not a number or is a valid numeric value, no events are emitted.
Signature¶
export const numberIsNaN: ScanRule (raw: unknown, path: FieldPath) => JaneEvent[]
Events¶
| Event code | Description |
|---|---|
number.not.number |
Numeric value resolves to NaN. |
Design rationale¶
- Detects
NaN, which is structurally a number but semantically unusable. - Surfaces arithmetic failures, invalid parsing, and unexpected coercions early in the scan stage.
- Uses
Number.isNaN()to ensure preciseNaNdetection. - Emits a warning when the value is
NaN. - Prevents downstream logic from assuming a valid numeric value.
- Provides metadata (
{ value }) for policy and analysis. - Performs no mutation or transformation of the input.
Invoke¶
numberIsNaN runs automatically whenever the scan stage is enabled.
- Enable scan explicitly:
jane.value(input).scan(). - Use a mode that enables scan:
strict()enables scan by default.moderate()andlax()do not enable scan unless.scan()is called.- Enable scan with policy:
jane.value(input).withPolicy({ mode: 'strict' }).
If scan is not enabled or the value is not structurally a number, numberIsNaN does not run and no NaN detection occurs.
Examples¶
NaN detected¶
const result = numberIsNaN(NaN, "$");
// → [ JaneEvent{ kind: "warn", code: "number.not.number", ... } ]
Valid number¶
const result = numberIsNaN(42, "$");
// → []
Non‑number value¶
const result = numberIsNaN("NaN", "$");
// → []