UNPKG

typia

Version:

Superfast runtime validators with only one line

28 lines (27 loc) 1.15 kB
import { _randomInteger } from "../_randomInteger.mjs"; //#region src/internal/private/__randomEpoch.ts /** * Draws an epoch millisecond inside the requested bounds. * * Shared by the `date` and `date-time` generators, which had the same bound * expression written twice: `props?.maximum ?? props?.minimum === undefined` * parses as `props?.maximum ?? (props?.minimum === undefined)` because `??` * binds looser than `===`, so any supplied `maximum` made the condition truthy * and was replaced by `Date.now()`, while `maximum: 0` fell through to * `undefined + one year` and produced `NaN` (issue #2287). Keeping the * resolution in one place is what stops the two copies from drifting again. * * With no bound at all the window ends at the present instant; with only a * lower bound it spans one year from there. */ const __randomEpoch = (props) => { return _randomInteger({ type: "integer", minimum: props?.minimum ?? 0, maximum: props?.maximum ?? (props?.minimum === void 0 ? Date.now() : props.minimum + YEAR) }); }; const YEAR = 365 * 24 * 60 * 60 * 1e3; //#endregion export { __randomEpoch }; //# sourceMappingURL=__randomEpoch.mjs.map