UNPKG

@tabular-json/tabular-json

Version:

Tabular-JSON: a superset of JSON with CSV-like tables

35 lines 974 B
// The utils are largely copied from: // - https://github.com/josdejong/csv42 export function isObject(value) { return typeof value === 'object' && value !== null && value.constructor === Object; // do not match on classes or Array } export function getIn(object, path) { let value = object; let i = 0; while (i < path.length && value !== undefined) { value = value?.[path[i]]; i++; } return value; } export function setIn(object, path, value) { let nested = object; const iLast = path.length - 1; let i = 0; while (i < iLast) { const part = path[i]; if (nested[part] === undefined) { if (typeof path[i + 1] === 'number') { nested[part] = []; } else { nested[part] = {}; } } nested = nested[part]; i++; } nested[path[iLast]] = value; return object; } //# sourceMappingURL=objects.js.map