Skip to content

isValidNanoseconds

isValidNanoseconds(value: unknown): value is bigint

Validate whether a value is an epoch-nanosecond bigint the precision/ namespace accepts.

  • Every precision/ function gates on this range, so anything it accepts is renderable by fromNanoseconds. Reach for it before truncateNanoseconds, whose 0n return is both a legitimate result and the invalid-input sentinel.
  • Requires a bigint. A number is rejected outright rather than coerced: nanoseconds since the epoch passed Number.MAX_SAFE_INTEGER in April 1970, so a number cannot carry one exactly and silently accepting it would defeat the namespace.
  • The range is ±8_640_000_000_000_000_000_000n — what Temporal.Instant can represent.
  • A span is not an epoch nanosecond value. spanNs reaches twice this range, because it measures a duration rather than naming an instant. Do not validate one with this.
ParameterTypeDescription
valueunknowncandidate epoch-nanosecond value

boolean indicating whether the value is an in-range epoch-nanosecond bigint

import { isValidNanoseconds } from "@northguild/gmt/precision/validate";
isValidNanoseconds(0n) // true — the epoch
output 

precision/validate/isValidNanoseconds.ts