@jsopen/objects 1.1.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/cjs/index.js +1 -1
- package/cjs/merge.js +36 -23
- package/cjs/omit.js +28 -49
- package/cjs/tsconfig-build-cjs.tsbuildinfo +1 -1
- package/cjs/{is-built-in.js → type-guards.js} +16 -0
- package/esm/index.js +1 -1
- package/esm/merge.js +36 -23
- package/esm/omit.js +27 -49
- package/esm/tsconfig-build-esm.tsbuildinfo +1 -1
- package/esm/{is-built-in.js → type-guards.js} +13 -0
- package/package.json +1 -1
- package/types/index.d.cts +1 -1
- package/types/index.d.ts +1 -1
- package/types/omit.d.ts +4 -4
- package/types/type-guards.d.ts +5 -0
- package/types/is-built-in.d.ts +0 -1
package/CHANGELOG.md
CHANGED
package/cjs/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
tslib_1.__exportStar(require("./clone.js"), exports);
|
|
5
|
-
tslib_1.__exportStar(require("./is-built-in.js"), exports);
|
|
6
5
|
tslib_1.__exportStar(require("./is-object.js"), exports);
|
|
7
6
|
tslib_1.__exportStar(require("./merge.js"), exports);
|
|
8
7
|
tslib_1.__exportStar(require("./omit.js"), exports);
|
|
8
|
+
tslib_1.__exportStar(require("./type-guards.js"), exports);
|
package/cjs/merge.js
CHANGED
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.merge = merge;
|
|
4
4
|
exports.getMergeFunction = getMergeFunction;
|
|
5
5
|
const is_object_js_1 = require("./is-object.js");
|
|
6
|
+
const type_guards_js_1 = require("./type-guards.js");
|
|
6
7
|
function merge(target, source, options) {
|
|
7
8
|
if (!((0, is_object_js_1.isObject)(target) || typeof target === 'function')) {
|
|
8
9
|
throw new TypeError('"target" argument must be an object');
|
|
@@ -12,7 +13,7 @@ function merge(target, source, options) {
|
|
|
12
13
|
throw new TypeError('"target" argument must be an object');
|
|
13
14
|
}
|
|
14
15
|
const fn = getMergeFunction(options);
|
|
15
|
-
return fn(target, source, '', options, fn,
|
|
16
|
+
return fn(target, source, '', options, fn, type_guards_js_1.isBuiltIn, is_object_js_1.isObject, is_object_js_1.isPlainObject, arrayClone);
|
|
16
17
|
}
|
|
17
18
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
18
19
|
const functionCache = new Map();
|
|
@@ -49,14 +50,15 @@ function buildMerge(options) {
|
|
|
49
50
|
'curPath',
|
|
50
51
|
'options',
|
|
51
52
|
'mergeFunction',
|
|
52
|
-
'
|
|
53
|
+
'isBuiltIn',
|
|
53
54
|
'isObject',
|
|
55
|
+
'isPlainObject',
|
|
54
56
|
'arrayClone',
|
|
55
57
|
];
|
|
56
58
|
const scriptL0 = [
|
|
57
59
|
`
|
|
58
60
|
const _merge = (_trgVal, _srcVal, _curPath) =>
|
|
59
|
-
mergeFunction(_trgVal, _srcVal, _curPath, options, mergeFunction,
|
|
61
|
+
mergeFunction(_trgVal, _srcVal, _curPath, options, mergeFunction, isBuiltIn, isObject, isPlainObject, arrayClone);
|
|
60
62
|
const keys = Object.getOwnPropertyNames(source);
|
|
61
63
|
keys.push(...Object.getOwnPropertySymbols(source));
|
|
62
64
|
let key;
|
|
@@ -66,7 +68,7 @@ let trgVal;
|
|
|
66
68
|
`,
|
|
67
69
|
];
|
|
68
70
|
if (options?.deep) {
|
|
69
|
-
scriptL0.push(`let subPath;`, `let
|
|
71
|
+
scriptL0.push(`let subPath;`, `let _isArray;`);
|
|
70
72
|
if (typeof options?.deep === 'function') {
|
|
71
73
|
scriptL0.push(`const deepCallback = options.deep;`);
|
|
72
74
|
}
|
|
@@ -84,6 +86,7 @@ let trgVal;
|
|
|
84
86
|
scriptL0.push(`const moveArraysCallback = options.moveArrays;`);
|
|
85
87
|
}
|
|
86
88
|
scriptL0.push(`
|
|
89
|
+
if (isPlainObject(target)) Object.setPrototypeOf(target, Object.getPrototypeOf(source));
|
|
87
90
|
let i = 0;
|
|
88
91
|
const len = keys.length;
|
|
89
92
|
for (i = 0; i < len; i++) {
|
|
@@ -133,7 +136,7 @@ if (
|
|
|
133
136
|
srcVal = source[key];`);
|
|
134
137
|
}
|
|
135
138
|
else {
|
|
136
|
-
scriptL1For.push(`descriptor = {enumerable: true, configurable: true, writable: true}`, `srcVal =
|
|
139
|
+
scriptL1For.push(`descriptor = {enumerable: true, configurable: true, writable: true}`, `srcVal = source[key];`);
|
|
137
140
|
}
|
|
138
141
|
/** ************* keepExisting *****************/
|
|
139
142
|
if (options?.keepExisting) {
|
|
@@ -147,36 +150,32 @@ if (
|
|
|
147
150
|
if (options?.ignoreNulls) {
|
|
148
151
|
scriptL1For.push(`if (srcVal === null) continue;`);
|
|
149
152
|
}
|
|
153
|
+
const deepArray = !options?.moveArrays || typeof options?.moveArrays === 'function';
|
|
150
154
|
/** ************* deep *****************/
|
|
151
155
|
if (options?.deep) {
|
|
152
|
-
|
|
153
|
-
|
|
156
|
+
if (deepArray) {
|
|
157
|
+
scriptL1For.push(`
|
|
154
158
|
_isArray = Array.isArray(srcVal);
|
|
155
|
-
if (
|
|
159
|
+
if (_isArray || (typeof srcVal === 'object' && !isBuiltIn(srcVal))) {`);
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
scriptL1For.push(`
|
|
163
|
+
if (typeof srcVal === 'object' && !isBuiltIn(srcVal)) {
|
|
164
|
+
subPath = curPath + (curPath ? '.' : '') + key;`);
|
|
165
|
+
}
|
|
166
|
+
scriptL1For.push(`subPath = curPath + (curPath ? '.' : '') + key;`);
|
|
156
167
|
const scriptL2Deep = [];
|
|
157
168
|
scriptL1For.push(scriptL2Deep);
|
|
158
169
|
scriptL1For.push('}');
|
|
159
170
|
let scriptL3Deep = scriptL2Deep;
|
|
160
171
|
if (typeof options?.deep === 'function') {
|
|
161
172
|
scriptL2Deep.push(`
|
|
162
|
-
subPath = curPath + (curPath ? '.' : '') + key;
|
|
163
173
|
if (deepCallback(key, subPath, target, source)) {`);
|
|
164
174
|
scriptL3Deep = [];
|
|
165
175
|
scriptL2Deep.push(scriptL3Deep);
|
|
166
176
|
scriptL2Deep.push('}');
|
|
167
177
|
}
|
|
168
|
-
/** *************
|
|
169
|
-
scriptL3Deep.push(`
|
|
170
|
-
if (_isPlain) {
|
|
171
|
-
trgVal = target[key];
|
|
172
|
-
if (!isObject(trgVal)) {
|
|
173
|
-
descriptor.value = trgVal = {};
|
|
174
|
-
Object.defineProperty(target, key, descriptor);
|
|
175
|
-
}
|
|
176
|
-
_merge(trgVal, srcVal, subPath, options);
|
|
177
|
-
continue;
|
|
178
|
-
}`);
|
|
179
|
-
/** ************* moveArrays *****************/
|
|
178
|
+
/** ************* Array *****************/
|
|
180
179
|
if (!options?.moveArrays || typeof options?.moveArrays === 'function') {
|
|
181
180
|
scriptL3Deep.push(`if (_isArray) {`);
|
|
182
181
|
const scriptL4IsArray = [];
|
|
@@ -184,7 +183,12 @@ if (_isPlain) {
|
|
|
184
183
|
scriptL3Deep.push('}');
|
|
185
184
|
let scriptL5CloneArrays = scriptL4IsArray;
|
|
186
185
|
if (typeof options?.moveArrays === 'function') {
|
|
187
|
-
scriptL4IsArray.push(`
|
|
186
|
+
scriptL4IsArray.push(`
|
|
187
|
+
if (moveArraysCallback(key, subPath, target, source)) {
|
|
188
|
+
descriptor.value = srcVal;
|
|
189
|
+
Object.defineProperty(target, key, descriptor);
|
|
190
|
+
continue;
|
|
191
|
+
} else {`);
|
|
188
192
|
scriptL5CloneArrays = [];
|
|
189
193
|
scriptL4IsArray.push(scriptL5CloneArrays);
|
|
190
194
|
scriptL4IsArray.push('}');
|
|
@@ -195,6 +199,15 @@ Object.defineProperty(target, key, descriptor);
|
|
|
195
199
|
continue;
|
|
196
200
|
`);
|
|
197
201
|
}
|
|
202
|
+
/** ************* object *****************/
|
|
203
|
+
scriptL3Deep.push(`
|
|
204
|
+
trgVal = target[key];
|
|
205
|
+
if (!isObject(trgVal)) {
|
|
206
|
+
descriptor.value = trgVal = {};
|
|
207
|
+
Object.defineProperty(target, key, descriptor);
|
|
208
|
+
}
|
|
209
|
+
_merge(trgVal, srcVal, subPath, options);
|
|
210
|
+
continue;`);
|
|
198
211
|
}
|
|
199
212
|
/** ************* finalize *****************/
|
|
200
213
|
scriptL1For.push(`
|
|
@@ -209,7 +222,7 @@ function arrayClone(arr, _merge, curPath) {
|
|
|
209
222
|
return arr.map((x) => {
|
|
210
223
|
if (Array.isArray(x))
|
|
211
224
|
return arrayClone(x, _merge, curPath);
|
|
212
|
-
if ((0,
|
|
225
|
+
if (typeof x === 'object' && !(0, type_guards_js_1.isBuiltIn)(x))
|
|
213
226
|
return _merge({}, x, curPath);
|
|
214
227
|
return x;
|
|
215
228
|
});
|
package/cjs/omit.js
CHANGED
|
@@ -1,60 +1,39 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.omit = omit;
|
|
3
4
|
exports.omitUndefined = omitUndefined;
|
|
4
5
|
exports.omitNull = omitNull;
|
|
5
6
|
exports.omitNullish = omitNullish;
|
|
6
|
-
const
|
|
7
|
+
const merge_js_1 = require("./merge.js");
|
|
8
|
+
function omit(obj, keys) {
|
|
9
|
+
const keysSet = new Set(keys);
|
|
10
|
+
return (0, merge_js_1.merge)({}, obj, {
|
|
11
|
+
deep: false,
|
|
12
|
+
filter(key) {
|
|
13
|
+
return !keysSet.has(key);
|
|
14
|
+
},
|
|
15
|
+
});
|
|
16
|
+
}
|
|
7
17
|
function omitUndefined(obj, deep) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
v = obj[k];
|
|
14
|
-
if (v === undefined)
|
|
15
|
-
delete obj[k];
|
|
16
|
-
else if (deep) {
|
|
17
|
-
if (Array.isArray(v))
|
|
18
|
-
v.forEach(x => omitUndefined(x, deep));
|
|
19
|
-
else if ((0, is_object_js_1.isPlainObject)(v))
|
|
20
|
-
omitUndefined(obj[k], deep);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
return obj;
|
|
18
|
+
return (0, merge_js_1.merge)({}, obj, {
|
|
19
|
+
deep,
|
|
20
|
+
ignoreUndefined: true,
|
|
21
|
+
copyDescriptors: true,
|
|
22
|
+
});
|
|
24
23
|
}
|
|
25
24
|
function omitNull(obj, deep) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
if (v === null)
|
|
33
|
-
delete obj[k];
|
|
34
|
-
else if (deep) {
|
|
35
|
-
if (Array.isArray(v))
|
|
36
|
-
v.forEach(x => omitNull(x, deep));
|
|
37
|
-
else if ((0, is_object_js_1.isPlainObject)(v))
|
|
38
|
-
omitNull(obj[k], deep);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
return obj;
|
|
25
|
+
return (0, merge_js_1.merge)({}, obj, {
|
|
26
|
+
deep,
|
|
27
|
+
ignoreNulls: true,
|
|
28
|
+
ignoreUndefined: false,
|
|
29
|
+
copyDescriptors: true,
|
|
30
|
+
});
|
|
42
31
|
}
|
|
43
32
|
function omitNullish(obj, deep) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
if (v == null)
|
|
51
|
-
delete obj[k];
|
|
52
|
-
else if (deep) {
|
|
53
|
-
if (Array.isArray(v))
|
|
54
|
-
v.forEach(x => omitNullish(x, deep));
|
|
55
|
-
else if ((0, is_object_js_1.isPlainObject)(v))
|
|
56
|
-
omitNullish(obj[k], deep);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
return obj;
|
|
33
|
+
return (0, merge_js_1.merge)({}, obj, {
|
|
34
|
+
deep,
|
|
35
|
+
ignoreNulls: true,
|
|
36
|
+
ignoreUndefined: true,
|
|
37
|
+
copyDescriptors: true,
|
|
38
|
+
});
|
|
60
39
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"root":["../../src/clone.ts","../../src/index.ts","../../src/is-
|
|
1
|
+
{"root":["../../src/clone.ts","../../src/index.ts","../../src/is-object.ts","../../src/merge.ts","../../src/omit.ts","../../src/type-guards.ts"],"version":"5.6.3"}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isBuiltIn = isBuiltIn;
|
|
4
|
+
exports.isConstructor = isConstructor;
|
|
5
|
+
exports.isIterable = isIterable;
|
|
6
|
+
exports.isAsyncIterable = isAsyncIterable;
|
|
4
7
|
function isBuiltIn(v) {
|
|
5
8
|
return ((typeof v === 'object' &&
|
|
6
9
|
(v instanceof Date ||
|
|
@@ -25,3 +28,16 @@ function isBuiltIn(v) {
|
|
|
25
28
|
Buffer.isBuffer(v))) ||
|
|
26
29
|
Array.isArray(v));
|
|
27
30
|
}
|
|
31
|
+
function isConstructor(fn) {
|
|
32
|
+
return (typeof fn === 'function' &&
|
|
33
|
+
fn.prototype &&
|
|
34
|
+
fn.prototype.constructor === fn &&
|
|
35
|
+
fn.prototype.constructor.name !== 'Function' &&
|
|
36
|
+
fn.prototype.constructor.name !== 'embedded');
|
|
37
|
+
}
|
|
38
|
+
function isIterable(x) {
|
|
39
|
+
return Symbol.iterator in x;
|
|
40
|
+
}
|
|
41
|
+
function isAsyncIterable(x) {
|
|
42
|
+
return Symbol.asyncIterator in x;
|
|
43
|
+
}
|
package/esm/index.js
CHANGED
package/esm/merge.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { isObject, isPlainObject } from './is-object.js';
|
|
2
|
+
import { isBuiltIn } from './type-guards.js';
|
|
2
3
|
export function merge(target, source, options) {
|
|
3
4
|
if (!(isObject(target) || typeof target === 'function')) {
|
|
4
5
|
throw new TypeError('"target" argument must be an object');
|
|
@@ -8,7 +9,7 @@ export function merge(target, source, options) {
|
|
|
8
9
|
throw new TypeError('"target" argument must be an object');
|
|
9
10
|
}
|
|
10
11
|
const fn = getMergeFunction(options);
|
|
11
|
-
return fn(target, source, '', options, fn,
|
|
12
|
+
return fn(target, source, '', options, fn, isBuiltIn, isObject, isPlainObject, arrayClone);
|
|
12
13
|
}
|
|
13
14
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
14
15
|
const functionCache = new Map();
|
|
@@ -45,14 +46,15 @@ function buildMerge(options) {
|
|
|
45
46
|
'curPath',
|
|
46
47
|
'options',
|
|
47
48
|
'mergeFunction',
|
|
48
|
-
'
|
|
49
|
+
'isBuiltIn',
|
|
49
50
|
'isObject',
|
|
51
|
+
'isPlainObject',
|
|
50
52
|
'arrayClone',
|
|
51
53
|
];
|
|
52
54
|
const scriptL0 = [
|
|
53
55
|
`
|
|
54
56
|
const _merge = (_trgVal, _srcVal, _curPath) =>
|
|
55
|
-
mergeFunction(_trgVal, _srcVal, _curPath, options, mergeFunction,
|
|
57
|
+
mergeFunction(_trgVal, _srcVal, _curPath, options, mergeFunction, isBuiltIn, isObject, isPlainObject, arrayClone);
|
|
56
58
|
const keys = Object.getOwnPropertyNames(source);
|
|
57
59
|
keys.push(...Object.getOwnPropertySymbols(source));
|
|
58
60
|
let key;
|
|
@@ -62,7 +64,7 @@ let trgVal;
|
|
|
62
64
|
`,
|
|
63
65
|
];
|
|
64
66
|
if (options?.deep) {
|
|
65
|
-
scriptL0.push(`let subPath;`, `let
|
|
67
|
+
scriptL0.push(`let subPath;`, `let _isArray;`);
|
|
66
68
|
if (typeof options?.deep === 'function') {
|
|
67
69
|
scriptL0.push(`const deepCallback = options.deep;`);
|
|
68
70
|
}
|
|
@@ -80,6 +82,7 @@ let trgVal;
|
|
|
80
82
|
scriptL0.push(`const moveArraysCallback = options.moveArrays;`);
|
|
81
83
|
}
|
|
82
84
|
scriptL0.push(`
|
|
85
|
+
if (isPlainObject(target)) Object.setPrototypeOf(target, Object.getPrototypeOf(source));
|
|
83
86
|
let i = 0;
|
|
84
87
|
const len = keys.length;
|
|
85
88
|
for (i = 0; i < len; i++) {
|
|
@@ -129,7 +132,7 @@ if (
|
|
|
129
132
|
srcVal = source[key];`);
|
|
130
133
|
}
|
|
131
134
|
else {
|
|
132
|
-
scriptL1For.push(`descriptor = {enumerable: true, configurable: true, writable: true}`, `srcVal =
|
|
135
|
+
scriptL1For.push(`descriptor = {enumerable: true, configurable: true, writable: true}`, `srcVal = source[key];`);
|
|
133
136
|
}
|
|
134
137
|
/** ************* keepExisting *****************/
|
|
135
138
|
if (options?.keepExisting) {
|
|
@@ -143,36 +146,32 @@ if (
|
|
|
143
146
|
if (options?.ignoreNulls) {
|
|
144
147
|
scriptL1For.push(`if (srcVal === null) continue;`);
|
|
145
148
|
}
|
|
149
|
+
const deepArray = !options?.moveArrays || typeof options?.moveArrays === 'function';
|
|
146
150
|
/** ************* deep *****************/
|
|
147
151
|
if (options?.deep) {
|
|
148
|
-
|
|
149
|
-
|
|
152
|
+
if (deepArray) {
|
|
153
|
+
scriptL1For.push(`
|
|
150
154
|
_isArray = Array.isArray(srcVal);
|
|
151
|
-
if (
|
|
155
|
+
if (_isArray || (typeof srcVal === 'object' && !isBuiltIn(srcVal))) {`);
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
scriptL1For.push(`
|
|
159
|
+
if (typeof srcVal === 'object' && !isBuiltIn(srcVal)) {
|
|
160
|
+
subPath = curPath + (curPath ? '.' : '') + key;`);
|
|
161
|
+
}
|
|
162
|
+
scriptL1For.push(`subPath = curPath + (curPath ? '.' : '') + key;`);
|
|
152
163
|
const scriptL2Deep = [];
|
|
153
164
|
scriptL1For.push(scriptL2Deep);
|
|
154
165
|
scriptL1For.push('}');
|
|
155
166
|
let scriptL3Deep = scriptL2Deep;
|
|
156
167
|
if (typeof options?.deep === 'function') {
|
|
157
168
|
scriptL2Deep.push(`
|
|
158
|
-
subPath = curPath + (curPath ? '.' : '') + key;
|
|
159
169
|
if (deepCallback(key, subPath, target, source)) {`);
|
|
160
170
|
scriptL3Deep = [];
|
|
161
171
|
scriptL2Deep.push(scriptL3Deep);
|
|
162
172
|
scriptL2Deep.push('}');
|
|
163
173
|
}
|
|
164
|
-
/** *************
|
|
165
|
-
scriptL3Deep.push(`
|
|
166
|
-
if (_isPlain) {
|
|
167
|
-
trgVal = target[key];
|
|
168
|
-
if (!isObject(trgVal)) {
|
|
169
|
-
descriptor.value = trgVal = {};
|
|
170
|
-
Object.defineProperty(target, key, descriptor);
|
|
171
|
-
}
|
|
172
|
-
_merge(trgVal, srcVal, subPath, options);
|
|
173
|
-
continue;
|
|
174
|
-
}`);
|
|
175
|
-
/** ************* moveArrays *****************/
|
|
174
|
+
/** ************* Array *****************/
|
|
176
175
|
if (!options?.moveArrays || typeof options?.moveArrays === 'function') {
|
|
177
176
|
scriptL3Deep.push(`if (_isArray) {`);
|
|
178
177
|
const scriptL4IsArray = [];
|
|
@@ -180,7 +179,12 @@ if (_isPlain) {
|
|
|
180
179
|
scriptL3Deep.push('}');
|
|
181
180
|
let scriptL5CloneArrays = scriptL4IsArray;
|
|
182
181
|
if (typeof options?.moveArrays === 'function') {
|
|
183
|
-
scriptL4IsArray.push(`
|
|
182
|
+
scriptL4IsArray.push(`
|
|
183
|
+
if (moveArraysCallback(key, subPath, target, source)) {
|
|
184
|
+
descriptor.value = srcVal;
|
|
185
|
+
Object.defineProperty(target, key, descriptor);
|
|
186
|
+
continue;
|
|
187
|
+
} else {`);
|
|
184
188
|
scriptL5CloneArrays = [];
|
|
185
189
|
scriptL4IsArray.push(scriptL5CloneArrays);
|
|
186
190
|
scriptL4IsArray.push('}');
|
|
@@ -191,6 +195,15 @@ Object.defineProperty(target, key, descriptor);
|
|
|
191
195
|
continue;
|
|
192
196
|
`);
|
|
193
197
|
}
|
|
198
|
+
/** ************* object *****************/
|
|
199
|
+
scriptL3Deep.push(`
|
|
200
|
+
trgVal = target[key];
|
|
201
|
+
if (!isObject(trgVal)) {
|
|
202
|
+
descriptor.value = trgVal = {};
|
|
203
|
+
Object.defineProperty(target, key, descriptor);
|
|
204
|
+
}
|
|
205
|
+
_merge(trgVal, srcVal, subPath, options);
|
|
206
|
+
continue;`);
|
|
194
207
|
}
|
|
195
208
|
/** ************* finalize *****************/
|
|
196
209
|
scriptL1For.push(`
|
|
@@ -205,7 +218,7 @@ function arrayClone(arr, _merge, curPath) {
|
|
|
205
218
|
return arr.map((x) => {
|
|
206
219
|
if (Array.isArray(x))
|
|
207
220
|
return arrayClone(x, _merge, curPath);
|
|
208
|
-
if (
|
|
221
|
+
if (typeof x === 'object' && !isBuiltIn(x))
|
|
209
222
|
return _merge({}, x, curPath);
|
|
210
223
|
return x;
|
|
211
224
|
});
|
package/esm/omit.js
CHANGED
|
@@ -1,55 +1,33 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { merge } from './merge.js';
|
|
2
|
+
export function omit(obj, keys) {
|
|
3
|
+
const keysSet = new Set(keys);
|
|
4
|
+
return merge({}, obj, {
|
|
5
|
+
deep: false,
|
|
6
|
+
filter(key) {
|
|
7
|
+
return !keysSet.has(key);
|
|
8
|
+
},
|
|
9
|
+
});
|
|
10
|
+
}
|
|
2
11
|
export function omitUndefined(obj, deep) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
v = obj[k];
|
|
9
|
-
if (v === undefined)
|
|
10
|
-
delete obj[k];
|
|
11
|
-
else if (deep) {
|
|
12
|
-
if (Array.isArray(v))
|
|
13
|
-
v.forEach(x => omitUndefined(x, deep));
|
|
14
|
-
else if (isPlainObject(v))
|
|
15
|
-
omitUndefined(obj[k], deep);
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
return obj;
|
|
12
|
+
return merge({}, obj, {
|
|
13
|
+
deep,
|
|
14
|
+
ignoreUndefined: true,
|
|
15
|
+
copyDescriptors: true,
|
|
16
|
+
});
|
|
19
17
|
}
|
|
20
18
|
export function omitNull(obj, deep) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
if (v === null)
|
|
28
|
-
delete obj[k];
|
|
29
|
-
else if (deep) {
|
|
30
|
-
if (Array.isArray(v))
|
|
31
|
-
v.forEach(x => omitNull(x, deep));
|
|
32
|
-
else if (isPlainObject(v))
|
|
33
|
-
omitNull(obj[k], deep);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
return obj;
|
|
19
|
+
return merge({}, obj, {
|
|
20
|
+
deep,
|
|
21
|
+
ignoreNulls: true,
|
|
22
|
+
ignoreUndefined: false,
|
|
23
|
+
copyDescriptors: true,
|
|
24
|
+
});
|
|
37
25
|
}
|
|
38
26
|
export function omitNullish(obj, deep) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
if (v == null)
|
|
46
|
-
delete obj[k];
|
|
47
|
-
else if (deep) {
|
|
48
|
-
if (Array.isArray(v))
|
|
49
|
-
v.forEach(x => omitNullish(x, deep));
|
|
50
|
-
else if (isPlainObject(v))
|
|
51
|
-
omitNullish(obj[k], deep);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
return obj;
|
|
27
|
+
return merge({}, obj, {
|
|
28
|
+
deep,
|
|
29
|
+
ignoreNulls: true,
|
|
30
|
+
ignoreUndefined: true,
|
|
31
|
+
copyDescriptors: true,
|
|
32
|
+
});
|
|
55
33
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"root":["../../src/clone.ts","../../src/index.ts","../../src/is-
|
|
1
|
+
{"root":["../../src/clone.ts","../../src/index.ts","../../src/is-object.ts","../../src/merge.ts","../../src/omit.ts","../../src/type-guards.ts"],"version":"5.6.3"}
|
|
@@ -22,3 +22,16 @@ export function isBuiltIn(v) {
|
|
|
22
22
|
Buffer.isBuffer(v))) ||
|
|
23
23
|
Array.isArray(v));
|
|
24
24
|
}
|
|
25
|
+
export function isConstructor(fn) {
|
|
26
|
+
return (typeof fn === 'function' &&
|
|
27
|
+
fn.prototype &&
|
|
28
|
+
fn.prototype.constructor === fn &&
|
|
29
|
+
fn.prototype.constructor.name !== 'Function' &&
|
|
30
|
+
fn.prototype.constructor.name !== 'embedded');
|
|
31
|
+
}
|
|
32
|
+
export function isIterable(x) {
|
|
33
|
+
return Symbol.iterator in x;
|
|
34
|
+
}
|
|
35
|
+
export function isAsyncIterable(x) {
|
|
36
|
+
return Symbol.asyncIterator in x;
|
|
37
|
+
}
|
package/package.json
CHANGED
package/types/index.d.cts
CHANGED
package/types/index.d.ts
CHANGED
package/types/omit.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
export declare function omitUndefined<T>(obj: T, deep?: boolean):
|
|
3
|
-
export declare function omitNull<T>(obj: T, deep?: boolean):
|
|
4
|
-
export declare function omitNullish<T>(obj: T, deep?: boolean):
|
|
1
|
+
export declare function omit<T, K extends keyof T>(obj: T, keys: K[]): Omit<T, K>;
|
|
2
|
+
export declare function omitUndefined<T>(obj: T, deep?: boolean): T;
|
|
3
|
+
export declare function omitNull<T>(obj: T, deep?: boolean): T;
|
|
4
|
+
export declare function omitNullish<T>(obj: T, deep?: boolean): T;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Type } from 'ts-gems';
|
|
2
|
+
export declare function isBuiltIn(v: any): boolean;
|
|
3
|
+
export declare function isConstructor(fn: any): fn is Type;
|
|
4
|
+
export declare function isIterable<T = unknown>(x: any): x is Iterable<T>;
|
|
5
|
+
export declare function isAsyncIterable<T = unknown>(x: any): x is AsyncIterableIterator<T>;
|
package/types/is-built-in.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function isBuiltIn(v: any): boolean;
|