@jsonjoy.com/json-type
Version:
High-performance JSON Pointer implementation
41 lines • 1.23 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.unknown = exports.Value = void 0;
const printTree_1 = require("tree-dump/lib/printTree");
const printJson_1 = require("tree-dump/lib/printJson");
const copyForPrint = (data) => {
if (typeof data === 'function')
return '__fN---';
if (Array.isArray(data))
return data.map(copyForPrint);
if (data && typeof data === 'object') {
const res = {};
for (const k in data)
res[k] = copyForPrint(data[k]);
return res;
}
return data;
};
class Value {
constructor(data, type) {
this.data = data;
this.type = type;
}
name() {
return 'Value';
}
toString(tab = '') {
const type = this.type;
return (this.name() +
(type
? (0, printTree_1.printTree)(tab, [
(tab) => type.toString(tab),
(tab) => (0, printJson_1.printJson)(tab, copyForPrint(this.data)).replace(/"__fN---"/g, 'fn()'),
])
: ''));
}
}
exports.Value = Value;
const unknown = (data) => new Value(data);
exports.unknown = unknown;
//# sourceMappingURL=Value.js.map