template-transformer
Version:
Transform jsons using templates
35 lines • 1.1 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.compact = void 0;
function isObject(val) {
return Object === val.constructor;
}
function compact($, keysThatMustExist = [], dropValues = [undefined]) {
if (Array.isArray($)) {
$ = $.filter((o) => dropValues.indexOf(o) === -1);
if ($.length > 0)
return $;
}
else if ($ && isObject($)) {
if ((keysThatMustExist === null || keysThatMustExist === void 0 ? void 0 : keysThatMustExist.length) > 0) {
for (let key of keysThatMustExist) {
if (dropValues.indexOf($[key]) !== -1)
return;
}
}
const newObj = {};
for (key in $) {
if (dropValues.indexOf($[key]) === -1)
newObj[key] = $[key];
}
for (var key in newObj) {
if (dropValues.indexOf($[key]) === -1)
return newObj;
}
}
else if (dropValues.indexOf($) === -1) {
return $;
}
}
exports.compact = compact;
//# sourceMappingURL=compact.js.map