Skip to content

isValidNanoPattern

isValidNanoPattern(value: string): boolean

Validate whether a string is a nanosecond timestamp parseNanoseconds will parse.

  • parseNanoseconds returns 0n for both "0" and garbage, so this is how the two are told apart — the check its own JSDoc asks callers to make.
  • Shape and range: a canonical decimal integer (optional -, digits, no leading zeros) that also falls inside what Temporal.Instant can represent. Shape alone is nanosecondDecimal in regex/.
  • Length is checked before BigInt, so an arbitrarily long payload string is rejected rather than converted.
  • Takes the string value, not JSON text — JSON.parse(payload).observedAt, not the payload. A quoted "\"123\"" is not a decimal integer.
  • Returns false for non-strings.
ParameterTypeDescription
valuestringcandidate decimal string form of a nanosecond timestamp

boolean indicating whether parseNanoseconds will parse it

import { isValidNanoPattern } from "@northguild/gmt/precision/validate";
isValidNanoPattern("1710072000123456789") // true
output 

precision/validate/isValidNanoPattern.ts