src/util/num.ts — integers at the boundaries
Purpose
Section titled “Purpose”The numeric rules every argument boundary shares, and the one duration format every surface prints, in one place.
export const MAX_TIMEOUT_MS = 2 ** 31 - 1clampInt(n, min, max): numberparseDecimalInt(input): number | nullformatElapsed(ms, minutes?): stringMAX_TIMEOUT_MSis the largest delaysetTimeouthonours (~24.8 days). A larger one does not saturate and does not throw — it silently becomes 1 ms, the inverse of what was asked: a task declaring a 317-year timeout would be SIGTERMed 4 ms after it spawns. Every surface that accepts a millisecond delay bounds against it.clampIntfloors to an integer in[min, max]; non-finite collapses tomin. The floor is load-bearing wherever the result reaches SQL: a fractionalLIMITis adatatype mismatch, not a smaller page.parseDecimalIntaccepts a plain decimal integer only.Number()at an argument boundary accepts hex, exponents, fractions, a leading+and whitespace, so a typo becomes a different number instead of an error; values pastMAX_SAFE_INTEGERparse to a number the user did not type and are rejected too.formatElapsedis a duration as vx prints it:12ms,1.23s, and withminutes(vx last)2m 5s. The value is rounded to the unit shown before the unit is chosen: 999.6 ms printed1000msand 119,600 ms1m 60s(item 1034).
clampInt is re-exported from @vzn/vx for plugins that bound their
own arguments; parseDecimalInt is not.
tests/util-num.test.ts; tests/timeout-bounds.test.ts (every
timeout surface against the ceiling); tests/options-resolve.test.ts.