UNPKG

typia

Version:

Superfast runtime validators with only one line

26 lines 1.57 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports._randomFormatRelativeJsonPointer = void 0; const _randomInteger_1 = require("./_randomInteger"); const _randomString_1 = require("./_randomString"); const _randomStringLength_1 = require("./_randomStringLength"); const __randomComposition_1 = require("./private/__randomComposition"); const _randomFormatRelativeJsonPointer = (props) => { if ((props === null || props === void 0 ? void 0 : props.minLength) === undefined && (props === null || props === void 0 ? void 0 : props.maxLength) === undefined) return `${(0, _randomInteger_1._randomInteger)({ type: "integer", minimum: 0, maximum: 10 })}#`; // The leading non-negative integer stands alone as a pointer, so a single // digit is the shortest form; `#` names the key and a `/`-prefixed token names // a member, which absorbs any remaining length. const length = (0, _randomStringLength_1._randomLengthPick)((0, _randomStringLength_1._randomLengthWindow)(props, { minimum: 1, spread: 6 })); if (length === 1) return (0, __randomComposition_1.__randomNumeric)(1); if (length === 2) return `${(0, __randomComposition_1.__randomNumeric)(1)}#`; return `${(0, __randomComposition_1.__randomNumeric)(1)}/${(0, _randomString_1._randomString)({ type: "string", minLength: length - 2, maxLength: length - 2, })}`; }; exports._randomFormatRelativeJsonPointer = _randomFormatRelativeJsonPointer; //# sourceMappingURL=_randomFormatRelativeJsonPointer.js.map