UNPKG

@northguild/gmt

Version:

Date and time library for JavaScript and TypeScript, built on TC39 Temporal: time zones, DST, business days, ISO 8601 strings in and out. Never throws.

46 lines • 1.98 kB
/** * 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. * * @param props the two epoch values and the settings for the check * @returns boolean indicating whether the Unix range is valid * * @example isValidUnixRange({ value1: 0, value2: 1700000000 }) // true * @example isValidUnixRange({ value1: 1000, value2: 1000, options: { allowEqual: true } }) // true * @example isValidUnixRange({ value1: 1700000000, value2: 0 }) // false (reversed) * @example isValidUnixRange({ value1: 0, value2: 1.5 }) // false (fractional) * @example isValidUnixRange({ value1: "", value2: 1000 }) // false (empty string is not epoch 0) * @example isValidUnixRange({ value1: "0", value2: "1e3" }) // false (exponent notation is not an epoch) */ export declare function isValidUnixRange(props: { /** * The start of the range: a Unix epoch in seconds or milliseconds, as a safe integer or a digit * string. */ value1: number | string; /** * The end of the range, in the same form and unit as `value1`. */ value2: number | string; /** * The settings for the comparison. It must be an object or omitted; any other value, `null` * included, returns `false`. * * @defaultValue None. Equal values are not a valid range. */ options?: { /** * Whether `value1` equal to `value2` is a valid range. `false` requires `value1` to be * before `value2`. * * @defaultValue `false` */ allowEqual?: boolean; }; }): boolean;