Skip to content

isValidUnixRange

isValidUnixRange(props: { value1: string | number; value2: string | number; options?: { allowEqual?: boolean; }; }): boolean

Return true if value1 and value2 form a valid Unix range — both safe-integer epochs and value1 < value2 (or <= with allowEqual).

  • Each input must be a safe integer (Number.isSafeInteger) or a string of optionally negative ASCII digits naming one — the epoch grammar every unix/ function shares.
  • Fractional values, NaN, ±Infinity and anything beyond ±(2^53 − 1) return false.
  • Strings with whitespace, +, a decimal point, an exponent or hex digits return false, and an empty string is not epoch 0.

props

the two epoch values and the settings for the check

OptionTypeDefaultDescription
value1string | numberRequiredThe start of the range: a Unix epoch in seconds or milliseconds, as a safe integer or a digit string.
value2string | numberRequiredThe end of the range, in the same form and unit as value1.
options?objectNone. Equal values are not a valid range.The settings for the comparison. It must be an object or omitted; any other value, null included, returns false.
options.allowEqual?booleanfalseWhether value1 equal to value2 is a valid range. false requires value1 to be before value2.

boolean indicating whether the Unix range is valid

import { isValidUnixRange } from "@northguild/gmt/unix/validate";
isValidUnixRange({ value1: 0, value2: 1700000000 }) // true
output 

unix/validate/isValidUnixRange.ts