es-toolkit 1.12.0-dev.280 → 1.12.0-dev.282
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/array/index.mjs +31 -31
- package/dist/{chunk-Y5V7UAZZ.mjs → chunk-32AEPQYI.mjs} +4 -4
- package/dist/chunk-54TK5BIS.mjs +1 -0
- package/dist/chunk-MIGAC7F4.mjs +25 -0
- package/dist/chunk-MIGAC7F4.mjs.map +1 -0
- package/dist/chunk-WGX4WINP.mjs +1 -0
- package/dist/chunk-XGQWTHW6.mjs +34 -0
- package/dist/chunk-XGQWTHW6.mjs.map +1 -0
- package/dist/compat/index.d.mts +26 -1
- package/dist/compat/index.d.ts +26 -1
- package/dist/compat/index.js +81 -0
- package/dist/compat/index.js.map +1 -1
- package/dist/compat/index.mjs +105 -69
- package/dist/compat/index.mjs.map +1 -1
- package/dist/function/index.mjs +6 -6
- package/dist/index.d.mts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +51 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +77 -69
- 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/flattenObject.mjs.map +1 -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 +9 -4
- package/dist/predicate/index.d.mts +1 -0
- package/dist/predicate/index.d.ts +1 -0
- package/dist/predicate/index.js +23 -0
- package/dist/predicate/index.js.map +1 -1
- package/dist/predicate/index.mjs +7 -3
- 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/string/camelCase.mjs +2 -2
- package/dist/string/index.mjs +8 -8
- package/package.json +1 -1
- package/dist/chunk-ASJF5D6C.mjs +0 -1
- package/dist/chunk-OSOLEQLZ.mjs +0 -1
- /package/dist/{chunk-Y5V7UAZZ.mjs.map → chunk-32AEPQYI.mjs.map} +0 -0
- /package/dist/{chunk-ASJF5D6C.mjs.map → chunk-54TK5BIS.mjs.map} +0 -0
- /package/dist/{chunk-OSOLEQLZ.mjs.map → chunk-WGX4WINP.mjs.map} +0 -0
package/dist/index.mjs
CHANGED
|
@@ -4,7 +4,16 @@ import {
|
|
|
4
4
|
withTimeout
|
|
5
5
|
} from "./chunk-XWPCDIFC.mjs";
|
|
6
6
|
import "./chunk-J3GE7DEU.mjs";
|
|
7
|
+
import {
|
|
8
|
+
delay
|
|
9
|
+
} from "./chunk-O64NE2P4.mjs";
|
|
7
10
|
import "./chunk-XT74R35S.mjs";
|
|
11
|
+
import {
|
|
12
|
+
kebabCase
|
|
13
|
+
} from "./chunk-EYYZQFOP.mjs";
|
|
14
|
+
import {
|
|
15
|
+
lowerCase
|
|
16
|
+
} from "./chunk-5IKVJGHO.mjs";
|
|
8
17
|
import {
|
|
9
18
|
snakeCase
|
|
10
19
|
} from "./chunk-F3WCQQET.mjs";
|
|
@@ -13,18 +22,15 @@ import {
|
|
|
13
22
|
} from "./chunk-QXTNZR7B.mjs";
|
|
14
23
|
import {
|
|
15
24
|
camelCase
|
|
16
|
-
} from "./chunk-
|
|
25
|
+
} from "./chunk-32AEPQYI.mjs";
|
|
26
|
+
import "./chunk-WVQ7YVRK.mjs";
|
|
17
27
|
import {
|
|
18
28
|
capitalize
|
|
19
29
|
} from "./chunk-U56ZOM7L.mjs";
|
|
30
|
+
import "./chunk-WGX4WINP.mjs";
|
|
20
31
|
import {
|
|
21
|
-
|
|
22
|
-
} from "./chunk-
|
|
23
|
-
import {
|
|
24
|
-
lowerCase
|
|
25
|
-
} from "./chunk-5IKVJGHO.mjs";
|
|
26
|
-
import "./chunk-WVQ7YVRK.mjs";
|
|
27
|
-
import "./chunk-ASJF5D6C.mjs";
|
|
32
|
+
isUndefined
|
|
33
|
+
} from "./chunk-VH2PV426.mjs";
|
|
28
34
|
import {
|
|
29
35
|
isEqual
|
|
30
36
|
} from "./chunk-JYSV56US.mjs";
|
|
@@ -37,19 +43,22 @@ import {
|
|
|
37
43
|
import {
|
|
38
44
|
isNull
|
|
39
45
|
} from "./chunk-AIRSKN47.mjs";
|
|
46
|
+
import "./chunk-54TK5BIS.mjs";
|
|
40
47
|
import {
|
|
41
|
-
|
|
42
|
-
} from "./chunk-
|
|
43
|
-
import {
|
|
44
|
-
delay
|
|
45
|
-
} from "./chunk-O64NE2P4.mjs";
|
|
46
|
-
import "./chunk-OSOLEQLZ.mjs";
|
|
48
|
+
pick
|
|
49
|
+
} from "./chunk-HPFDYUGP.mjs";
|
|
47
50
|
import {
|
|
48
51
|
pickBy
|
|
49
52
|
} from "./chunk-6CLH5YZ2.mjs";
|
|
50
53
|
import {
|
|
51
54
|
clone
|
|
52
55
|
} from "./chunk-U4JGKZ56.mjs";
|
|
56
|
+
import {
|
|
57
|
+
flattenObject
|
|
58
|
+
} from "./chunk-XGQWTHW6.mjs";
|
|
59
|
+
import {
|
|
60
|
+
isPlainObject
|
|
61
|
+
} from "./chunk-MIGAC7F4.mjs";
|
|
53
62
|
import {
|
|
54
63
|
invert
|
|
55
64
|
} from "./chunk-OLX53VEF.mjs";
|
|
@@ -59,9 +68,6 @@ import {
|
|
|
59
68
|
import {
|
|
60
69
|
omitBy
|
|
61
70
|
} from "./chunk-BCTYOXT7.mjs";
|
|
62
|
-
import {
|
|
63
|
-
pick
|
|
64
|
-
} from "./chunk-HPFDYUGP.mjs";
|
|
65
71
|
import "./chunk-FUS75PJ7.mjs";
|
|
66
72
|
import {
|
|
67
73
|
sumBy
|
|
@@ -84,10 +90,35 @@ import {
|
|
|
84
90
|
import {
|
|
85
91
|
round
|
|
86
92
|
} from "./chunk-5PMKOZ2F.mjs";
|
|
93
|
+
import "./chunk-236H5JZJ.mjs";
|
|
94
|
+
import {
|
|
95
|
+
debounce
|
|
96
|
+
} from "./chunk-3IP4JVLL.mjs";
|
|
97
|
+
import {
|
|
98
|
+
negate
|
|
99
|
+
} from "./chunk-BOOQBJN2.mjs";
|
|
100
|
+
import {
|
|
101
|
+
noop
|
|
102
|
+
} from "./chunk-LKXCOLNY.mjs";
|
|
103
|
+
import {
|
|
104
|
+
once
|
|
105
|
+
} from "./chunk-CMBC4MXG.mjs";
|
|
106
|
+
import {
|
|
107
|
+
throttle
|
|
108
|
+
} from "./chunk-QOJGMVVR.mjs";
|
|
87
109
|
import {
|
|
88
110
|
clamp
|
|
89
111
|
} from "./chunk-MLCL773E.mjs";
|
|
90
112
|
import "./chunk-DDH7K4QM.mjs";
|
|
113
|
+
import {
|
|
114
|
+
zipWith
|
|
115
|
+
} from "./chunk-4KYXHZ4R.mjs";
|
|
116
|
+
import {
|
|
117
|
+
unzip
|
|
118
|
+
} from "./chunk-UYZKMBDO.mjs";
|
|
119
|
+
import {
|
|
120
|
+
unzipWith
|
|
121
|
+
} from "./chunk-IFNXROZR.mjs";
|
|
91
122
|
import {
|
|
92
123
|
without
|
|
93
124
|
} from "./chunk-PYEYV7BY.mjs";
|
|
@@ -107,8 +138,11 @@ import {
|
|
|
107
138
|
zipObject
|
|
108
139
|
} from "./chunk-6GWEY5EL.mjs";
|
|
109
140
|
import {
|
|
110
|
-
|
|
111
|
-
} from "./chunk-
|
|
141
|
+
takeWhile
|
|
142
|
+
} from "./chunk-2IXFGSUA.mjs";
|
|
143
|
+
import {
|
|
144
|
+
toFilled
|
|
145
|
+
} from "./chunk-OP4OAKQJ.mjs";
|
|
112
146
|
import {
|
|
113
147
|
union
|
|
114
148
|
} from "./chunk-R6QA7PLZ.mjs";
|
|
@@ -128,11 +162,11 @@ import {
|
|
|
128
162
|
uniqWith
|
|
129
163
|
} from "./chunk-237HGSZS.mjs";
|
|
130
164
|
import {
|
|
131
|
-
|
|
132
|
-
} from "./chunk-
|
|
165
|
+
partition
|
|
166
|
+
} from "./chunk-DN3NOZ3H.mjs";
|
|
133
167
|
import {
|
|
134
|
-
|
|
135
|
-
} from "./chunk-
|
|
168
|
+
sample
|
|
169
|
+
} from "./chunk-2KNLZB7V.mjs";
|
|
136
170
|
import {
|
|
137
171
|
sampleSize
|
|
138
172
|
} from "./chunk-EHSKB6DF.mjs";
|
|
@@ -158,11 +192,11 @@ import {
|
|
|
158
192
|
takeRightWhile
|
|
159
193
|
} from "./chunk-NTLX2MPV.mjs";
|
|
160
194
|
import {
|
|
161
|
-
|
|
162
|
-
} from "./chunk-
|
|
195
|
+
intersection
|
|
196
|
+
} from "./chunk-FVVSE2F2.mjs";
|
|
163
197
|
import {
|
|
164
|
-
|
|
165
|
-
} from "./chunk-
|
|
198
|
+
intersectionBy
|
|
199
|
+
} from "./chunk-O6UXZR3U.mjs";
|
|
166
200
|
import {
|
|
167
201
|
intersectionWith
|
|
168
202
|
} from "./chunk-XI7KRD2C.mjs";
|
|
@@ -182,14 +216,14 @@ import {
|
|
|
182
216
|
orderBy
|
|
183
217
|
} from "./chunk-7B7W36UP.mjs";
|
|
184
218
|
import {
|
|
185
|
-
|
|
186
|
-
} from "./chunk-
|
|
187
|
-
import {
|
|
188
|
-
sample
|
|
189
|
-
} from "./chunk-2KNLZB7V.mjs";
|
|
219
|
+
flatMap
|
|
220
|
+
} from "./chunk-UY76KTPE.mjs";
|
|
190
221
|
import {
|
|
191
222
|
flattenDeep
|
|
192
223
|
} from "./chunk-ML727RRJ.mjs";
|
|
224
|
+
import {
|
|
225
|
+
flatten
|
|
226
|
+
} from "./chunk-33MSBDC6.mjs";
|
|
193
227
|
import {
|
|
194
228
|
forEachRight
|
|
195
229
|
} from "./chunk-IEA53J7P.mjs";
|
|
@@ -203,11 +237,11 @@ import {
|
|
|
203
237
|
initial
|
|
204
238
|
} from "./chunk-XPSOKBRZ.mjs";
|
|
205
239
|
import {
|
|
206
|
-
|
|
207
|
-
} from "./chunk-
|
|
240
|
+
difference
|
|
241
|
+
} from "./chunk-JPUKH67K.mjs";
|
|
208
242
|
import {
|
|
209
|
-
|
|
210
|
-
} from "./chunk-
|
|
243
|
+
differenceBy
|
|
244
|
+
} from "./chunk-LVWX5B43.mjs";
|
|
211
245
|
import {
|
|
212
246
|
differenceWith
|
|
213
247
|
} from "./chunk-6NVQAHXP.mjs";
|
|
@@ -226,12 +260,13 @@ import {
|
|
|
226
260
|
import {
|
|
227
261
|
fill
|
|
228
262
|
} from "./chunk-YFN6KOC4.mjs";
|
|
263
|
+
import "./chunk-F47GLYUU.mjs";
|
|
229
264
|
import {
|
|
230
|
-
|
|
231
|
-
} from "./chunk-
|
|
265
|
+
AbortError
|
|
266
|
+
} from "./chunk-DXB7EZUQ.mjs";
|
|
232
267
|
import {
|
|
233
|
-
|
|
234
|
-
} from "./chunk-
|
|
268
|
+
TimeoutError
|
|
269
|
+
} from "./chunk-KIOYQRMQ.mjs";
|
|
235
270
|
import {
|
|
236
271
|
chunk
|
|
237
272
|
} from "./chunk-E6C5EZQA.mjs";
|
|
@@ -241,35 +276,6 @@ import {
|
|
|
241
276
|
import {
|
|
242
277
|
countBy
|
|
243
278
|
} from "./chunk-CRSKT4WW.mjs";
|
|
244
|
-
import {
|
|
245
|
-
difference
|
|
246
|
-
} from "./chunk-JPUKH67K.mjs";
|
|
247
|
-
import {
|
|
248
|
-
differenceBy
|
|
249
|
-
} from "./chunk-LVWX5B43.mjs";
|
|
250
|
-
import "./chunk-F47GLYUU.mjs";
|
|
251
|
-
import {
|
|
252
|
-
AbortError
|
|
253
|
-
} from "./chunk-DXB7EZUQ.mjs";
|
|
254
|
-
import {
|
|
255
|
-
TimeoutError
|
|
256
|
-
} from "./chunk-KIOYQRMQ.mjs";
|
|
257
|
-
import "./chunk-236H5JZJ.mjs";
|
|
258
|
-
import {
|
|
259
|
-
noop
|
|
260
|
-
} from "./chunk-LKXCOLNY.mjs";
|
|
261
|
-
import {
|
|
262
|
-
once
|
|
263
|
-
} from "./chunk-CMBC4MXG.mjs";
|
|
264
|
-
import {
|
|
265
|
-
throttle
|
|
266
|
-
} from "./chunk-QOJGMVVR.mjs";
|
|
267
|
-
import {
|
|
268
|
-
debounce
|
|
269
|
-
} from "./chunk-3IP4JVLL.mjs";
|
|
270
|
-
import {
|
|
271
|
-
negate
|
|
272
|
-
} from "./chunk-BOOQBJN2.mjs";
|
|
273
279
|
import "./chunk-424M7IR7.mjs";
|
|
274
280
|
export {
|
|
275
281
|
AbortError,
|
|
@@ -294,6 +300,7 @@ export {
|
|
|
294
300
|
flatMap,
|
|
295
301
|
flatten,
|
|
296
302
|
flattenDeep,
|
|
303
|
+
flattenObject,
|
|
297
304
|
forEachRight,
|
|
298
305
|
groupBy,
|
|
299
306
|
head,
|
|
@@ -307,6 +314,7 @@ export {
|
|
|
307
314
|
isNil,
|
|
308
315
|
isNotNil,
|
|
309
316
|
isNull,
|
|
317
|
+
isPlainObject,
|
|
310
318
|
isUndefined,
|
|
311
319
|
kebabCase,
|
|
312
320
|
keyBy,
|
|
@@ -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\n while (Object.getPrototypeOf(proto) !== null) {\n proto = Object.getPrototypeOf(proto);\n }\n\n return Object.getPrototypeOf(object) === proto;\n}"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACaO,SAAS,cAAc,QAAyB;AACrD,MAAI,OAAO,WAAW,UAAU;AAC9B,WAAO;AAAA,EACT;AAEA,MAAI,UAAU,MAAM;AAClB,WAAO;AAAA,EACT;AAEA,MAAI,OAAO,eAAe,MAAM,MAAM,MAAM;AAC1C,WAAO;AAAA,EACT;AAEA,MAAI,OAAO,SAAS,MAAM,mBAAmB;AAC3C,WAAO;AAAA,EACT;AAEA,MAAI,QAAQ;AAEZ,SAAO,OAAO,eAAe,KAAK,MAAM,MAAM;AAC5C,YAAQ,OAAO,eAAe,KAAK;AAAA,EACrC;AAEA,SAAO,OAAO,eAAe,MAAM,MAAM;AAC3C;;;ADVO,SAAS,cAAc,QAAqC;AACjE,SAAO,kBAAkB,MAAM;AACjC;AAEA,SAAS,kBAAkB,QAAgB,SAAS,IAAyB;AAC3E,QAAM,SAA8B,CAAC;AACrC,QAAM,OAAO,OAAO,KAAK,MAAM;AAE/B,WAAS,IAAI,GAAG,IAAI,KAAK,QAAQ,KAAK;AACpC,UAAM,MAAM,KAAK,CAAC;AAClB,UAAM,QAAS,OAAe,GAAG;AAEjC,UAAM,cAAc,SAAS,GAAG,MAAM,IAAI,GAAG,KAAK;AAElD,QAAI,cAAc,KAAK,KAAK,OAAO,KAAK,KAAK,EAAE,SAAS,GAAG;AACzD,aAAO,OAAO,QAAQ,kBAAkB,OAAO,WAAW,CAAC;AAC3D;AAAA,IACF;AAEA,QAAI,MAAM,QAAQ,KAAK,GAAG;AACxB,eAAS,QAAQ,GAAG,QAAQ,MAAM,QAAQ,SAAS;AACjD,eAAO,GAAG,WAAW,IAAI,KAAK,EAAE,IAAI,MAAM,KAAK;AAAA,MACjD;AACA;AAAA,IACF;AAEA,WAAO,WAAW,IAAI;AAAA,EACxB;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","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,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,SAAO;AACT;;;ACjBO,SAAS,KAAuD,KAAQ,MAAuB;AACpG,QAAM,SAAS,CAAC;AAEhB,aAAW,OAAO,MAAM;AACtB,WAAO,GAAG,IAAI,IAAI,GAAG;AAAA,EACvB;AAEA,SAAO;AACT;;;ACNO,SAAS,OACd,KACA,YACY;AACZ,QAAM,SAAqB,CAAC;AAE5B,aAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,GAAG,GAAG;AAC9C,QAAI,CAAC,WAAW,OAAO,GAAG,GAAG;AAC3B;AAAA,IACF;AAEA,IAAC,OAAe,GAAG,IAAI;AAAA,EACzB;AAEA,SAAO;AACT;;;AChBO,SAAS,OAAqD,KAAsC;AACzG,QAAM,SAAS,CAAC;AAEhB,QAAM,OAAO,OAAO,KAAK,GAAG;AAE5B,WAAS,IAAI,GAAG,IAAI,KAAK,QAAQ,KAAK;AACpC,UAAM,MAAM,KAAK,CAAC;AAClB,UAAM,QAAQ,IAAI,GAAG;AACrB,WAAO,KAAK,IAAI;AAAA,EAClB;AAEA,SAAO;AACT;;;ACFO,SAAS,MAAS,KAAW;AAClC,MAAI,YAAY,GAAG,GAAG;AACpB,WAAO;AAAA,EACT;AAEA,MAAI,MAAM,QAAQ,GAAG,GAAG;AACtB,WAAO,IAAI,MAAM;AAAA,EACnB;AAEA,MAAI,eAAe,MAAM;AACvB,WAAO,IAAI,KAAK,IAAI,QAAQ,CAAC;AAAA,EAC/B;AAEA,MAAI,eAAe,QAAQ;AACzB,WAAO,IAAI,OAAO,IAAI,QAAQ,IAAI,KAAK;AAAA,EACzC;AAEA,MAAI,eAAe,KAAK;AACtB,UAAM,SAAS,oBAAI,IAAI;AACvB,eAAW,CAAC,KAAK,KAAK,KAAK,KAAK;AAC9B,aAAO,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":"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","names":[]}
|
package/dist/object/index.mjs
CHANGED
|
@@ -1,10 +1,17 @@
|
|
|
1
|
-
import "../chunk-
|
|
1
|
+
import "../chunk-54TK5BIS.mjs";
|
|
2
|
+
import {
|
|
3
|
+
pick
|
|
4
|
+
} from "../chunk-HPFDYUGP.mjs";
|
|
2
5
|
import {
|
|
3
6
|
pickBy
|
|
4
7
|
} from "../chunk-6CLH5YZ2.mjs";
|
|
5
8
|
import {
|
|
6
9
|
clone
|
|
7
10
|
} from "../chunk-U4JGKZ56.mjs";
|
|
11
|
+
import {
|
|
12
|
+
flattenObject
|
|
13
|
+
} from "../chunk-XGQWTHW6.mjs";
|
|
14
|
+
import "../chunk-MIGAC7F4.mjs";
|
|
8
15
|
import {
|
|
9
16
|
invert
|
|
10
17
|
} from "../chunk-OLX53VEF.mjs";
|
|
@@ -14,12 +21,10 @@ import {
|
|
|
14
21
|
import {
|
|
15
22
|
omitBy
|
|
16
23
|
} from "../chunk-BCTYOXT7.mjs";
|
|
17
|
-
import {
|
|
18
|
-
pick
|
|
19
|
-
} from "../chunk-HPFDYUGP.mjs";
|
|
20
24
|
import "../chunk-424M7IR7.mjs";
|
|
21
25
|
export {
|
|
22
26
|
clone,
|
|
27
|
+
flattenObject,
|
|
23
28
|
invert,
|
|
24
29
|
omit,
|
|
25
30
|
omitBy,
|
package/dist/predicate/index.js
CHANGED
|
@@ -24,6 +24,7 @@ __export(predicate_exports, {
|
|
|
24
24
|
isNil: () => isNil,
|
|
25
25
|
isNotNil: () => isNotNil,
|
|
26
26
|
isNull: () => isNull,
|
|
27
|
+
isPlainObject: () => isPlainObject,
|
|
27
28
|
isUndefined: () => isUndefined
|
|
28
29
|
});
|
|
29
30
|
module.exports = __toCommonJS(predicate_exports);
|
|
@@ -90,12 +91,34 @@ function isNull(x) {
|
|
|
90
91
|
function isUndefined(x) {
|
|
91
92
|
return x === void 0;
|
|
92
93
|
}
|
|
94
|
+
|
|
95
|
+
// src/predicate/isPlainObject.ts
|
|
96
|
+
function isPlainObject(object) {
|
|
97
|
+
if (typeof object !== "object") {
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
if (object == null) {
|
|
101
|
+
return false;
|
|
102
|
+
}
|
|
103
|
+
if (Object.getPrototypeOf(object) === null) {
|
|
104
|
+
return true;
|
|
105
|
+
}
|
|
106
|
+
if (object.toString() !== "[object Object]") {
|
|
107
|
+
return false;
|
|
108
|
+
}
|
|
109
|
+
let proto = object;
|
|
110
|
+
while (Object.getPrototypeOf(proto) !== null) {
|
|
111
|
+
proto = Object.getPrototypeOf(proto);
|
|
112
|
+
}
|
|
113
|
+
return Object.getPrototypeOf(object) === proto;
|
|
114
|
+
}
|
|
93
115
|
// Annotate the CommonJS export names for ESM import in node:
|
|
94
116
|
0 && (module.exports = {
|
|
95
117
|
isEqual,
|
|
96
118
|
isNil,
|
|
97
119
|
isNotNil,
|
|
98
120
|
isNull,
|
|
121
|
+
isPlainObject,
|
|
99
122
|
isUndefined
|
|
100
123
|
});
|
|
101
124
|
//# sourceMappingURL=index.js.map
|