Skip to content

Infinity to undefined

infinityToUndefined is a built‑in normalization rule that converts Infinity and -Infinity into undefined.

This prevents non‑finite numeric values from leaking into downstream validators, scanners, or policy layers, where they cannot be represented or compared safely.

If the value is not a number, or the number is finite, no normalization step is emitted.

Signature

export const infinityToUndefined: NormalizationRule<unknown>
(value: unknown, mode: NormalizationMode, path: FieldPath) => NormalizationStep[]

Events

Event code Description
number.now.undefined Infinite numeric value was converted.

Design rationale

  • Removes only non‑finite numeric values (Infinity, -Infinity).
  • Prevents serialization failures and unsafe comparisons in downstream layers.
  • Treats infinite values as semantically equivalent to "no usable numeric value".
  • Emits a normalization step only when the input is infinite.
  • Classified as lossy normalization — the original value is discarded.
  • Addresses values originating from math operations, division by zero, or external APIs that surface infinite results.

Invoke

infinityToUndefined runs automatically when:

  • The value is structurally a number.
  • The normalization stage is active.
  • The current mode allows lossy normalization.

Mode behavior:

  • strict: Rule does not run (lossy).
  • moderate: Rule does not run (lossy).
  • lax: Rule runs.

Normalization cannot be invoked manually. It is always applied automatically based on structural type and mode.

Examples

Infinite value converted to undefined

const value = Infinity;

const result = infinityToUndefined(value, "lax", "$");
// → [
//     {
//       path: "$",
//       nextValue: undefined,
//       lossy: "lossy",
//       events: [
//         JaneEvent{ kind: "info", code: "number.now.undefined", ... }
//       ]
//     }
//   ]

Finite number — no normalization

const result = infinityToUndefined(42, "lax", "$");
// → []

Non‑number value

const result = infinityToUndefined("not a number", "lax", "$");
// → []