UNPKG

@jsonjoy.com/json-type

Version:

High-performance JSON Pointer implementation

45 lines (44 loc) 1.3 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.random = random; const tslib_1 = require("tslib"); const gen = tslib_1.__importStar(require("./generators")); /** * Main router function that dispatches to the correct random generator based on the type's kind. * This replaces the individual random() methods in each type class. */ function random(type) { const kind = type.getTypeName(); switch (kind) { case 'any': return gen.any(type); case 'arr': return gen.arr(type); case 'bin': return gen.bin(type); case 'bool': return gen.bool(type); case 'con': return gen.const_(type); case 'fn': case 'fn$': return gen.fn(type); case 'map': return gen.map(type); case 'num': return gen.num(type); case 'obj': return gen.obj(type); case 'or': return gen.or(type); case 'ref': return gen.ref(type); case 'str': return gen.str(type); case 'tup': return gen.tup(type); default: // Fallback to generic random JSON for unknown types return gen.any(type); } }