es-toolkit 1.12.0 → 1.13.0-dev.290
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 +16 -5
- package/dist/array/chunk.mjs +1 -1
- package/dist/array/compact.mjs +1 -1
- package/dist/array/countBy.mjs +1 -1
- package/dist/array/difference.mjs +1 -1
- package/dist/array/differenceBy.mjs +1 -1
- package/dist/array/differenceWith.mjs +1 -1
- package/dist/array/drop.mjs +1 -1
- package/dist/array/dropRight.mjs +1 -1
- package/dist/array/dropRightWhile.mjs +1 -1
- package/dist/array/dropWhile.mjs +1 -1
- package/dist/array/fill.mjs +1 -1
- package/dist/array/flatMap.mjs +1 -1
- package/dist/array/flatten.mjs +1 -1
- package/dist/array/flattenDeep.mjs +1 -1
- package/dist/array/forEachRight.mjs +1 -1
- package/dist/array/groupBy.mjs +1 -1
- package/dist/array/head.mjs +1 -1
- package/dist/array/index.js.map +1 -1
- package/dist/array/index.mjs +2 -2
- package/dist/array/initial.mjs +1 -1
- package/dist/array/intersection.mjs +1 -1
- package/dist/array/intersectionBy.mjs +1 -1
- package/dist/array/intersectionWith.mjs +1 -1
- package/dist/array/keyBy.mjs +1 -1
- package/dist/array/last.mjs +1 -1
- package/dist/array/maxBy.mjs +1 -1
- package/dist/array/minBy.mjs +1 -1
- package/dist/array/orderBy.mjs +1 -1
- package/dist/array/partition.mjs +1 -1
- package/dist/array/sample.mjs +1 -1
- package/dist/array/sampleSize.mjs +1 -1
- package/dist/array/shuffle.mjs +1 -1
- package/dist/array/tail.d.mts +24 -0
- package/dist/array/tail.d.ts +24 -0
- package/dist/array/tail.js.map +1 -1
- package/dist/array/tail.mjs +2 -2
- package/dist/array/take.mjs +1 -1
- package/dist/array/takeRight.mjs +1 -1
- package/dist/array/takeRightWhile.mjs +1 -1
- package/dist/array/takeWhile.mjs +1 -1
- package/dist/array/toFilled.mjs +1 -1
- package/dist/array/union.mjs +1 -1
- package/dist/array/unionBy.mjs +1 -1
- package/dist/array/unionWith.mjs +1 -1
- package/dist/array/uniq.mjs +1 -1
- package/dist/array/uniqBy.mjs +1 -1
- package/dist/array/uniqWith.mjs +1 -1
- package/dist/array/unzip.mjs +1 -1
- package/dist/array/unzipWith.mjs +1 -1
- package/dist/array/without.mjs +1 -1
- package/dist/array/xor.mjs +1 -1
- package/dist/array/xorBy.mjs +1 -1
- package/dist/array/xorWith.mjs +1 -1
- package/dist/array/zip.mjs +1 -1
- package/dist/array/zipObject.mjs +1 -1
- package/dist/array/zipWith.mjs +1 -1
- package/dist/browser.d.mts +2 -0
- package/dist/browser.d.ts +2 -0
- package/dist/browser.js +1108 -0
- package/dist/browser.js.map +1 -0
- package/dist/browser.mjs +108 -0
- package/dist/browser.mjs.map +1 -0
- package/dist/{chunk-424M7IR7.mjs → chunk-24FKGR6U.mjs} +6 -1
- package/dist/chunk-27QMXBLJ.mjs +9 -0
- package/dist/chunk-27QMXBLJ.mjs.map +1 -0
- package/dist/chunk-54TK5BIS.mjs +1 -0
- package/dist/chunk-5JN3CIWZ.mjs +373 -0
- package/dist/chunk-5JN3CIWZ.mjs.map +1 -0
- package/dist/chunk-B645AYL4.mjs +1 -0
- package/dist/{chunk-J3GE7DEU.mjs → chunk-CVVZHOJX.mjs} +2 -2
- package/dist/{chunk-XWPCDIFC.mjs → chunk-IIDZ3KAJ.mjs} +3 -3
- package/dist/chunk-MIGAC7F4.mjs +25 -0
- package/dist/chunk-MIGAC7F4.mjs.map +1 -0
- package/dist/{chunk-OF6NM4G7.mjs → chunk-TJ4Z5I7M.mjs} +1 -1
- package/dist/{chunk-OF6NM4G7.mjs.map → chunk-TJ4Z5I7M.mjs.map} +1 -1
- package/dist/{chunk-U7V3G7CR.mjs → chunk-WFZXCGEG.mjs} +2 -2
- package/dist/chunk-XGQWTHW6.mjs +34 -0
- package/dist/chunk-XGQWTHW6.mjs.map +1 -0
- package/dist/compat/index.d.mts +59 -3
- package/dist/compat/index.d.ts +59 -3
- package/dist/compat/index.js +105 -1
- package/dist/compat/index.js.map +1 -1
- package/dist/compat/index.mjs +90 -36
- package/dist/compat/index.mjs.map +1 -1
- package/dist/error/AbortError.mjs +1 -1
- package/dist/error/TimeoutError.mjs +1 -1
- package/dist/error/index.mjs +1 -1
- package/dist/function/debounce.mjs +1 -1
- package/dist/function/index.mjs +1 -1
- package/dist/function/negate.mjs +1 -1
- package/dist/function/noop.mjs +1 -1
- package/dist/function/once.mjs +1 -1
- package/dist/function/throttle.mjs +1 -1
- package/dist/index.d.mts +3 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +58 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +47 -35
- package/dist/math/clamp.mjs +1 -1
- package/dist/math/inRange.mjs +1 -1
- package/dist/math/index.mjs +7 -7
- package/dist/math/mean.mjs +1 -1
- package/dist/math/meanBy.mjs +1 -1
- package/dist/math/random.mjs +1 -1
- package/dist/math/randomInt.mjs +1 -1
- package/dist/math/range.mjs +1 -1
- package/dist/math/round.mjs +1 -1
- package/dist/math/sum.mjs +1 -1
- package/dist/math/sumBy.mjs +1 -1
- package/dist/object/clone.mjs +1 -1
- package/dist/object/flattenObject.d.mts +28 -0
- package/dist/object/flattenObject.d.ts +28 -0
- package/dist/object/flattenObject.js +77 -0
- package/dist/object/flattenObject.js.map +1 -0
- package/dist/object/flattenObject.mjs +9 -0
- package/dist/object/index.d.mts +1 -0
- package/dist/object/index.d.ts +1 -0
- package/dist/object/index.js +49 -0
- package/dist/object/index.js.map +1 -1
- package/dist/object/index.mjs +14 -9
- package/dist/object/invert.mjs +1 -1
- package/dist/object/omit.mjs +2 -2
- package/dist/object/omitBy.mjs +1 -1
- package/dist/object/pick.mjs +1 -1
- package/dist/object/pickBy.mjs +1 -1
- package/dist/predicate/index.d.mts +2 -0
- package/dist/predicate/index.d.ts +2 -0
- package/dist/predicate/index.js +30 -0
- package/dist/predicate/index.js.map +1 -1
- package/dist/predicate/index.mjs +15 -7
- package/dist/predicate/isEqual.mjs +1 -1
- package/dist/predicate/isLength.d.mts +3 -0
- package/dist/predicate/isLength.d.ts +3 -0
- package/dist/predicate/isLength.js +33 -0
- package/dist/predicate/isLength.js.map +1 -0
- package/dist/predicate/isLength.mjs +8 -0
- package/dist/predicate/isLength.mjs.map +1 -0
- package/dist/predicate/isNil.mjs +1 -1
- package/dist/predicate/isNotNil.mjs +1 -1
- package/dist/predicate/isNull.mjs +1 -1
- package/dist/predicate/isPlainObject.d.mts +16 -0
- package/dist/predicate/isPlainObject.d.ts +16 -0
- package/dist/predicate/isPlainObject.js +49 -0
- package/dist/predicate/isPlainObject.js.map +1 -0
- package/dist/predicate/isPlainObject.mjs +8 -0
- package/dist/predicate/isPlainObject.mjs.map +1 -0
- package/dist/predicate/isUndefined.mjs +1 -1
- package/dist/promise/delay.mjs +1 -1
- package/dist/promise/index.mjs +3 -3
- package/dist/promise/timeout.mjs +2 -2
- package/dist/promise/withTimeout.mjs +3 -3
- package/dist/string/camelCase.mjs +1 -1
- package/dist/string/capitalize.mjs +1 -1
- package/dist/string/index.mjs +7 -7
- package/dist/string/kebabCase.mjs +1 -1
- package/dist/string/lowerCase.mjs +1 -1
- package/dist/string/snakeCase.mjs +1 -1
- package/dist/string/startCase.mjs +1 -1
- package/package.json +3 -1
- package/umd/browser.global.js +2 -0
- package/dist/chunk-ASJF5D6C.mjs +0 -1
- package/dist/chunk-NKLIE2OI.mjs +0 -1
- package/dist/chunk-OSOLEQLZ.mjs +0 -1
- /package/dist/{chunk-424M7IR7.mjs.map → chunk-24FKGR6U.mjs.map} +0 -0
- /package/dist/{chunk-ASJF5D6C.mjs.map → chunk-54TK5BIS.mjs.map} +0 -0
- /package/dist/{chunk-NKLIE2OI.mjs.map → chunk-B645AYL4.mjs.map} +0 -0
- /package/dist/{chunk-J3GE7DEU.mjs.map → chunk-CVVZHOJX.mjs.map} +0 -0
- /package/dist/{chunk-XWPCDIFC.mjs.map → chunk-IIDZ3KAJ.mjs.map} +0 -0
- /package/dist/{chunk-U7V3G7CR.mjs.map → chunk-WFZXCGEG.mjs.map} +0 -0
- /package/dist/{chunk-OSOLEQLZ.mjs.map → object/flattenObject.mjs.map} +0 -0
package/dist/index.mjs
CHANGED
|
@@ -1,71 +1,86 @@
|
|
|
1
|
-
import "./chunk-
|
|
2
|
-
import "./chunk-4OIZM4HS.mjs";
|
|
3
|
-
import {
|
|
4
|
-
withTimeout
|
|
5
|
-
} from "./chunk-XWPCDIFC.mjs";
|
|
6
|
-
import "./chunk-J3GE7DEU.mjs";
|
|
1
|
+
import "./chunk-5JN3CIWZ.mjs";
|
|
7
2
|
import "./chunk-XT74R35S.mjs";
|
|
3
|
+
import {
|
|
4
|
+
kebabCase
|
|
5
|
+
} from "./chunk-EYYZQFOP.mjs";
|
|
6
|
+
import {
|
|
7
|
+
lowerCase
|
|
8
|
+
} from "./chunk-5IKVJGHO.mjs";
|
|
8
9
|
import {
|
|
9
10
|
snakeCase
|
|
10
11
|
} from "./chunk-F3WCQQET.mjs";
|
|
11
12
|
import {
|
|
12
13
|
startCase
|
|
13
14
|
} from "./chunk-QXTNZR7B.mjs";
|
|
15
|
+
import "./chunk-4OIZM4HS.mjs";
|
|
16
|
+
import {
|
|
17
|
+
withTimeout
|
|
18
|
+
} from "./chunk-IIDZ3KAJ.mjs";
|
|
19
|
+
import "./chunk-CVVZHOJX.mjs";
|
|
20
|
+
import {
|
|
21
|
+
delay
|
|
22
|
+
} from "./chunk-O64NE2P4.mjs";
|
|
14
23
|
import {
|
|
15
24
|
camelCase
|
|
16
25
|
} from "./chunk-Y5V7UAZZ.mjs";
|
|
17
26
|
import {
|
|
18
27
|
capitalize
|
|
19
28
|
} from "./chunk-U56ZOM7L.mjs";
|
|
29
|
+
import "./chunk-WVQ7YVRK.mjs";
|
|
30
|
+
import "./chunk-B645AYL4.mjs";
|
|
20
31
|
import {
|
|
21
|
-
|
|
22
|
-
} from "./chunk-
|
|
32
|
+
isNull
|
|
33
|
+
} from "./chunk-AIRSKN47.mjs";
|
|
23
34
|
import {
|
|
24
|
-
|
|
25
|
-
} from "./chunk-
|
|
26
|
-
import "./chunk-WVQ7YVRK.mjs";
|
|
27
|
-
import "./chunk-ASJF5D6C.mjs";
|
|
35
|
+
isUndefined
|
|
36
|
+
} from "./chunk-VH2PV426.mjs";
|
|
28
37
|
import {
|
|
29
38
|
isEqual
|
|
30
39
|
} from "./chunk-JYSV56US.mjs";
|
|
40
|
+
import {
|
|
41
|
+
isLength
|
|
42
|
+
} from "./chunk-27QMXBLJ.mjs";
|
|
31
43
|
import {
|
|
32
44
|
isNil
|
|
33
45
|
} from "./chunk-WMM7TZLG.mjs";
|
|
34
46
|
import {
|
|
35
47
|
isNotNil
|
|
36
48
|
} from "./chunk-BMRTZMRE.mjs";
|
|
49
|
+
import "./chunk-54TK5BIS.mjs";
|
|
37
50
|
import {
|
|
38
|
-
|
|
39
|
-
} from "./chunk-
|
|
40
|
-
import {
|
|
41
|
-
isUndefined
|
|
42
|
-
} from "./chunk-VH2PV426.mjs";
|
|
51
|
+
omitBy
|
|
52
|
+
} from "./chunk-BCTYOXT7.mjs";
|
|
43
53
|
import {
|
|
44
|
-
|
|
45
|
-
} from "./chunk-
|
|
46
|
-
import "./chunk-OSOLEQLZ.mjs";
|
|
54
|
+
pick
|
|
55
|
+
} from "./chunk-HPFDYUGP.mjs";
|
|
47
56
|
import {
|
|
48
57
|
pickBy
|
|
49
58
|
} from "./chunk-6CLH5YZ2.mjs";
|
|
50
59
|
import {
|
|
51
60
|
clone
|
|
52
61
|
} from "./chunk-U4JGKZ56.mjs";
|
|
62
|
+
import {
|
|
63
|
+
flattenObject
|
|
64
|
+
} from "./chunk-XGQWTHW6.mjs";
|
|
65
|
+
import {
|
|
66
|
+
isPlainObject
|
|
67
|
+
} from "./chunk-MIGAC7F4.mjs";
|
|
53
68
|
import {
|
|
54
69
|
invert
|
|
55
70
|
} from "./chunk-OLX53VEF.mjs";
|
|
56
71
|
import {
|
|
57
72
|
omit
|
|
58
|
-
} from "./chunk-
|
|
59
|
-
import {
|
|
60
|
-
omitBy
|
|
61
|
-
} from "./chunk-BCTYOXT7.mjs";
|
|
62
|
-
import {
|
|
63
|
-
pick
|
|
64
|
-
} from "./chunk-HPFDYUGP.mjs";
|
|
73
|
+
} from "./chunk-WFZXCGEG.mjs";
|
|
65
74
|
import "./chunk-FUS75PJ7.mjs";
|
|
75
|
+
import {
|
|
76
|
+
round
|
|
77
|
+
} from "./chunk-5PMKOZ2F.mjs";
|
|
66
78
|
import {
|
|
67
79
|
sumBy
|
|
68
80
|
} from "./chunk-5L4VWRFX.mjs";
|
|
81
|
+
import {
|
|
82
|
+
clamp
|
|
83
|
+
} from "./chunk-MLCL773E.mjs";
|
|
69
84
|
import {
|
|
70
85
|
inRange
|
|
71
86
|
} from "./chunk-BH6HLGBA.mjs";
|
|
@@ -81,12 +96,6 @@ import {
|
|
|
81
96
|
import {
|
|
82
97
|
range
|
|
83
98
|
} from "./chunk-DPH2KE6O.mjs";
|
|
84
|
-
import {
|
|
85
|
-
round
|
|
86
|
-
} from "./chunk-5PMKOZ2F.mjs";
|
|
87
|
-
import {
|
|
88
|
-
clamp
|
|
89
|
-
} from "./chunk-MLCL773E.mjs";
|
|
90
99
|
import "./chunk-DDH7K4QM.mjs";
|
|
91
100
|
import {
|
|
92
101
|
without
|
|
@@ -147,7 +156,7 @@ import {
|
|
|
147
156
|
} from "./chunk-G7UQ5PUR.mjs";
|
|
148
157
|
import {
|
|
149
158
|
tail
|
|
150
|
-
} from "./chunk-
|
|
159
|
+
} from "./chunk-TJ4Z5I7M.mjs";
|
|
151
160
|
import {
|
|
152
161
|
take
|
|
153
162
|
} from "./chunk-ME352XO7.mjs";
|
|
@@ -270,7 +279,7 @@ import {
|
|
|
270
279
|
import {
|
|
271
280
|
negate
|
|
272
281
|
} from "./chunk-BOOQBJN2.mjs";
|
|
273
|
-
import "./chunk-
|
|
282
|
+
import "./chunk-24FKGR6U.mjs";
|
|
274
283
|
export {
|
|
275
284
|
AbortError,
|
|
276
285
|
TimeoutError,
|
|
@@ -294,6 +303,7 @@ export {
|
|
|
294
303
|
flatMap,
|
|
295
304
|
flatten,
|
|
296
305
|
flattenDeep,
|
|
306
|
+
flattenObject,
|
|
297
307
|
forEachRight,
|
|
298
308
|
groupBy,
|
|
299
309
|
head,
|
|
@@ -304,9 +314,11 @@ export {
|
|
|
304
314
|
intersectionWith,
|
|
305
315
|
invert,
|
|
306
316
|
isEqual,
|
|
317
|
+
isLength,
|
|
307
318
|
isNil,
|
|
308
319
|
isNotNil,
|
|
309
320
|
isNull,
|
|
321
|
+
isPlainObject,
|
|
310
322
|
isUndefined,
|
|
311
323
|
kebabCase,
|
|
312
324
|
keyBy,
|
package/dist/math/clamp.mjs
CHANGED
package/dist/math/inRange.mjs
CHANGED
package/dist/math/index.mjs
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import "../chunk-FUS75PJ7.mjs";
|
|
2
|
+
import {
|
|
3
|
+
round
|
|
4
|
+
} from "../chunk-5PMKOZ2F.mjs";
|
|
2
5
|
import {
|
|
3
6
|
sumBy
|
|
4
7
|
} from "../chunk-5L4VWRFX.mjs";
|
|
8
|
+
import {
|
|
9
|
+
clamp
|
|
10
|
+
} from "../chunk-MLCL773E.mjs";
|
|
5
11
|
import {
|
|
6
12
|
inRange
|
|
7
13
|
} from "../chunk-BH6HLGBA.mjs";
|
|
@@ -17,19 +23,13 @@ import {
|
|
|
17
23
|
import {
|
|
18
24
|
range
|
|
19
25
|
} from "../chunk-DPH2KE6O.mjs";
|
|
20
|
-
import {
|
|
21
|
-
round
|
|
22
|
-
} from "../chunk-5PMKOZ2F.mjs";
|
|
23
|
-
import {
|
|
24
|
-
clamp
|
|
25
|
-
} from "../chunk-MLCL773E.mjs";
|
|
26
26
|
import {
|
|
27
27
|
randomInt
|
|
28
28
|
} from "../chunk-GIWAOOFY.mjs";
|
|
29
29
|
import {
|
|
30
30
|
random
|
|
31
31
|
} from "../chunk-SYWMYQYJ.mjs";
|
|
32
|
-
import "../chunk-
|
|
32
|
+
import "../chunk-24FKGR6U.mjs";
|
|
33
33
|
export {
|
|
34
34
|
clamp,
|
|
35
35
|
inRange,
|
package/dist/math/mean.mjs
CHANGED
package/dist/math/meanBy.mjs
CHANGED
package/dist/math/random.mjs
CHANGED
package/dist/math/randomInt.mjs
CHANGED
package/dist/math/range.mjs
CHANGED
package/dist/math/round.mjs
CHANGED
package/dist/math/sum.mjs
CHANGED
package/dist/math/sumBy.mjs
CHANGED
package/dist/object/clone.mjs
CHANGED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flattens a nested object into a single level object with dot-separated keys.
|
|
3
|
+
*
|
|
4
|
+
* @param {object} object - The object to flatten.
|
|
5
|
+
* @returns {Record<string, any>} - The flattened object.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* const nestedObject = {
|
|
9
|
+
* a: {
|
|
10
|
+
* b: {
|
|
11
|
+
* c: 1
|
|
12
|
+
* }
|
|
13
|
+
* },
|
|
14
|
+
* d: [2, 3]
|
|
15
|
+
* };
|
|
16
|
+
*
|
|
17
|
+
* const flattened = flattenObject(nestedObject);
|
|
18
|
+
* console.log(flattened);
|
|
19
|
+
* // Output:
|
|
20
|
+
* // {
|
|
21
|
+
* // 'a.b.c': 1,
|
|
22
|
+
* // 'd.0': 2,
|
|
23
|
+
* // 'd.1': 3
|
|
24
|
+
* // }
|
|
25
|
+
*/
|
|
26
|
+
declare function flattenObject(object: object): Record<string, any>;
|
|
27
|
+
|
|
28
|
+
export { flattenObject };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flattens a nested object into a single level object with dot-separated keys.
|
|
3
|
+
*
|
|
4
|
+
* @param {object} object - The object to flatten.
|
|
5
|
+
* @returns {Record<string, any>} - The flattened object.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* const nestedObject = {
|
|
9
|
+
* a: {
|
|
10
|
+
* b: {
|
|
11
|
+
* c: 1
|
|
12
|
+
* }
|
|
13
|
+
* },
|
|
14
|
+
* d: [2, 3]
|
|
15
|
+
* };
|
|
16
|
+
*
|
|
17
|
+
* const flattened = flattenObject(nestedObject);
|
|
18
|
+
* console.log(flattened);
|
|
19
|
+
* // Output:
|
|
20
|
+
* // {
|
|
21
|
+
* // 'a.b.c': 1,
|
|
22
|
+
* // 'd.0': 2,
|
|
23
|
+
* // 'd.1': 3
|
|
24
|
+
* // }
|
|
25
|
+
*/
|
|
26
|
+
declare function flattenObject(object: object): Record<string, any>;
|
|
27
|
+
|
|
28
|
+
export { flattenObject };
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/object/flattenObject.ts
|
|
21
|
+
var flattenObject_exports = {};
|
|
22
|
+
__export(flattenObject_exports, {
|
|
23
|
+
flattenObject: () => flattenObject
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(flattenObject_exports);
|
|
26
|
+
|
|
27
|
+
// src/predicate/isPlainObject.ts
|
|
28
|
+
function isPlainObject(object) {
|
|
29
|
+
if (typeof object !== "object") {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
if (object == null) {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
if (Object.getPrototypeOf(object) === null) {
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
if (object.toString() !== "[object Object]") {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
let proto = object;
|
|
42
|
+
while (Object.getPrototypeOf(proto) !== null) {
|
|
43
|
+
proto = Object.getPrototypeOf(proto);
|
|
44
|
+
}
|
|
45
|
+
return Object.getPrototypeOf(object) === proto;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// src/object/flattenObject.ts
|
|
49
|
+
function flattenObject(object) {
|
|
50
|
+
return flattenObjectImpl(object);
|
|
51
|
+
}
|
|
52
|
+
function flattenObjectImpl(object, prefix = "") {
|
|
53
|
+
const result = {};
|
|
54
|
+
const keys = Object.keys(object);
|
|
55
|
+
for (let i = 0; i < keys.length; i++) {
|
|
56
|
+
const key = keys[i];
|
|
57
|
+
const value = object[key];
|
|
58
|
+
const prefixedKey = prefix ? `${prefix}.${key}` : key;
|
|
59
|
+
if (isPlainObject(value) && Object.keys(value).length > 0) {
|
|
60
|
+
Object.assign(result, flattenObjectImpl(value, prefixedKey));
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
if (Array.isArray(value)) {
|
|
64
|
+
for (let index = 0; index < value.length; index++) {
|
|
65
|
+
result[`${prefixedKey}.${index}`] = value[index];
|
|
66
|
+
}
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
result[prefixedKey] = value;
|
|
70
|
+
}
|
|
71
|
+
return result;
|
|
72
|
+
}
|
|
73
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
74
|
+
0 && (module.exports = {
|
|
75
|
+
flattenObject
|
|
76
|
+
});
|
|
77
|
+
//# sourceMappingURL=flattenObject.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/object/flattenObject.ts","../../src/predicate/isPlainObject.ts"],"sourcesContent":["import { isPlainObject } from \"../predicate/isPlainObject.ts\";\n\n/**\n * Flattens a nested object into a single level object with dot-separated keys.\n * \n * @param {object} object - The object to flatten.\n * @returns {Record<string, any>} - The flattened object.\n * \n * @example\n * const nestedObject = {\n * a: {\n * b: {\n * c: 1\n * }\n * },\n * d: [2, 3]\n * };\n * \n * const flattened = flattenObject(nestedObject);\n * console.log(flattened); \n * // Output:\n * // {\n * // 'a.b.c': 1,\n * // 'd.0': 2,\n * // 'd.1': 3\n * // }\n */\nexport function flattenObject(object: object): Record<string, any> {\n return flattenObjectImpl(object);\n}\n\nfunction flattenObjectImpl(object: object, prefix = ''): Record<string, any> {\n const result: Record<string, any> = {};\n const keys = Object.keys(object);\n\n for (let i = 0; i < keys.length; i++) {\n const key = keys[i];\n const value = (object as any)[key];\n\n const prefixedKey = prefix ? `${prefix}.${key}` : key;\n\n if (isPlainObject(value) && Object.keys(value).length > 0) {\n Object.assign(result, flattenObjectImpl(value, prefixedKey));\n continue;\n }\n\n if (Array.isArray(value)) {\n for (let index = 0; index < value.length; index++) {\n result[`${prefixedKey}.${index}`] = value[index];\n }\n continue;\n }\n\n result[prefixedKey] = value;\n }\n\n return result;\n}","/**\n * Checks if a given value is a plain object.\n * \n * @param {object} object - The value to check.\n * @returns {boolean} - True if the value is a plain object, otherwise false.\n * \n * @example\n * console.log(isPlainObject({})); // true\n * console.log(isPlainObject([])); // false\n * console.log(isPlainObject(null)); // false\n * console.log(isPlainObject(Object.create(null))); // true\n * console.log(Buffer.from('hello, world')); // false\n */\nexport function isPlainObject(object: object): boolean {\n if (typeof object !== 'object') {\n return false;\n }\n\n if (object == null) {\n return false;\n }\n\n if (Object.getPrototypeOf(object) === null) {\n return true;\n }\n\n if (object.toString() !== '[object Object]') {\n return false;\n }\n\n let proto = object;\n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ACxB;AAEA,SAAO;AACT;","names":[]}
|
package/dist/object/index.d.mts
CHANGED
package/dist/object/index.d.ts
CHANGED
package/dist/object/index.js
CHANGED
|
@@ -35,6 +35,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
35
35
|
var object_exports = {};
|
|
36
36
|
__export(object_exports, {
|
|
37
37
|
clone: () => clone,
|
|
38
|
+
flattenObject: () => flattenObject,
|
|
38
39
|
invert: () => invert,
|
|
39
40
|
omit: () => omit,
|
|
40
41
|
omitBy: () => omitBy,
|
|
@@ -133,9 +134,57 @@ function clone(obj) {
|
|
|
133
134
|
function isPrimitive(value) {
|
|
134
135
|
return value == null || typeof value !== "object" && typeof value !== "function";
|
|
135
136
|
}
|
|
137
|
+
|
|
138
|
+
// src/predicate/isPlainObject.ts
|
|
139
|
+
function isPlainObject(object) {
|
|
140
|
+
if (typeof object !== "object") {
|
|
141
|
+
return false;
|
|
142
|
+
}
|
|
143
|
+
if (object == null) {
|
|
144
|
+
return false;
|
|
145
|
+
}
|
|
146
|
+
if (Object.getPrototypeOf(object) === null) {
|
|
147
|
+
return true;
|
|
148
|
+
}
|
|
149
|
+
if (object.toString() !== "[object Object]") {
|
|
150
|
+
return false;
|
|
151
|
+
}
|
|
152
|
+
let proto = object;
|
|
153
|
+
while (Object.getPrototypeOf(proto) !== null) {
|
|
154
|
+
proto = Object.getPrototypeOf(proto);
|
|
155
|
+
}
|
|
156
|
+
return Object.getPrototypeOf(object) === proto;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// src/object/flattenObject.ts
|
|
160
|
+
function flattenObject(object) {
|
|
161
|
+
return flattenObjectImpl(object);
|
|
162
|
+
}
|
|
163
|
+
function flattenObjectImpl(object, prefix = "") {
|
|
164
|
+
const result = {};
|
|
165
|
+
const keys = Object.keys(object);
|
|
166
|
+
for (let i = 0; i < keys.length; i++) {
|
|
167
|
+
const key = keys[i];
|
|
168
|
+
const value = object[key];
|
|
169
|
+
const prefixedKey = prefix ? `${prefix}.${key}` : key;
|
|
170
|
+
if (isPlainObject(value) && Object.keys(value).length > 0) {
|
|
171
|
+
Object.assign(result, flattenObjectImpl(value, prefixedKey));
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
174
|
+
if (Array.isArray(value)) {
|
|
175
|
+
for (let index = 0; index < value.length; index++) {
|
|
176
|
+
result[`${prefixedKey}.${index}`] = value[index];
|
|
177
|
+
}
|
|
178
|
+
continue;
|
|
179
|
+
}
|
|
180
|
+
result[prefixedKey] = value;
|
|
181
|
+
}
|
|
182
|
+
return result;
|
|
183
|
+
}
|
|
136
184
|
// Annotate the CommonJS export names for ESM import in node:
|
|
137
185
|
0 && (module.exports = {
|
|
138
186
|
clone,
|
|
187
|
+
flattenObject,
|
|
139
188
|
invert,
|
|
140
189
|
omit,
|
|
141
190
|
omitBy,
|
package/dist/object/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/object/index.ts","../../src/object/omit.ts","../../src/object/omitBy.ts","../../src/object/pick.ts","../../src/object/pickBy.ts","../../src/object/invert.ts","../../src/object/clone.ts"],"sourcesContent":["export { omit } from './omit.ts';\nexport { omitBy } from './omitBy.ts';\nexport { pick } from './pick.ts';\nexport { pickBy } from './pickBy.ts';\nexport { invert } from './invert.ts';\nexport { clone } from './clone.ts';\n","/**\n * Creates a new object with specified keys omitted.\n *\n * This function takes an object and an array of keys, and returns a new object that\n * excludes the properties corresponding to the specified keys.\n *\n * @template T - The type of object.\n * @template K - The type of keys in object.\n * @param {T} obj - The object to omit keys from.\n * @param {K[]} keys - An array of keys to be omitted from the object.\n * @returns {Omit<T, K>} A new object with the specified keys omitted.\n *\n * @example\n * const obj = { a: 1, b: 2, c: 3 };\n * const result = omit(obj, ['b', 'c']);\n * // result will be { a: 1 }\n */\nexport function omit<T extends Record<string, any>, K extends keyof T>(obj: T, keys: K[]): Omit<T, K> {\n const result = { ...obj };\n\n for (const key of keys) {\n delete result[key];\n }\n\n return result as Omit<T, K>;\n}\n","/**\n * Creates a new object composed of the properties that do not satisfy the predicate function.\n *\n * This function takes an object and a predicate function, and returns a new object that\n * includes only the properties for which the predicate function returns false.\n *\n * @template T - The type of object.\n * @param {T} obj - The object to omit properties from.\n * @param {(value: T[string], key: keyof T) => boolean} shouldOmit - A predicate function that determines\n * whether a property should be omitted. It takes the property's key and value as arguments and returns `true`\n * if the property should be omitted, and `false` otherwise.\n * @returns {Partial<T>} A new object with the properties that do not satisfy the predicate function.\n *\n * @example\n * const obj = { a: 1, b: 'omit', c: 3 };\n * const shouldOmit = (key, value) => typeof value === 'string';\n * const result = omitBy(obj, shouldOmit);\n * // result will be { a: 1, c: 3 }\n */\nexport function omitBy<T extends Record<string, any>>(\n obj: T,\n shouldOmit: (value: T[keyof T], key: keyof T) => boolean\n): Partial<T> {\n const result: Partial<T> = {};\n\n for (const [key, value] of Object.entries(obj)) {\n if (shouldOmit(value, key)) {\n continue;\n }\n\n (result as any)[key] = value;\n }\n\n return result;\n}\n","/**\n * Creates a new object composed of the picked object properties.\n *\n * This function takes an object and an array of keys, and returns a new object that\n * includes only the properties corresponding to the specified keys.\n *\n * @template T - The type of object.\n * @template K - The type of keys in object.\n * @param {T} obj - The object to pick keys from.\n * @param {K[]} keys - An array of keys to be picked from the object.\n * @returns {Pick<T, K>} A new object with the specified keys picked.\n *\n * @example\n * const obj = { a: 1, b: 2, c: 3 };\n * const result = pick(obj, ['a', 'c']);\n * // result will be { a: 1, c: 3 }\n */\nexport function pick<T extends Record<string, any>, K extends keyof T>(obj: T, keys: K[]): Pick<T, K> {\n const result = {} as Pick<T, K>;\n\n for (const key of keys) {\n result[key] = obj[key];\n }\n\n return result;\n}\n","/**\n * Creates a new object composed of the properties that satisfy the predicate function.\n *\n * This function takes an object and a predicate function, and returns a new object that\n * includes only the properties for which the predicate function returns true.\n *\n * @template T - The type of object.\n * @param {T} obj - The object to pick properties from.\n * @param {(value: T[keyof T], key: keyof T) => boolean} shouldPick - A predicate function that determines\n * whether a property should be picked. It takes the property's key and value as arguments and returns `true`\n * if the property should be picked, and `false` otherwise.\n * @returns {Partial<T>} A new object with the properties that satisfy the predicate function.\n *\n * @example\n * const obj = { a: 1, b: 'pick', c: 3 };\n * const shouldPick = (value) => typeof value === 'string';\n * const result = pickBy(obj, shouldPick);\n * // result will be { b: 'pick' }\n */\nexport function pickBy<T extends Record<string, any>>(\n obj: T,\n shouldPick: (value: T[keyof T], key: keyof T) => boolean\n): Partial<T> {\n const result: Partial<T> = {};\n\n for (const [key, value] of Object.entries(obj)) {\n if (!shouldPick(value, key)) {\n continue;\n }\n\n (result as any)[key] = value;\n }\n\n return result;\n}\n","/**\n * Inverts the keys and values of an object. The keys of the input object become the values of the output object and vice versa.\n *\n * This function takes an object and creates a new object by inverting its keys and values. If the input object has duplicate values,\n * the key of the last occurrence will be used as the value for the new key in the output object. It effectively creates a reverse mapping\n * of the input object's key-value pairs.\n *\n * @template K - Type of the keys in the input object (string, number, symbol)\n * @template V - Type of the values in the input object (string, number, symbol)\n * @param {Record<K, V>} obj - The input object whose keys and values are to be inverted\n * @returns {{ [key in V]: K }} - A new object with keys and values inverted\n *\n * @example\n * invert({ a: 1, b: 2, c: 3 }); // { 1: 'a', 2: 'b', 3: 'c' }\n * invert({ 1: 'a', 2: 'b', 3: 'c' }); // { a: '1', b: '2', c: '3' }\n * invert({ a: 1, 2: 'b', c: 3, 4: 'd' }); // { 1: 'a', b: '2', 3: 'c', d: '4' }\n * invert({ a: Symbol('sym1'), b: Symbol('sym2') }); // { [Symbol('sym1')]: 'a', [Symbol('sym2')]: 'b' }\n */\nexport function invert<K extends PropertyKey, V extends PropertyKey>(obj: Record<K, V>): { [key in V]: K } {\n const result = {} as { [key in V]: K };\n\n const keys = Object.keys(obj) as K[];\n \n for (let i = 0; i < keys.length; i++) {\n const key = keys[i];\n const value = obj[key];\n result[value] = key;\n }\n\n return result;\n}\n","/**\n * Creates a shallow clone of the given object.\n *\n * @template T - The type of the object.\n * @param {T} obj - The object to clone.\n * @returns {T} - A shallow clone of the given object.\n *\n * @example\n * // Clone a primitive values\n * const num = 29;\n * const clonedNum = clone(num);\n * console.log(clonedNum); // 29\n * console.log(clonedNum === num) ; // true\n *\n * @example\n * // Clone an array\n * const arr = [1, 2, 3];\n * const clonedArr = clone(arr);\n * console.log(clonedArr); // [1, 2, 3]\n * console.log(clonedArr === arr); // false\n *\n * @example\n * // Clone an object\n * const obj = { a: 1, b: 'es-toolkit', c: [1, 2, 3] };\n * const clonedObj = clone(obj);\n * console.log(clonedObj); // { a: 1, b: 'es-toolkit', c: [1, 2, 3] }\n * console.log(clonedObj === obj); // false\n */\nexport function clone<T>(obj: T): T {\n if (isPrimitive(obj)) {\n return obj;\n }\n\n if (Array.isArray(obj)) {\n return obj.slice() as T;\n }\n\n if (obj instanceof Date) {\n return new Date(obj.getTime()) as T;\n }\n\n if (obj instanceof RegExp) {\n return new RegExp(obj.source, obj.flags) as T;\n }\n\n if (obj instanceof Map) {\n const result = new Map();\n for (const [key, value] of obj) {\n result.set(key, value);\n }\n return result as T;\n }\n\n if (obj instanceof Set) {\n const result = new Set();\n for (const value of obj) {\n result.add(value);\n }\n return result as T;\n }\n\n if (typeof obj === \"object\") {\n return Object.assign({}, obj) as T;\n }\n return obj;\n}\n\ntype Primitive = null | undefined | string | number | boolean | symbol | bigint;\n\nfunction isPrimitive(value: unknown): value is Primitive {\n return value == null ||\n (typeof value !== \"object\" && typeof value !== \"function\");\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACiBO,SAAS,KAAuD,KAAQ,MAAuB;AACpG,QAAM,SAAS,mBAAK;AAEpB,aAAW,OAAO,MAAM;AACtB,WAAO,OAAO,GAAG;AAAA,EACnB;AAEA,SAAO;AACT;;;ACNO,SAAS,OACd,KACA,YACY;AACZ,QAAM,SAAqB,CAAC;AAE5B,aAAW,C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AAO,IAAI,KAAK,KAAK;AAAA,IACvB;AACA,WAAO;AAAA,EACT;AAEA,MAAI,eAAe,KAAK;AACtB,UAAM,SAAS,oBAAI,IAAI;AACvB,eAAW,SAAS,KAAK;AACvB,aAAO,IAAI,KAAK;AAAA,IAClB;AACA,WAAO;AAAA,EACT;AAEA,MAAI,OAAO,QAAQ,UAAU;AAC3B,WAAO,OAAO,OAAO,CAAC,GAAG,GAAG;AAAA,EAC9B;AACA,SAAO;AACT;AAIA,SAAS,YAAY,OAAoC;AACvD,SAAO,SAAS,QACb,OAAO,UAAU,YAAY,OAAO,UAAU;AACnD;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/object/index.ts","../../src/object/omit.ts","../../src/object/omitBy.ts","../../src/object/pick.ts","../../src/object/pickBy.ts","../../src/object/invert.ts","../../src/object/clone.ts","../../src/predicate/isPlainObject.ts","../../src/object/flattenObject.ts"],"sourcesContent":["export { omit } from './omit.ts';\nexport { omitBy } from './omitBy.ts';\nexport { pick } from './pick.ts';\nexport { pickBy } from './pickBy.ts';\nexport { invert } from './invert.ts';\nexport { clone } from './clone.ts';\nexport { flattenObject } from './flattenObject.ts';","/**\n * Creates a new object with specified keys omitted.\n *\n * This function takes an object and an array of keys, and returns a new object that\n * excludes the properties corresponding to the specified keys.\n *\n * @template T - The type of object.\n * @template K - The type of keys in object.\n * @param {T} obj - The object to omit keys from.\n * @param {K[]} keys - An array of keys to be omitted from the object.\n * @returns {Omit<T, K>} A new object with the specified keys omitted.\n *\n * @example\n * const obj = { a: 1, b: 2, c: 3 };\n * const result = omit(obj, ['b', 'c']);\n * // result will be { a: 1 }\n */\nexport function omit<T extends Record<string, any>, K extends keyof T>(obj: T, keys: K[]): Omit<T, K> {\n const result = { ...obj };\n\n for (const key of keys) {\n delete result[key];\n }\n\n return result as Omit<T, K>;\n}\n","/**\n * Creates a new object composed of the properties that do not satisfy the predicate function.\n *\n * This function takes an object and a predicate function, and returns a new object that\n * includes only the properties for which the predicate function returns false.\n *\n * @template T - The type of object.\n * @param {T} obj - The object to omit properties from.\n * @param {(value: T[string], key: keyof T) => boolean} shouldOmit - A predicate function that determines\n * whether a property should be omitted. It takes the property's key and value as arguments and returns `true`\n * if the property should be omitted, and `false` otherwise.\n * @returns {Partial<T>} A new object with the properties that do not satisfy the predicate function.\n *\n * @example\n * const obj = { a: 1, b: 'omit', c: 3 };\n * const shouldOmit = (key, value) => typeof value === 'string';\n * const result = omitBy(obj, shouldOmit);\n * // result will be { a: 1, c: 3 }\n */\nexport function omitBy<T extends Record<string, any>>(\n obj: T,\n shouldOmit: (value: T[keyof T], key: keyof T) => boolean\n): Partial<T> {\n const result: Partial<T> = {};\n\n for (const [key, value] of Object.entries(obj)) {\n if (shouldOmit(value, key)) {\n continue;\n }\n\n (result as any)[key] = value;\n }\n\n return result;\n}\n","/**\n * Creates a new object composed of the picked object properties.\n *\n * This function takes an object and an array of keys, and returns a new object that\n * includes only the properties corresponding to the specified keys.\n *\n * @template T - The type of object.\n * @template K - The type of keys in object.\n * @param {T} obj - The object to pick keys from.\n * @param {K[]} keys - An array of keys to be picked from the object.\n * @returns {Pick<T, K>} A new object with the specified keys picked.\n *\n * @example\n * const obj = { a: 1, b: 2, c: 3 };\n * const result = pick(obj, ['a', 'c']);\n * // result will be { a: 1, c: 3 }\n */\nexport function pick<T extends Record<string, any>, K extends keyof T>(obj: T, keys: K[]): Pick<T, K> {\n const result = {} as Pick<T, K>;\n\n for (const key of keys) {\n result[key] = obj[key];\n }\n\n return result;\n}\n","/**\n * Creates a new object composed of the properties that satisfy the predicate function.\n *\n * This function takes an object and a predicate function, and returns a new object that\n * includes only the properties for which the predicate function returns true.\n *\n * @template T - The type of object.\n * @param {T} obj - The object to pick properties from.\n * @param {(value: T[keyof T], key: keyof T) => boolean} shouldPick - A predicate function that determines\n * whether a property should be picked. It takes the property's key and value as arguments and returns `true`\n * if the property should be picked, and `false` otherwise.\n * @returns {Partial<T>} A new object with the properties that satisfy the predicate function.\n *\n * @example\n * const obj = { a: 1, b: 'pick', c: 3 };\n * const shouldPick = (value) => typeof value === 'string';\n * const result = pickBy(obj, shouldPick);\n * // result will be { b: 'pick' }\n */\nexport function pickBy<T extends Record<string, any>>(\n obj: T,\n shouldPick: (value: T[keyof T], key: keyof T) => boolean\n): Partial<T> {\n const result: Partial<T> = {};\n\n for (const [key, value] of Object.entries(obj)) {\n if (!shouldPick(value, key)) {\n continue;\n }\n\n (result as any)[key] = value;\n }\n\n return result;\n}\n","/**\n * Inverts the keys and values of an object. The keys of the input object become the values of the output object and vice versa.\n *\n * This function takes an object and creates a new object by inverting its keys and values. If the input object has duplicate values,\n * the key of the last occurrence will be used as the value for the new key in the output object. It effectively creates a reverse mapping\n * of the input object's key-value pairs.\n *\n * @template K - Type of the keys in the input object (string, number, symbol)\n * @template V - Type of the values in the input object (string, number, symbol)\n * @param {Record<K, V>} obj - The input object whose keys and values are to be inverted\n * @returns {{ [key in V]: K }} - A new object with keys and values inverted\n *\n * @example\n * invert({ a: 1, b: 2, c: 3 }); // { 1: 'a', 2: 'b', 3: 'c' }\n * invert({ 1: 'a', 2: 'b', 3: 'c' }); // { a: '1', b: '2', c: '3' }\n * invert({ a: 1, 2: 'b', c: 3, 4: 'd' }); // { 1: 'a', b: '2', 3: 'c', d: '4' }\n * invert({ a: Symbol('sym1'), b: Symbol('sym2') }); // { [Symbol('sym1')]: 'a', [Symbol('sym2')]: 'b' }\n */\nexport function invert<K extends PropertyKey, V extends PropertyKey>(obj: Record<K, V>): { [key in V]: K } {\n const result = {} as { [key in V]: K };\n\n const keys = Object.keys(obj) as K[];\n \n for (let i = 0; i < keys.length; i++) {\n const key = keys[i];\n const value = obj[key];\n result[value] = key;\n }\n\n return result;\n}\n","/**\n * Creates a shallow clone of the given object.\n *\n * @template T - The type of the object.\n * @param {T} obj - The object to clone.\n * @returns {T} - A shallow clone of the given object.\n *\n * @example\n * // Clone a primitive values\n * const num = 29;\n * const clonedNum = clone(num);\n * console.log(clonedNum); // 29\n * console.log(clonedNum === num) ; // true\n *\n * @example\n * // Clone an array\n * const arr = [1, 2, 3];\n * const clonedArr = clone(arr);\n * console.log(clonedArr); // [1, 2, 3]\n * console.log(clonedArr === arr); // false\n *\n * @example\n * // Clone an object\n * const obj = { a: 1, b: 'es-toolkit', c: [1, 2, 3] };\n * const clonedObj = clone(obj);\n * console.log(clonedObj); // { a: 1, b: 'es-toolkit', c: [1, 2, 3] }\n * console.log(clonedObj === obj); // false\n */\nexport function clone<T>(obj: T): T {\n if (isPrimitive(obj)) {\n return obj;\n }\n\n if (Array.isArray(obj)) {\n return obj.slice() as T;\n }\n\n if (obj instanceof Date) {\n return new Date(obj.getTime()) as T;\n }\n\n if (obj instanceof RegExp) {\n return new RegExp(obj.source, obj.flags) as T;\n }\n\n if (obj instanceof Map) {\n const result = new Map();\n for (const [key, value] of obj) {\n result.set(key, value);\n }\n return result as T;\n }\n\n if (obj instanceof Set) {\n const result = new Set();\n for (const value of obj) {\n result.add(value);\n }\n return result as T;\n }\n\n if (typeof obj === \"object\") {\n return Object.assign({}, obj) as T;\n }\n return obj;\n}\n\ntype Primitive = null | undefined | string | number | boolean | symbol | bigint;\n\nfunction isPrimitive(value: unknown): value is Primitive {\n return value == null ||\n (typeof value !== \"object\" && typeof value !== \"function\");\n}\n","/**\n * Checks if a given value is a plain object.\n * \n * @param {object} object - The value to check.\n * @returns {boolean} - True if the value is a plain object, otherwise false.\n * \n * @example\n * console.log(isPlainObject({})); // true\n * console.log(isPlainObject([])); // false\n * console.log(isPlainObject(null)); // false\n * console.log(isPlainObject(Object.create(null))); // true\n * console.log(Buffer.from('hello, world')); // false\n */\nexport function isPlainObject(object: object): boolean {\n if (typeof object !== 'object') {\n return false;\n }\n\n if (object == null) {\n return false;\n }\n\n if (Object.getPrototypeOf(object) === null) {\n return true;\n }\n\n if (object.toString() !== '[object Object]') {\n return false;\n }\n\n let proto = object;\n\n while (Object.getPrototypeOf(proto) !== null) {\n proto = Object.getPrototypeOf(proto);\n }\n\n return Object.getPrototypeOf(object) === proto;\n}","import { isPlainObject } from \"../predicate/isPlainObject.ts\";\n\n/**\n * Flattens a nested object into a single level object with dot-separated keys.\n * \n * @param {object} object - The object to flatten.\n * @returns {Record<string, any>} - The flattened object.\n * \n * @example\n * const nestedObject = {\n * a: {\n * b: {\n * c: 1\n * }\n * },\n * d: [2, 3]\n * };\n * \n * const flattened = flattenObject(nestedObject);\n * console.log(flattened); \n * // Output:\n * // {\n * // 'a.b.c': 1,\n * // 'd.0': 2,\n * // 'd.1': 3\n * // }\n */\nexport function flattenObject(object: object): Record<string, any> {\n return flattenObjectImpl(object);\n}\n\nfunction flattenObjectImpl(object: object, prefix = ''): Record<string, any> {\n const result: Record<string, any> = {};\n const keys = Object.keys(object);\n\n for (let i = 0; i < keys.length; i++) {\n const key = keys[i];\n const value = (object as any)[key];\n\n const prefixedKey = prefix ? `${prefix}.${key}` : key;\n\n if (isPlainObject(value) && Object.keys(value).length > 0) {\n Object.assign(result, flattenObjectImpl(value, prefixedKey));\n continue;\n }\n\n if (Array.isArray(value)) {\n for (let index = 0; index < value.length; index++) {\n result[`${prefixedKey}.${index}`] = value[index];\n }\n continue;\n }\n\n result[prefixedKey] = value;\n }\n\n return result;\n}"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACiBO,SAAS,KAAuD,KAAQ,MAAuB;AACpG,QAAM,SAAS,mBAAK;AAEpB,aAAW,OAAO,MAAM;AACtB,WAAO,OAAO,GAAG;AAAA,EACnB;AAEA,SAAO;AACT;;;ACNO,SAAS,OACd,KACA,YACY;AACZ,QAAM,SAAqB,CAAC;AAE5B,aAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,GAAG,GAAG;AAC9C,QAAI,WAAW,OAAO,GAAG,GAAG;AAC1B;AAAA,IACF;AAEA,IAAC,OAAe,GAAG,IAAI;AAAA,EACzB;AAEA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AAE,IAAI,MAAM,KAAK;AAAA,MACjD;AACA;AAAA,IACF;AAEA,WAAO,WAAW,IAAI;AAAA,EACxB;AAEA,SAAO;AACT;","names":[]}
|
package/dist/object/index.mjs
CHANGED
|
@@ -1,25 +1,30 @@
|
|
|
1
|
-
import "../chunk-
|
|
1
|
+
import "../chunk-54TK5BIS.mjs";
|
|
2
|
+
import {
|
|
3
|
+
omitBy
|
|
4
|
+
} from "../chunk-BCTYOXT7.mjs";
|
|
5
|
+
import {
|
|
6
|
+
pick
|
|
7
|
+
} from "../chunk-HPFDYUGP.mjs";
|
|
2
8
|
import {
|
|
3
9
|
pickBy
|
|
4
10
|
} from "../chunk-6CLH5YZ2.mjs";
|
|
5
11
|
import {
|
|
6
12
|
clone
|
|
7
13
|
} from "../chunk-U4JGKZ56.mjs";
|
|
14
|
+
import {
|
|
15
|
+
flattenObject
|
|
16
|
+
} from "../chunk-XGQWTHW6.mjs";
|
|
17
|
+
import "../chunk-MIGAC7F4.mjs";
|
|
8
18
|
import {
|
|
9
19
|
invert
|
|
10
20
|
} from "../chunk-OLX53VEF.mjs";
|
|
11
21
|
import {
|
|
12
22
|
omit
|
|
13
|
-
} from "../chunk-
|
|
14
|
-
import
|
|
15
|
-
omitBy
|
|
16
|
-
} from "../chunk-BCTYOXT7.mjs";
|
|
17
|
-
import {
|
|
18
|
-
pick
|
|
19
|
-
} from "../chunk-HPFDYUGP.mjs";
|
|
20
|
-
import "../chunk-424M7IR7.mjs";
|
|
23
|
+
} from "../chunk-WFZXCGEG.mjs";
|
|
24
|
+
import "../chunk-24FKGR6U.mjs";
|
|
21
25
|
export {
|
|
22
26
|
clone,
|
|
27
|
+
flattenObject,
|
|
23
28
|
invert,
|
|
24
29
|
omit,
|
|
25
30
|
omitBy,
|
package/dist/object/invert.mjs
CHANGED