Skip to content

Number is unsafe integer

numberIsUnsafeInteger is a built‑in scan rule that detects integers that fall outside JavaScript’s safe integer range (from -(2^53‑1) to +(2^53‑1)).

When the value is a number, is an integer, and Number.isSafeInteger(raw) returns false, the rule emits a warn‑level number.not.safe-integer scan event containing the original value. If the value is not a number, not an integer, or is a safe integer, no events are emitted.

Signature

export const numberIsUnsafeInteger: ScanRule (raw: unknown, path: FieldPath) => JaneEvent[]

Events

Event code Description
number.not.safe-integer Integer is outside JavaScript’s safe integer range.

Design rationale

  • Detects whole numbers that cannot be represented precisely using JavaScript’s IEEE‑754 number type.
  • Surfaces precision‑loss hazards early in the scan stage.
  • Uses Number.isInteger() and Number.isSafeInteger() to ensure accurate classification.
  • Emits a warning when the integer exceeds the safe range.
  • Prevents downstream logic from assuming reliable comparisons or arithmetic.
  • Provides metadata ({ value }) for policy and analysis.
  • Performs no mutation or transformation of the input.

Invoke

numberIsUnsafeInteger runs automatically whenever the scan stage is enabled.

Activation methods:

  • Enable scan explicitly: jane.value(input).scan().
  • Use a mode that enables scan:
  • strict() enables scan by default.
  • moderate() and lax() do not enable scan unless .scan() is called.
  • Enable scan with policy: jane.value(input).withPolicy({ mode: 'strict' }).

If scan is not enabled, numberIsUnsafeInteger does not run and no unsafe‑integer detection occurs.

Examples

Unsafe integer detected

const result = numberIsUnsafeInteger(2 ** 60, "$");
// → [ JaneEvent{ kind: "warn", code: "number.not.safe-integer", ... } ]

Safe integer

const result = numberIsUnsafeInteger(9007199254740991, "$");
// → []

Non‑number value

const result = numberIsUnsafeInteger("123", "$");
// → []