isValidNanoseconds
Signature
Section titled “Signature”isValidNanoseconds(value: unknown): value is bigintValidate 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 byfromNanoseconds. Reach for it beforetruncateNanoseconds, whose0nreturn is both a legitimate result and the invalid-input sentinel. - Requires a
bigint. Anumberis rejected outright rather than coerced: nanoseconds since the epoch passedNumber.MAX_SAFE_INTEGERin April 1970, so anumbercannot carry one exactly and silently accepting it would defeat the namespace. - The range is ±8_640_000_000_000_000_000_000n — what
Temporal.Instantcan represent. - A span is not an epoch nanosecond value.
spanNsreaches twice this range, because it measures a duration rather than naming an instant. Do not validate one with this.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
value | unknown | candidate epoch-nanosecond value |
Returns
Section titled “Returns”boolean indicating whether the value is an in-range epoch-nanosecond bigint
Examples
Section titled “Examples”import { isValidNanoseconds } from "@northguild/gmt/precision/validate";
isValidNanoseconds(0n) // true — the epoch