typia
Version:
Superfast runtime validators with only one line
1 lines • 1.6 kB
Source Map (JSON)
{"version":3,"file":"__randomEpoch.mjs","names":[],"sources":["../../../src/internal/private/__randomEpoch.ts"],"sourcesContent":["import { _randomInteger } from \"../_randomInteger\";\n\nexport interface __IEpochProps {\n minimum?: number;\n maximum?: number;\n}\n\n/**\n * Draws an epoch millisecond inside the requested bounds.\n *\n * Shared by the `date` and `date-time` generators, which had the same bound\n * expression written twice: `props?.maximum ?? props?.minimum === undefined`\n * parses as `props?.maximum ?? (props?.minimum === undefined)` because `??`\n * binds looser than `===`, so any supplied `maximum` made the condition truthy\n * and was replaced by `Date.now()`, while `maximum: 0` fell through to\n * `undefined + one year` and produced `NaN` (issue #2287). Keeping the\n * resolution in one place is what stops the two copies from drifting again.\n *\n * With no bound at all the window ends at the present instant; with only a\n * lower bound it spans one year from there.\n */\nexport const __randomEpoch = (props?: __IEpochProps): number => {\n const minimum: number = props?.minimum ?? 0;\n const maximum: number =\n props?.maximum ??\n (props?.minimum === undefined ? Date.now() : props.minimum + YEAR);\n return _randomInteger({\n type: \"integer\",\n minimum,\n maximum,\n });\n};\n\nconst YEAR = 365 * 24 * 60 * 60 * 1_000;\n"],"mappings":";;;;;;;;;;;;;;;;AAqBA,MAAa,iBAAiB,UAAkC;CAK9D,OAAO,eAAe;EACpB,MAAM;EACN,SANsB,OAAO,WAAW;EAOxC,SALA,OAAO,YACN,OAAO,YAAY,KAAA,IAAY,KAAK,IAAI,IAAI,MAAM,UAAU;CAK/D,CAAC;AACH;AAEA,MAAM,OAAO,MAAM,KAAK,KAAK,KAAK"}