UNPKG

ts-logs

Version:

This package provide a skd for audit and manager logs in nodejs and express

49 lines 1.93 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DeleteObjectKey = void 0; /** * @description Remove keys from an object or array of objects. * @param body as object or array of objects. * @param keys as array of string. * @returns body as object or array without removed keys. */ const DeleteObjectKey = (body, keys) => { if (!Array.isArray(keys)) return body; if (Array.isArray(body)) { return body.map((val) => (0, exports.DeleteObjectKey)(val, keys)); } if (body && typeof body === 'object' && !(body instanceof Date) && keys.length > 0) { let result = {}; const objectKeys = Object.keys(body); let currentObjectKeyIndex = 0; while (objectKeys[currentObjectKeyIndex]) { const currentKey = objectKeys[currentObjectKeyIndex]; if (keys.includes(currentKey)) { currentObjectKeyIndex++; continue; } ; const value = body[currentKey]; if (Array.isArray(value)) { const arr = value.map((val) => (0, exports.DeleteObjectKey)(val, keys)); result = Object.assign({}, result, { [currentKey]: arr }); currentObjectKeyIndex++; continue; } if (value && typeof value === 'object' && !(value instanceof Date)) { const subObj = (0, exports.DeleteObjectKey)(value, keys); result = Object.assign({}, result, { [currentKey]: subObj }); currentObjectKeyIndex++; continue; } result = Object.assign({}, result, { [currentKey]: value }); currentObjectKeyIndex++; } return result; } return body; }; exports.DeleteObjectKey = DeleteObjectKey; exports.default = exports.DeleteObjectKey; //# sourceMappingURL=delete-object-key.util.js.map