UNPKG

typia

Version:

Superfast runtime validators with only one line

27 lines 1.58 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports._randomFormatJsonPointer = void 0; const _randomString_1 = require("./_randomString"); const _randomStringLength_1 = require("./_randomStringLength"); const _randomFormatJsonPointer = (props) => { if ((props === null || props === void 0 ? void 0 : props.minLength) === undefined && (props === null || props === void 0 ? void 0 : props.maxLength) === undefined) return `${PREFIX}${random()}`; // The `/components/schemas/` prefix (20 chars) is fixed; the reference token // after it grows or shrinks to hit the requested length. if (props.maxLength === undefined || props.maxLength >= PREFIX.length) return `${PREFIX}${(0, _randomStringLength_1._randomSegmentLength)(props, PREFIX.length, 10, 0)}`; // Below that prefix a pointer still exists: the empty pointer addresses the // whole document, and one `/`-prefixed token addresses a member of it. const length = (0, _randomStringLength_1._randomLengthPick)((0, _randomStringLength_1._randomLengthWindow)(props, { minimum: 0, spread: 6 })); return length === 0 ? "" : `/${(0, _randomString_1._randomString)({ type: "string", minLength: length - 1, maxLength: length - 1, })}`; }; exports._randomFormatJsonPointer = _randomFormatJsonPointer; const PREFIX = "/components/schemas/"; const random = () => (0, _randomString_1._randomString)({ type: "string", minLength: 10, maxLength: 10 }); //# sourceMappingURL=_randomFormatJsonPointer.js.map