UNPKG

typia

Version:

Superfast runtime validators with only one line

22 lines (21 loc) 1.05 kB
import { _RANDOM_LENGTH_ERROR, _randomLengthPick, _randomLengthWindow } from "./_randomStringLength.mjs"; import { __randomEpoch } from "./private/__randomEpoch.mjs"; import { __randomDigits } from "./private/__randomComposition.mjs"; //#region src/internal/_randomFormatDatetime.ts const _randomFormatDatetime = (props) => { const instant = () => new Date(__randomEpoch(props)).toISOString(); if (props?.minLength === void 0 && props?.maxLength === void 0) return instant(); const window = _randomLengthWindow(props, { minimum: SECONDS + 1, spread: 8 }); let length = _randomLengthPick(window); if (length === SECONDS + 2) length = window.high >= SECONDS + 3 ? SECONDS + 3 : SECONDS + 1; if (length < window.low || length > window.high) throw new Error(_RANDOM_LENGTH_ERROR); const base = instant().substring(0, SECONDS); return length === SECONDS + 1 ? `${base}Z` : `${base}.${__randomDigits(length - SECONDS - 2)}Z`; }; const SECONDS = 19; //#endregion export { _randomFormatDatetime }; //# sourceMappingURL=_randomFormatDatetime.mjs.map