UNPKG

typia

Version:

Superfast runtime validators with only one line

27 lines 1.03 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports._randomString = void 0; const _randomInteger_1 = require("./_randomInteger"); const DEFAULT_MIN_LENGTH = 5; const DEFAULT_RANGE = 5; const _randomString = (props) => { var _a, _b, _c; const minimum = (_a = props.minLength) !== null && _a !== void 0 ? _a : Math.min((_b = props.maxLength) !== null && _b !== void 0 ? _b : DEFAULT_MIN_LENGTH, DEFAULT_MIN_LENGTH); const length = (0, _randomInteger_1._randomInteger)({ type: "integer", minimum, maximum: (_c = props.maxLength) !== null && _c !== void 0 ? _c : minimum + DEFAULT_RANGE, }); return new Array(length) .fill(0) .map(() => ALPHABETS[random()]) .join(""); }; exports._randomString = _randomString; const ALPHABETS = "abcdefghijklmnopqrstuvwxyz"; const random = () => (0, _randomInteger_1._randomInteger)({ type: "integer", minimum: 0, maximum: ALPHABETS.length - 1, }); //# sourceMappingURL=_randomString.js.map