UNPKG

@newdash/newdash

Version:

javascript/typescript utility library

61 lines (60 loc) 2.24 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.omit = void 0; const arrayMap_1 = __importDefault(require("./.internal/arrayMap")); const baseClone_1 = __importDefault(require("./.internal/baseClone")); const baseUnset_1 = __importDefault(require("./.internal/baseUnset")); const castPath_1 = __importDefault(require("./.internal/castPath")); const CONSTANTS_1 = require("./.internal/CONSTANTS"); const copyObject_1 = __importDefault(require("./.internal/copyObject")); const flatRest_1 = __importDefault(require("./.internal/flatRest")); const getAllKeysIn_1 = __importDefault(require("./.internal/getAllKeysIn")); const isPlainObject_1 = __importDefault(require("./isPlainObject")); /** * Used by `_.omit` to customize its `_.cloneDeep` use to only clone plain * objects. * * @internal * @ignore * @private * @param value The value to inspect. * @param key The key of the property to inspect. * @returns Returns the uncloned value or `undefined` to defer cloning to `_.cloneDeep`. */ function customOmitClone(value) { return (0, isPlainObject_1.default)(value) ? undefined : value; } /** * @internal * @ignore * @private */ const internalOmit = (0, flatRest_1.default)((object, paths) => { let result = {}; if (object == null) { return result; } let isDeep = false; paths = (0, arrayMap_1.default)(paths, (path) => { path = (0, castPath_1.default)(path, object); isDeep || (isDeep = path.length > 1); return path; }); (0, copyObject_1.default)(object, (0, getAllKeysIn_1.default)(object), result); if (isDeep) { result = (0, baseClone_1.default)(result, CONSTANTS_1.CLONE_DEEP_FLAG | CONSTANTS_1.CLONE_FLAT_FLAG | CONSTANTS_1.CLONE_SYMBOLS_FLAG, customOmitClone); } let length = paths.length; while (length--) { (0, baseUnset_1.default)(result, paths[length]); } return result; }); function omit(object, ...paths) { return object == null ? {} : internalOmit(object, ...paths); } exports.omit = omit; exports.default = omit;