UNPKG

typia

Version:

Superfast runtime validators with only one line

31 lines 1.54 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.__randomEpoch = void 0; const _randomInteger_1 = require("../_randomInteger"); /** * 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) => { var _a, _b; const minimum = (_a = props === null || props === void 0 ? void 0 : props.minimum) !== null && _a !== void 0 ? _a : 0; const maximum = (_b = props === null || props === void 0 ? void 0 : props.maximum) !== null && _b !== void 0 ? _b : ((props === null || props === void 0 ? void 0 : props.minimum) === undefined ? Date.now() : props.minimum + YEAR); return (0, _randomInteger_1._randomInteger)({ type: "integer", minimum, maximum, }); }; exports.__randomEpoch = __randomEpoch; const YEAR = 365 * 24 * 60 * 60 * 1000; //# sourceMappingURL=__randomEpoch.js.map