es-toolkit 1.18.0-dev.601 → 1.18.0-dev.602
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/dist/_chunk/{toMerged-LBvzaK.js → toMerged-Bzkqyz.js} +0 -9
- package/dist/array/unzip.d.mts +1 -1
- package/dist/array/unzip.d.ts +1 -1
- package/dist/browser.global.js +1 -1
- package/dist/browser.global.js.map +1 -1
- package/dist/compat/_internal/isDeepKey.mjs +1 -3
- package/dist/compat/_internal/toKey.mjs +2 -7
- package/dist/compat/index.d.mts +1 -1
- package/dist/compat/index.d.ts +1 -1
- package/dist/compat/index.js +171 -58
- package/dist/compat/index.mjs +1 -1
- package/dist/compat/object/get.mjs +53 -16
- package/dist/compat/object/omit.d.mts +34 -0
- package/dist/compat/object/omit.d.ts +34 -0
- package/dist/compat/object/omit.mjs +33 -0
- package/dist/compat/object/pick.d.mts +2 -1
- package/dist/compat/object/pick.d.ts +2 -1
- package/dist/compat/object/unset.d.mts +1 -1
- package/dist/compat/object/unset.d.ts +1 -1
- package/dist/compat/object/unset.mjs +53 -8
- package/dist/compat/predicate/matchesProperty.mjs +12 -1
- package/dist/compat/string/trim.d.mts +1 -0
- package/dist/compat/string/trim.d.ts +1 -0
- package/dist/compat/string/trimEnd.d.mts +1 -0
- package/dist/compat/string/trimEnd.d.ts +1 -0
- package/dist/compat/string/trimStart.d.mts +1 -0
- package/dist/compat/string/trimStart.d.ts +1 -0
- package/dist/compat/util/toPath.mjs +6 -9
- package/dist/index.js +4 -4
- package/dist/object/index.js +10 -2
- package/package.json +1 -1
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
const IS_PLAIN = /^\w*$/;
|
|
2
|
-
const IS_DEEP = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/;
|
|
3
1
|
function isDeepKey(key) {
|
|
4
2
|
switch (typeof key) {
|
|
5
3
|
case 'number':
|
|
@@ -7,7 +5,7 @@ function isDeepKey(key) {
|
|
|
7
5
|
return false;
|
|
8
6
|
}
|
|
9
7
|
case 'string': {
|
|
10
|
-
return
|
|
8
|
+
return key.includes('.') || key.includes('[') || key.includes(']');
|
|
11
9
|
}
|
|
12
10
|
}
|
|
13
11
|
}
|
|
@@ -1,13 +1,8 @@
|
|
|
1
|
-
import { isSymbol } from '../predicate/isSymbol.mjs';
|
|
2
|
-
|
|
3
1
|
function toKey(value) {
|
|
4
|
-
if (
|
|
5
|
-
return value;
|
|
6
|
-
}
|
|
7
|
-
if (Object.is(value?.valueOf(), -0)) {
|
|
2
|
+
if (Object.is(value, -0)) {
|
|
8
3
|
return '-0';
|
|
9
4
|
}
|
|
10
|
-
return
|
|
5
|
+
return value.toString();
|
|
11
6
|
}
|
|
12
7
|
|
|
13
8
|
export { toKey };
|
package/dist/compat/index.d.mts
CHANGED
|
@@ -70,7 +70,6 @@ export { randomInt } from '../math/randomInt.mjs';
|
|
|
70
70
|
export { sum } from '../math/sum.mjs';
|
|
71
71
|
export { sumBy } from '../math/sumBy.mjs';
|
|
72
72
|
export { range } from '../math/range.mjs';
|
|
73
|
-
export { omit } from '../object/omit.mjs';
|
|
74
73
|
export { omitBy } from '../object/omitBy.mjs';
|
|
75
74
|
export { pickBy } from '../object/pickBy.mjs';
|
|
76
75
|
export { invert } from '../object/invert.mjs';
|
|
@@ -128,6 +127,7 @@ export { rearg } from './function/rearg.mjs';
|
|
|
128
127
|
export { get } from './object/get.mjs';
|
|
129
128
|
export { set } from './object/set.mjs';
|
|
130
129
|
export { pick } from './object/pick.mjs';
|
|
130
|
+
export { omit } from './object/omit.mjs';
|
|
131
131
|
export { has } from './object/has.mjs';
|
|
132
132
|
export { property } from './object/property.mjs';
|
|
133
133
|
export { mapKeys } from './object/mapKeys.mjs';
|
package/dist/compat/index.d.ts
CHANGED
|
@@ -70,7 +70,6 @@ export { randomInt } from '../math/randomInt.js';
|
|
|
70
70
|
export { sum } from '../math/sum.js';
|
|
71
71
|
export { sumBy } from '../math/sumBy.js';
|
|
72
72
|
export { range } from '../math/range.js';
|
|
73
|
-
export { omit } from '../object/omit.js';
|
|
74
73
|
export { omitBy } from '../object/omitBy.js';
|
|
75
74
|
export { pickBy } from '../object/pickBy.js';
|
|
76
75
|
export { invert } from '../object/invert.js';
|
|
@@ -128,6 +127,7 @@ export { rearg } from './function/rearg.js';
|
|
|
128
127
|
export { get } from './object/get.js';
|
|
129
128
|
export { set } from './object/set.js';
|
|
130
129
|
export { pick } from './object/pick.js';
|
|
130
|
+
export { omit } from './object/omit.js';
|
|
131
131
|
export { has } from './object/has.js';
|
|
132
132
|
export { property } from './object/property.js';
|
|
133
133
|
export { mapKeys } from './object/mapKeys.js';
|
package/dist/compat/index.js
CHANGED
|
@@ -7,7 +7,7 @@ const promise_index = require('../_chunk/index-BGZDR9.js');
|
|
|
7
7
|
const curry = require('../_chunk/curry-BmwJrK.js');
|
|
8
8
|
const range = require('../_chunk/range-BXlMmn.js');
|
|
9
9
|
const randomInt = require('../_chunk/randomInt-CF7bZK.js');
|
|
10
|
-
const toMerged = require('../_chunk/toMerged-
|
|
10
|
+
const toMerged = require('../_chunk/toMerged-Bzkqyz.js');
|
|
11
11
|
const isWeakSet$1 = require('../_chunk/isWeakSet-E_VMwB.js');
|
|
12
12
|
const isPlainObject$1 = require('../_chunk/isPlainObject-BIekvL.js');
|
|
13
13
|
const string_index = require('../string/index.js');
|
|
@@ -49,8 +49,6 @@ function fill(array, value, start = 0, end = array.length) {
|
|
|
49
49
|
return zipWith.fill(array, value, start, end);
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
const IS_PLAIN = /^\w*$/;
|
|
53
|
-
const IS_DEEP = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/;
|
|
54
52
|
function isDeepKey(key) {
|
|
55
53
|
switch (typeof key) {
|
|
56
54
|
case 'number':
|
|
@@ -58,25 +56,19 @@ function isDeepKey(key) {
|
|
|
58
56
|
return false;
|
|
59
57
|
}
|
|
60
58
|
case 'string': {
|
|
61
|
-
return
|
|
59
|
+
return key.includes('.') || key.includes('[') || key.includes(']');
|
|
62
60
|
}
|
|
63
61
|
}
|
|
64
62
|
}
|
|
65
63
|
|
|
66
|
-
function isSymbol(value) {
|
|
67
|
-
return typeof value === 'symbol' || (value != null && value instanceof Symbol);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
64
|
function toKey(value) {
|
|
71
|
-
if (
|
|
72
|
-
return value;
|
|
73
|
-
}
|
|
74
|
-
if (Object.is(value?.valueOf(), -0)) {
|
|
65
|
+
if (Object.is(value, -0)) {
|
|
75
66
|
return '-0';
|
|
76
67
|
}
|
|
77
|
-
return
|
|
68
|
+
return value.toString();
|
|
78
69
|
}
|
|
79
70
|
|
|
71
|
+
const DOTS_KEY = /^[\w.]+$/g;
|
|
80
72
|
const ESCAPE_REGEXP = /\\(\\)?/g;
|
|
81
73
|
const PROPERTY_REGEXP = RegExp('[^.[\\]]+' +
|
|
82
74
|
'|' +
|
|
@@ -88,13 +80,15 @@ const PROPERTY_REGEXP = RegExp('[^.[\\]]+' +
|
|
|
88
80
|
'|' +
|
|
89
81
|
'(?=(?:\\.|\\[\\])(?:\\.|\\[\\]|$))', 'g');
|
|
90
82
|
function toPath(deepKey) {
|
|
83
|
+
if (DOTS_KEY.test(deepKey)) {
|
|
84
|
+
return deepKey.split('.');
|
|
85
|
+
}
|
|
91
86
|
const result = [];
|
|
92
87
|
if (deepKey[0] === '.') {
|
|
93
88
|
result.push('');
|
|
94
89
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
while ((match = PROPERTY_REGEXP.exec(deepKey)) !== null) {
|
|
90
|
+
const matches = deepKey.matchAll(PROPERTY_REGEXP);
|
|
91
|
+
for (const match of matches) {
|
|
98
92
|
let key = match[0];
|
|
99
93
|
const expr = match[1];
|
|
100
94
|
const quote = match[2];
|
|
@@ -106,40 +100,71 @@ function toPath(deepKey) {
|
|
|
106
100
|
key = expr;
|
|
107
101
|
}
|
|
108
102
|
result.push(key);
|
|
109
|
-
if (PROPERTY_REGEXP.lastIndex === lastIndex) {
|
|
110
|
-
PROPERTY_REGEXP.lastIndex++;
|
|
111
|
-
}
|
|
112
|
-
else {
|
|
113
|
-
lastIndex = PROPERTY_REGEXP.lastIndex;
|
|
114
|
-
}
|
|
115
103
|
}
|
|
116
104
|
return result;
|
|
117
105
|
}
|
|
118
106
|
|
|
119
107
|
function get(object, path, defaultValue) {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
resolvedPath = path;
|
|
123
|
-
}
|
|
124
|
-
else if (typeof path === 'string' && isDeepKey(path) && object?.[path] == null) {
|
|
125
|
-
resolvedPath = toPath(path);
|
|
108
|
+
if (object == null) {
|
|
109
|
+
return defaultValue;
|
|
126
110
|
}
|
|
127
|
-
|
|
128
|
-
|
|
111
|
+
switch (typeof path) {
|
|
112
|
+
case 'string': {
|
|
113
|
+
const result = object[path];
|
|
114
|
+
if (result === undefined) {
|
|
115
|
+
if (isDeepKey(path)) {
|
|
116
|
+
return get(object, toPath(path), defaultValue);
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
return defaultValue;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return result;
|
|
123
|
+
}
|
|
124
|
+
case 'number':
|
|
125
|
+
case 'symbol': {
|
|
126
|
+
if (typeof path === 'number') {
|
|
127
|
+
path = toKey(path);
|
|
128
|
+
}
|
|
129
|
+
const result = object[path];
|
|
130
|
+
if (result === undefined) {
|
|
131
|
+
return defaultValue;
|
|
132
|
+
}
|
|
133
|
+
return result;
|
|
134
|
+
}
|
|
135
|
+
default: {
|
|
136
|
+
if (Array.isArray(path)) {
|
|
137
|
+
return getWithPath(object, path, defaultValue);
|
|
138
|
+
}
|
|
139
|
+
if (Object.is(path?.valueOf(), -0)) {
|
|
140
|
+
path = '-0';
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
path = String(path);
|
|
144
|
+
}
|
|
145
|
+
const result = object[path];
|
|
146
|
+
if (result === undefined) {
|
|
147
|
+
return defaultValue;
|
|
148
|
+
}
|
|
149
|
+
return result;
|
|
150
|
+
}
|
|
129
151
|
}
|
|
130
|
-
|
|
152
|
+
}
|
|
153
|
+
function getWithPath(object, path, defaultValue) {
|
|
154
|
+
if (path.length === 0) {
|
|
131
155
|
return defaultValue;
|
|
132
156
|
}
|
|
133
157
|
let current = object;
|
|
134
|
-
let index;
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
158
|
+
for (let index = 0; index < path.length; index++) {
|
|
159
|
+
if (current == null) {
|
|
160
|
+
return defaultValue;
|
|
161
|
+
}
|
|
162
|
+
current = current[path[index]];
|
|
138
163
|
}
|
|
139
|
-
if (current ===
|
|
140
|
-
return
|
|
164
|
+
if (current === undefined) {
|
|
165
|
+
return defaultValue;
|
|
141
166
|
}
|
|
142
|
-
return current
|
|
167
|
+
return current;
|
|
143
168
|
}
|
|
144
169
|
|
|
145
170
|
function property(path) {
|
|
@@ -322,7 +347,18 @@ function has(object, path) {
|
|
|
322
347
|
}
|
|
323
348
|
|
|
324
349
|
function matchesProperty(property, source) {
|
|
325
|
-
|
|
350
|
+
switch (typeof property) {
|
|
351
|
+
case 'object': {
|
|
352
|
+
if (Object.is(property?.valueOf(), -0)) {
|
|
353
|
+
property = '-0';
|
|
354
|
+
}
|
|
355
|
+
break;
|
|
356
|
+
}
|
|
357
|
+
case 'number': {
|
|
358
|
+
property = toKey(property);
|
|
359
|
+
break;
|
|
360
|
+
}
|
|
361
|
+
}
|
|
326
362
|
source = cloneDeep(source);
|
|
327
363
|
return function (target) {
|
|
328
364
|
const result = get(target, property);
|
|
@@ -516,6 +552,10 @@ const compareValues = (a, b, order) => {
|
|
|
516
552
|
return 0;
|
|
517
553
|
};
|
|
518
554
|
|
|
555
|
+
function isSymbol(value) {
|
|
556
|
+
return typeof value === 'symbol' || (value != null && value instanceof Symbol);
|
|
557
|
+
}
|
|
558
|
+
|
|
519
559
|
const regexIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/;
|
|
520
560
|
const regexIsPlainProp = /^\w*$/;
|
|
521
561
|
function isKey(value, object) {
|
|
@@ -816,6 +856,97 @@ function pick(obj, ...keysArr) {
|
|
|
816
856
|
return result;
|
|
817
857
|
}
|
|
818
858
|
|
|
859
|
+
function unset(obj, path) {
|
|
860
|
+
if (obj == null) {
|
|
861
|
+
return true;
|
|
862
|
+
}
|
|
863
|
+
switch (typeof path) {
|
|
864
|
+
case 'symbol':
|
|
865
|
+
case 'number':
|
|
866
|
+
case 'object': {
|
|
867
|
+
if (Array.isArray(path)) {
|
|
868
|
+
return unsetWithPath(obj, path);
|
|
869
|
+
}
|
|
870
|
+
if (typeof path === 'number') {
|
|
871
|
+
path = toKey(path);
|
|
872
|
+
}
|
|
873
|
+
else if (typeof path === 'object') {
|
|
874
|
+
if (Object.is(path?.valueOf(), -0)) {
|
|
875
|
+
path = '-0';
|
|
876
|
+
}
|
|
877
|
+
else {
|
|
878
|
+
path = String(path);
|
|
879
|
+
}
|
|
880
|
+
}
|
|
881
|
+
if (obj?.[path] === undefined) {
|
|
882
|
+
return true;
|
|
883
|
+
}
|
|
884
|
+
try {
|
|
885
|
+
delete obj[path];
|
|
886
|
+
return true;
|
|
887
|
+
}
|
|
888
|
+
catch {
|
|
889
|
+
return false;
|
|
890
|
+
}
|
|
891
|
+
}
|
|
892
|
+
case 'string': {
|
|
893
|
+
if (obj?.[path] === undefined && isDeepKey(path)) {
|
|
894
|
+
return unsetWithPath(obj, toPath(path));
|
|
895
|
+
}
|
|
896
|
+
try {
|
|
897
|
+
delete obj[path];
|
|
898
|
+
return true;
|
|
899
|
+
}
|
|
900
|
+
catch {
|
|
901
|
+
return false;
|
|
902
|
+
}
|
|
903
|
+
}
|
|
904
|
+
}
|
|
905
|
+
}
|
|
906
|
+
function unsetWithPath(obj, path) {
|
|
907
|
+
const parent = get(obj, path.slice(0, -1), obj);
|
|
908
|
+
const lastKey = path[path.length - 1];
|
|
909
|
+
if (parent?.[lastKey] === undefined) {
|
|
910
|
+
return true;
|
|
911
|
+
}
|
|
912
|
+
try {
|
|
913
|
+
delete parent[lastKey];
|
|
914
|
+
return true;
|
|
915
|
+
}
|
|
916
|
+
catch {
|
|
917
|
+
return false;
|
|
918
|
+
}
|
|
919
|
+
}
|
|
920
|
+
|
|
921
|
+
function omit(obj, ...keysArr) {
|
|
922
|
+
if (obj == null) {
|
|
923
|
+
return {};
|
|
924
|
+
}
|
|
925
|
+
const result = toMerged.cloneDeep(obj);
|
|
926
|
+
for (let i = 0; i < keysArr.length; i++) {
|
|
927
|
+
let keys = keysArr[i];
|
|
928
|
+
switch (typeof keys) {
|
|
929
|
+
case 'object': {
|
|
930
|
+
if (!Array.isArray(keys)) {
|
|
931
|
+
keys = Array.from(keys);
|
|
932
|
+
}
|
|
933
|
+
for (let j = 0; j < keys.length; j++) {
|
|
934
|
+
const key = keys[j];
|
|
935
|
+
unset(result, key);
|
|
936
|
+
}
|
|
937
|
+
break;
|
|
938
|
+
}
|
|
939
|
+
case 'string':
|
|
940
|
+
case 'symbol':
|
|
941
|
+
case 'number': {
|
|
942
|
+
unset(result, keys);
|
|
943
|
+
break;
|
|
944
|
+
}
|
|
945
|
+
}
|
|
946
|
+
}
|
|
947
|
+
return result;
|
|
948
|
+
}
|
|
949
|
+
|
|
819
950
|
function mapKeys(object, getNewKey) {
|
|
820
951
|
getNewKey = getNewKey ?? identity;
|
|
821
952
|
switch (typeof getNewKey) {
|
|
@@ -972,24 +1103,6 @@ function fromPairs(pairs) {
|
|
|
972
1103
|
return result;
|
|
973
1104
|
}
|
|
974
1105
|
|
|
975
|
-
function unset(obj, path) {
|
|
976
|
-
if (obj == null) {
|
|
977
|
-
return true;
|
|
978
|
-
}
|
|
979
|
-
const resolvedPath = Array.isArray(path) ? path : typeof path === 'string' ? toPath(path) : [path];
|
|
980
|
-
const parent = get(obj, resolvedPath.slice(0, -1), obj);
|
|
981
|
-
const lastKey = toKey(resolvedPath[resolvedPath.length - 1]);
|
|
982
|
-
if (typeof parent !== 'object' || parent == null || !Object.prototype.hasOwnProperty.call(parent, lastKey)) {
|
|
983
|
-
return true;
|
|
984
|
-
}
|
|
985
|
-
const isDeletable = Object.getOwnPropertyDescriptor(parent, lastKey)?.configurable;
|
|
986
|
-
if (!isDeletable) {
|
|
987
|
-
return false;
|
|
988
|
-
}
|
|
989
|
-
delete parent[lastKey];
|
|
990
|
-
return true;
|
|
991
|
-
}
|
|
992
|
-
|
|
993
1106
|
function isArray(value) {
|
|
994
1107
|
return Array.isArray(value);
|
|
995
1108
|
}
|
|
@@ -1331,7 +1444,6 @@ exports.cloneDeep = toMerged.cloneDeep;
|
|
|
1331
1444
|
exports.flattenObject = toMerged.flattenObject;
|
|
1332
1445
|
exports.invert = toMerged.invert;
|
|
1333
1446
|
exports.isObjectLike = toMerged.isObjectLike;
|
|
1334
|
-
exports.omit = toMerged.omit;
|
|
1335
1447
|
exports.omitBy = toMerged.omitBy;
|
|
1336
1448
|
exports.pickBy = toMerged.pickBy;
|
|
1337
1449
|
exports.toMerged = toMerged.toMerged;
|
|
@@ -1405,6 +1517,7 @@ exports.max = max;
|
|
|
1405
1517
|
exports.merge = merge;
|
|
1406
1518
|
exports.mergeWith = mergeWith;
|
|
1407
1519
|
exports.min = min;
|
|
1520
|
+
exports.omit = omit;
|
|
1408
1521
|
exports.orderBy = orderBy;
|
|
1409
1522
|
exports.padEnd = padEnd;
|
|
1410
1523
|
exports.padStart = padStart;
|
package/dist/compat/index.mjs
CHANGED
|
@@ -70,7 +70,6 @@ export { randomInt } from '../math/randomInt.mjs';
|
|
|
70
70
|
export { sum } from '../math/sum.mjs';
|
|
71
71
|
export { sumBy } from '../math/sumBy.mjs';
|
|
72
72
|
export { range } from '../math/range.mjs';
|
|
73
|
-
export { omit } from '../object/omit.mjs';
|
|
74
73
|
export { omitBy } from '../object/omitBy.mjs';
|
|
75
74
|
export { pickBy } from '../object/pickBy.mjs';
|
|
76
75
|
export { invert } from '../object/invert.mjs';
|
|
@@ -129,6 +128,7 @@ export { rearg } from './function/rearg.mjs';
|
|
|
129
128
|
export { get } from './object/get.mjs';
|
|
130
129
|
export { set } from './object/set.mjs';
|
|
131
130
|
export { pick } from './object/pick.mjs';
|
|
131
|
+
export { omit } from './object/omit.mjs';
|
|
132
132
|
export { has } from './object/has.mjs';
|
|
133
133
|
export { property } from './object/property.mjs';
|
|
134
134
|
export { mapKeys } from './object/mapKeys.mjs';
|
|
@@ -3,29 +3,66 @@ import { toKey } from '../_internal/toKey.mjs';
|
|
|
3
3
|
import { toPath } from '../util/toPath.mjs';
|
|
4
4
|
|
|
5
5
|
function get(object, path, defaultValue) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
resolvedPath = path;
|
|
9
|
-
}
|
|
10
|
-
else if (typeof path === 'string' && isDeepKey(path) && object?.[path] == null) {
|
|
11
|
-
resolvedPath = toPath(path);
|
|
6
|
+
if (object == null) {
|
|
7
|
+
return defaultValue;
|
|
12
8
|
}
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
switch (typeof path) {
|
|
10
|
+
case 'string': {
|
|
11
|
+
const result = object[path];
|
|
12
|
+
if (result === undefined) {
|
|
13
|
+
if (isDeepKey(path)) {
|
|
14
|
+
return get(object, toPath(path), defaultValue);
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
return defaultValue;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return result;
|
|
21
|
+
}
|
|
22
|
+
case 'number':
|
|
23
|
+
case 'symbol': {
|
|
24
|
+
if (typeof path === 'number') {
|
|
25
|
+
path = toKey(path);
|
|
26
|
+
}
|
|
27
|
+
const result = object[path];
|
|
28
|
+
if (result === undefined) {
|
|
29
|
+
return defaultValue;
|
|
30
|
+
}
|
|
31
|
+
return result;
|
|
32
|
+
}
|
|
33
|
+
default: {
|
|
34
|
+
if (Array.isArray(path)) {
|
|
35
|
+
return getWithPath(object, path, defaultValue);
|
|
36
|
+
}
|
|
37
|
+
if (Object.is(path?.valueOf(), -0)) {
|
|
38
|
+
path = '-0';
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
path = String(path);
|
|
42
|
+
}
|
|
43
|
+
const result = object[path];
|
|
44
|
+
if (result === undefined) {
|
|
45
|
+
return defaultValue;
|
|
46
|
+
}
|
|
47
|
+
return result;
|
|
48
|
+
}
|
|
15
49
|
}
|
|
16
|
-
|
|
50
|
+
}
|
|
51
|
+
function getWithPath(object, path, defaultValue) {
|
|
52
|
+
if (path.length === 0) {
|
|
17
53
|
return defaultValue;
|
|
18
54
|
}
|
|
19
55
|
let current = object;
|
|
20
|
-
let index;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
56
|
+
for (let index = 0; index < path.length; index++) {
|
|
57
|
+
if (current == null) {
|
|
58
|
+
return defaultValue;
|
|
59
|
+
}
|
|
60
|
+
current = current[path[index]];
|
|
24
61
|
}
|
|
25
|
-
if (current ===
|
|
26
|
-
return
|
|
62
|
+
if (current === undefined) {
|
|
63
|
+
return defaultValue;
|
|
27
64
|
}
|
|
28
|
-
return current
|
|
65
|
+
return current;
|
|
29
66
|
}
|
|
30
67
|
|
|
31
68
|
export { get };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a new object with specified keys omitted.
|
|
3
|
+
*
|
|
4
|
+
* This function takes an object and an array of keys, and returns a new object that
|
|
5
|
+
* excludes the properties corresponding to the specified keys.
|
|
6
|
+
*
|
|
7
|
+
* @template T - The type of object.
|
|
8
|
+
* @template K - The type of keys in object.
|
|
9
|
+
* @param {T} obj - The object to omit keys from.
|
|
10
|
+
* @param {K[]} keys - An array of keys to be omitted from the object.
|
|
11
|
+
* @returns {Omit<T, K>} A new object with the specified keys omitted.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* const obj = { a: 1, b: 2, c: 3 };
|
|
15
|
+
* const result = omit(obj, ['b', 'c']);
|
|
16
|
+
* // result will be { a: 1 }
|
|
17
|
+
*/
|
|
18
|
+
declare function omit<T extends Record<string, any>, K extends keyof T>(obj: T, keys: readonly K[]): Omit<T, K>;
|
|
19
|
+
/**
|
|
20
|
+
* Creates a new object with specified keys omitted.
|
|
21
|
+
*
|
|
22
|
+
* This function takes an object and a variable number of keys, and returns a new object that
|
|
23
|
+
* excludes the properties corresponding to the specified keys.
|
|
24
|
+
*
|
|
25
|
+
* Deep keys can be specified for keys.
|
|
26
|
+
*
|
|
27
|
+
* @template T - The type of object.
|
|
28
|
+
* @param {T} obj - The object to omit keys from.
|
|
29
|
+
* @param {...(PropertyKey | PropertyKey[] | PropertyKey[][]} keys - A variable number of keys to be omitted from the object.
|
|
30
|
+
* @returns {Partial<T>} A new object with the specified keys omitted.
|
|
31
|
+
*/
|
|
32
|
+
declare function omit<T extends {}>(obj: T | null | undefined, ...keys: Array<PropertyKey | readonly PropertyKey[] | ReadonlyArray<readonly PropertyKey[]>>): Partial<T>;
|
|
33
|
+
|
|
34
|
+
export { omit };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a new object with specified keys omitted.
|
|
3
|
+
*
|
|
4
|
+
* This function takes an object and an array of keys, and returns a new object that
|
|
5
|
+
* excludes the properties corresponding to the specified keys.
|
|
6
|
+
*
|
|
7
|
+
* @template T - The type of object.
|
|
8
|
+
* @template K - The type of keys in object.
|
|
9
|
+
* @param {T} obj - The object to omit keys from.
|
|
10
|
+
* @param {K[]} keys - An array of keys to be omitted from the object.
|
|
11
|
+
* @returns {Omit<T, K>} A new object with the specified keys omitted.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* const obj = { a: 1, b: 2, c: 3 };
|
|
15
|
+
* const result = omit(obj, ['b', 'c']);
|
|
16
|
+
* // result will be { a: 1 }
|
|
17
|
+
*/
|
|
18
|
+
declare function omit<T extends Record<string, any>, K extends keyof T>(obj: T, keys: readonly K[]): Omit<T, K>;
|
|
19
|
+
/**
|
|
20
|
+
* Creates a new object with specified keys omitted.
|
|
21
|
+
*
|
|
22
|
+
* This function takes an object and a variable number of keys, and returns a new object that
|
|
23
|
+
* excludes the properties corresponding to the specified keys.
|
|
24
|
+
*
|
|
25
|
+
* Deep keys can be specified for keys.
|
|
26
|
+
*
|
|
27
|
+
* @template T - The type of object.
|
|
28
|
+
* @param {T} obj - The object to omit keys from.
|
|
29
|
+
* @param {...(PropertyKey | PropertyKey[] | PropertyKey[][]} keys - A variable number of keys to be omitted from the object.
|
|
30
|
+
* @returns {Partial<T>} A new object with the specified keys omitted.
|
|
31
|
+
*/
|
|
32
|
+
declare function omit<T extends {}>(obj: T | null | undefined, ...keys: Array<PropertyKey | readonly PropertyKey[] | ReadonlyArray<readonly PropertyKey[]>>): Partial<T>;
|
|
33
|
+
|
|
34
|
+
export { omit };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { cloneDeep } from '../../object/cloneDeep.mjs';
|
|
2
|
+
import { unset } from './unset.mjs';
|
|
3
|
+
|
|
4
|
+
function omit(obj, ...keysArr) {
|
|
5
|
+
if (obj == null) {
|
|
6
|
+
return {};
|
|
7
|
+
}
|
|
8
|
+
const result = cloneDeep(obj);
|
|
9
|
+
for (let i = 0; i < keysArr.length; i++) {
|
|
10
|
+
let keys = keysArr[i];
|
|
11
|
+
switch (typeof keys) {
|
|
12
|
+
case 'object': {
|
|
13
|
+
if (!Array.isArray(keys)) {
|
|
14
|
+
keys = Array.from(keys);
|
|
15
|
+
}
|
|
16
|
+
for (let j = 0; j < keys.length; j++) {
|
|
17
|
+
const key = keys[j];
|
|
18
|
+
unset(result, key);
|
|
19
|
+
}
|
|
20
|
+
break;
|
|
21
|
+
}
|
|
22
|
+
case 'string':
|
|
23
|
+
case 'symbol':
|
|
24
|
+
case 'number': {
|
|
25
|
+
unset(result, keys);
|
|
26
|
+
break;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return result;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export { omit };
|
|
@@ -24,6 +24,7 @@ declare function pick<T extends Record<string, any>, K extends keyof T>(obj: T,
|
|
|
24
24
|
*
|
|
25
25
|
* @template T - The type of object.
|
|
26
26
|
* @param {T | null | undefined} obj - The object to pick keys from.
|
|
27
|
+
* @param {...any} keys
|
|
27
28
|
* @param {PropertyKey | PropertyKey[] | ProperyKey[][]}} keys - An array of keys to be picked from the object. received keysgoes through a flattening process before being used.
|
|
28
29
|
* @returns {Partial<T, K>} A new object with the specified keys picked.
|
|
29
30
|
*
|
|
@@ -41,6 +42,6 @@ declare function pick<T extends Record<string, any>, K extends keyof T>(obj: T,
|
|
|
41
42
|
* const result = pick(obj, 'a.b');
|
|
42
43
|
* // result will be { 'a.b': 1 }
|
|
43
44
|
*/
|
|
44
|
-
declare function pick<T extends {}>(obj: T | null | undefined, ...keys: Array<PropertyKey | readonly PropertyKey[] | readonly
|
|
45
|
+
declare function pick<T extends {}>(obj: T | null | undefined, ...keys: Array<PropertyKey | readonly PropertyKey[] | ReadonlyArray<readonly PropertyKey[]>>): Partial<T>;
|
|
45
46
|
|
|
46
47
|
export { pick };
|
|
@@ -24,6 +24,7 @@ declare function pick<T extends Record<string, any>, K extends keyof T>(obj: T,
|
|
|
24
24
|
*
|
|
25
25
|
* @template T - The type of object.
|
|
26
26
|
* @param {T | null | undefined} obj - The object to pick keys from.
|
|
27
|
+
* @param {...any} keys
|
|
27
28
|
* @param {PropertyKey | PropertyKey[] | ProperyKey[][]}} keys - An array of keys to be picked from the object. received keysgoes through a flattening process before being used.
|
|
28
29
|
* @returns {Partial<T, K>} A new object with the specified keys picked.
|
|
29
30
|
*
|
|
@@ -41,6 +42,6 @@ declare function pick<T extends Record<string, any>, K extends keyof T>(obj: T,
|
|
|
41
42
|
* const result = pick(obj, 'a.b');
|
|
42
43
|
* // result will be { 'a.b': 1 }
|
|
43
44
|
*/
|
|
44
|
-
declare function pick<T extends {}>(obj: T | null | undefined, ...keys: Array<PropertyKey | readonly PropertyKey[] | readonly
|
|
45
|
+
declare function pick<T extends {}>(obj: T | null | undefined, ...keys: Array<PropertyKey | readonly PropertyKey[] | ReadonlyArray<readonly PropertyKey[]>>): Partial<T>;
|
|
45
46
|
|
|
46
47
|
export { pick };
|
|
@@ -15,6 +15,6 @@
|
|
|
15
15
|
* unset(obj, ['a', 'b', 'c']); // true
|
|
16
16
|
* console.log(obj); // { a: { b: {} } }
|
|
17
17
|
*/
|
|
18
|
-
declare function unset(obj:
|
|
18
|
+
declare function unset(obj: any, path: PropertyKey | readonly PropertyKey[]): boolean;
|
|
19
19
|
|
|
20
20
|
export { unset };
|
|
@@ -15,6 +15,6 @@
|
|
|
15
15
|
* unset(obj, ['a', 'b', 'c']); // true
|
|
16
16
|
* console.log(obj); // { a: { b: {} } }
|
|
17
17
|
*/
|
|
18
|
-
declare function unset(obj:
|
|
18
|
+
declare function unset(obj: any, path: PropertyKey | readonly PropertyKey[]): boolean;
|
|
19
19
|
|
|
20
20
|
export { unset };
|