| 1 | 'use strict';
|
|---|
| 2 |
|
|---|
| 3 | Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|---|
| 4 |
|
|---|
| 5 | const cloneDeepWith = require('./cloneDeepWith.js');
|
|---|
| 6 | const keysIn = require('./keysIn.js');
|
|---|
| 7 | const unset = require('./unset.js');
|
|---|
| 8 | const getSymbolsIn = require('../_internal/getSymbolsIn.js');
|
|---|
| 9 | const isDeepKey = require('../_internal/isDeepKey.js');
|
|---|
| 10 | const flatten = require('../array/flatten.js');
|
|---|
| 11 | const isPlainObject = require('../predicate/isPlainObject.js');
|
|---|
| 12 |
|
|---|
| 13 | function omit(obj, ...keysArr) {
|
|---|
| 14 | if (obj == null) {
|
|---|
| 15 | return {};
|
|---|
| 16 | }
|
|---|
| 17 | keysArr = flatten.flatten(keysArr);
|
|---|
| 18 | const result = cloneInOmit(obj, keysArr);
|
|---|
| 19 | for (let i = 0; i < keysArr.length; i++) {
|
|---|
| 20 | let keys = keysArr[i];
|
|---|
| 21 | switch (typeof keys) {
|
|---|
| 22 | case 'object': {
|
|---|
| 23 | if (!Array.isArray(keys)) {
|
|---|
| 24 | keys = Array.from(keys);
|
|---|
| 25 | }
|
|---|
| 26 | for (let j = 0; j < keys.length; j++) {
|
|---|
| 27 | const key = keys[j];
|
|---|
| 28 | unset.unset(result, key);
|
|---|
| 29 | }
|
|---|
| 30 | break;
|
|---|
| 31 | }
|
|---|
| 32 | case 'string':
|
|---|
| 33 | case 'symbol':
|
|---|
| 34 | case 'number': {
|
|---|
| 35 | unset.unset(result, keys);
|
|---|
| 36 | break;
|
|---|
| 37 | }
|
|---|
| 38 | }
|
|---|
| 39 | }
|
|---|
| 40 | return result;
|
|---|
| 41 | }
|
|---|
| 42 | function cloneInOmit(obj, keys) {
|
|---|
| 43 | const hasDeepKey = keys.some(key => Array.isArray(key) || isDeepKey.isDeepKey(key));
|
|---|
| 44 | if (hasDeepKey) {
|
|---|
| 45 | return deepCloneInOmit(obj);
|
|---|
| 46 | }
|
|---|
| 47 | return shallowCloneInOmit(obj);
|
|---|
| 48 | }
|
|---|
| 49 | function shallowCloneInOmit(obj) {
|
|---|
| 50 | const result = {};
|
|---|
| 51 | const keysToCopy = [...keysIn.keysIn(obj), ...getSymbolsIn.getSymbolsIn(obj)];
|
|---|
| 52 | for (let i = 0; i < keysToCopy.length; i++) {
|
|---|
| 53 | const key = keysToCopy[i];
|
|---|
| 54 | result[key] = obj[key];
|
|---|
| 55 | }
|
|---|
| 56 | return result;
|
|---|
| 57 | }
|
|---|
| 58 | function deepCloneInOmit(obj) {
|
|---|
| 59 | const result = {};
|
|---|
| 60 | const keysToCopy = [...keysIn.keysIn(obj), ...getSymbolsIn.getSymbolsIn(obj)];
|
|---|
| 61 | for (let i = 0; i < keysToCopy.length; i++) {
|
|---|
| 62 | const key = keysToCopy[i];
|
|---|
| 63 | result[key] = cloneDeepWith.cloneDeepWith(obj[key], valueToClone => {
|
|---|
| 64 | if (isPlainObject.isPlainObject(valueToClone)) {
|
|---|
| 65 | return undefined;
|
|---|
| 66 | }
|
|---|
| 67 | return valueToClone;
|
|---|
| 68 | });
|
|---|
| 69 | }
|
|---|
| 70 | return result;
|
|---|
| 71 | }
|
|---|
| 72 |
|
|---|
| 73 | exports.omit = omit;
|
|---|