UNPKG

@amaui/utils

Version:
35 lines (34 loc) 1.43 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.removeObjectValue = void 0; const is_1 = __importDefault(require("./is")); const castParam_1 = __importDefault(require("./castParam")); const removeObjectValue = (object, keys) => { if (!(object || keys)) return object; if ((0, is_1.default)('string', keys)) { const keys_ = keys.split('.').filter(Boolean).map(key => (0, castParam_1.default)(key)); return (0, exports.removeObjectValue)(object, keys_); } if ((0, is_1.default)('array', keys)) { const key = keys[0]; // If object or array doesn't have the above key // then there's no point in moving forward if (object.hasOwnProperty(key)) { if (keys.length === 1) { if ((0, is_1.default)('array', object) && (0, is_1.default)('number', key)) object.splice(key, 1); if ((0, is_1.default)('object', object) && (0, is_1.default)('string', key)) delete object[key]; } else (0, exports.removeObjectValue)(object[key], keys.slice(1)); } } return object; }; exports.removeObjectValue = removeObjectValue; exports.default = exports.removeObjectValue;