UNPKG

@platform/cell.schema

Version:

URI and database schemas for the `cell.os`.

33 lines (32 loc) 1.04 kB
import { isUndefinedOrEmptyObject, defaultValue } from '../common'; export const squash = { props(props) { return squash.object(props); }, cell(cell, options = {}) { const empty = defaultValue(options.empty, undefined); if (!cell) { return empty; } else { const res = Object.assign({}, cell); Object.keys(res) .filter(key => isUndefinedOrEmptyObject(res[key])) .forEach(key => delete res[key]); return squash.object(res, options); } }, object(obj, options = {}) { const empty = defaultValue(options.empty, undefined); if (!obj) { return empty; } else { const res = Object.assign({}, obj); Object.keys(res) .filter(key => isUndefinedOrEmptyObject(res[key])) .forEach(key => delete res[key]); return isUndefinedOrEmptyObject(res, { ignoreHash: true }) ? empty : res; } }, };