UNPKG

clickable-json

Version:

Interactive JSON and JSON CRDT viewer and editor

42 lines 1.4 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.isContainer = exports.createValue = exports.id = void 0; const id = (node) => { const id = node.node.id; return id.sid + '.' + id.time; }; exports.id = id; const createValue = (model, json, type, constOrJson) => { let value = json; try { value = JSON.parse(json); } catch (_a) { } const api = model.api; const builder = api.builder; const valueId = type === 'any' ? constOrJson ? builder.constOrJson(value) : builder.json(value) : type === 'con' ? api.builder.const(value) : type === 'vec' ? api.builder.vec() : type === 'val' ? api.builder.val() : api.builder.const(undefined); if (type === 'vec') { if (json) { const valueVec = Array.isArray(value) ? value : [value]; builder.insVec(valueId, valueVec.map((x, i) => [i, api.builder.maybeConst(x)])); } } else if (type === 'val') { builder.setVal(valueId, json ? api.builder.maybeConst(value) : api.builder.const(undefined)); } return valueId; }; exports.createValue = createValue; const isContainer = (value) => !!value && typeof value === 'object'; exports.isContainer = isContainer; //# sourceMappingURL=utils.js.map