UNPKG

@jsonjoy.com/json-type

Version:

High-performance JSON Pointer implementation

66 lines 2.12 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ArrType = void 0; const tslib_1 = require("tslib"); const tree_dump_1 = require("tree-dump"); const schema = tslib_1.__importStar(require("../../schema")); const AbsType_1 = require("./AbsType"); class ArrType extends AbsType_1.AbsType { constructor(_type, _head, _tail, options) { super(schema.s.Array(schema.s.any, options)); this._type = _type; this._head = _head; this._tail = _tail; } head(...head) { this._head = head; return this; } tail(...tail) { this._tail = tail; return this; } min(min) { this.schema.min = min; return this; } max(max) { this.schema.max = max; return this; } getSchema(ctx) { const schema = { ...this.schema, }; const { _type, _head, _tail } = this; if (_type) schema.type = _type.getSchema(ctx); if (_head) schema.head = _head.map((t) => t.getSchema(ctx)); if (_tail) schema.tail = _tail.map((t) => t.getSchema(ctx)); return schema; } getOptions() { // biome-ignore lint: unused variables are intentional const { kind, type, ...options } = this.schema; return options; } toString(tab = '') { const { _head, _type, _tail } = this; return (super.toString(tab) + (0, tree_dump_1.printTree)(tab, [ _head && _head.length ? (tab) => '[ head, ... ]' + (0, tree_dump_1.printTree)(tab, _head.map((t) => (tab) => t.toString(tab))) : null, _type ? (tab) => (_type ? _type.toString(tab) : '...') : null, _tail && _tail.length ? (tab) => '[ ..., tail ]' + (0, tree_dump_1.printTree)(tab, _tail.map((t) => (tab) => t.toString(tab))) : null, ])); } } exports.ArrType = ArrType; //# sourceMappingURL=ArrType.js.map