es-toolkit 1.9.0-dev.195 → 1.9.0-dev.197

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/index.mjs CHANGED
@@ -3,6 +3,9 @@ import {
3
3
  delay
4
4
  } from "./chunk-O64NE2P4.mjs";
5
5
  import "./chunk-QKYYOLJ6.mjs";
6
+ import {
7
+ snakeCase
8
+ } from "./chunk-F3WCQQET.mjs";
6
9
  import {
7
10
  camelCase
8
11
  } from "./chunk-XGCYC4YA.mjs";
@@ -15,11 +18,11 @@ import {
15
18
  import {
16
19
  lowerCase
17
20
  } from "./chunk-5IKVJGHO.mjs";
18
- import {
19
- snakeCase
20
- } from "./chunk-F3WCQQET.mjs";
21
21
  import "./chunk-WVQ7YVRK.mjs";
22
22
  import "./chunk-MAJSPFA6.mjs";
23
+ import {
24
+ isUndefined
25
+ } from "./chunk-VH2PV426.mjs";
23
26
  import {
24
27
  isNil
25
28
  } from "./chunk-WMM7TZLG.mjs";
@@ -29,10 +32,10 @@ import {
29
32
  import {
30
33
  isNull
31
34
  } from "./chunk-AIRSKN47.mjs";
35
+ import "./chunk-OSOLEQLZ.mjs";
32
36
  import {
33
- isUndefined
34
- } from "./chunk-VH2PV426.mjs";
35
- import "./chunk-PMHULJNL.mjs";
37
+ omit
38
+ } from "./chunk-4E4D3BMI.mjs";
36
39
  import {
37
40
  omitBy
38
41
  } from "./chunk-BCTYOXT7.mjs";
@@ -42,35 +45,19 @@ import {
42
45
  import {
43
46
  pickBy
44
47
  } from "./chunk-6CLH5YZ2.mjs";
48
+ import {
49
+ clone
50
+ } from "./chunk-U4JGKZ56.mjs";
45
51
  import {
46
52
  invert
47
53
  } from "./chunk-74WWMNZS.mjs";
54
+ import "./chunk-2MRZANXZ.mjs";
48
55
  import {
49
- omit
50
- } from "./chunk-4E4D3BMI.mjs";
51
- import "./chunk-TLVQSNOE.mjs";
52
- import {
53
- range
54
- } from "./chunk-DPH2KE6O.mjs";
55
- import {
56
- round
57
- } from "./chunk-5PMKOZ2F.mjs";
58
- import {
59
- clamp
60
- } from "./chunk-MLCL773E.mjs";
61
- import {
62
- inRange
63
- } from "./chunk-BH6HLGBA.mjs";
64
- import {
65
- meanBy
66
- } from "./chunk-IZAD2S7R.mjs";
67
- import {
68
- mean
69
- } from "./chunk-GDC64SYJ.mjs";
56
+ xorBy
57
+ } from "./chunk-Q47NGNXT.mjs";
70
58
  import {
71
- sum
72
- } from "./chunk-2SLTL4KL.mjs";
73
- import "./chunk-2MRZANXZ.mjs";
59
+ xorWith
60
+ } from "./chunk-QRSJBBFY.mjs";
74
61
  import {
75
62
  zip
76
63
  } from "./chunk-IDCUZVJL.mjs";
@@ -80,9 +67,15 @@ import {
80
67
  import {
81
68
  zipWith
82
69
  } from "./chunk-4KYXHZ4R.mjs";
70
+ import {
71
+ unionWith
72
+ } from "./chunk-2ZCITDMK.mjs";
83
73
  import {
84
74
  uniqBy
85
75
  } from "./chunk-OXAZEEGP.mjs";
76
+ import {
77
+ uniqWith
78
+ } from "./chunk-237HGSZS.mjs";
86
79
  import {
87
80
  unzip
88
81
  } from "./chunk-UYZKMBDO.mjs";
@@ -96,11 +89,11 @@ import {
96
89
  xor
97
90
  } from "./chunk-L7FQX5MN.mjs";
98
91
  import {
99
- xorBy
100
- } from "./chunk-Q47NGNXT.mjs";
92
+ tail
93
+ } from "./chunk-OF6NM4G7.mjs";
101
94
  import {
102
- xorWith
103
- } from "./chunk-QRSJBBFY.mjs";
95
+ take
96
+ } from "./chunk-ME352XO7.mjs";
104
97
  import {
105
98
  takeRight
106
99
  } from "./chunk-IQLKIDXF.mjs";
@@ -116,18 +109,18 @@ import {
116
109
  import {
117
110
  union
118
111
  } from "./chunk-R6QA7PLZ.mjs";
112
+ import {
113
+ uniq
114
+ } from "./chunk-DVK2N4KC.mjs";
119
115
  import {
120
116
  unionBy
121
117
  } from "./chunk-NFS7RWWE.mjs";
122
118
  import {
123
- unionWith
124
- } from "./chunk-2ZCITDMK.mjs";
125
- import {
126
- uniqWith
127
- } from "./chunk-237HGSZS.mjs";
119
+ last
120
+ } from "./chunk-KPBQ7OUY.mjs";
128
121
  import {
129
- uniq
130
- } from "./chunk-DVK2N4KC.mjs";
122
+ maxBy
123
+ } from "./chunk-OOKNBU4V.mjs";
131
124
  import {
132
125
  minBy
133
126
  } from "./chunk-IJD7FE2Z.mjs";
@@ -143,21 +136,15 @@ import {
143
136
  import {
144
137
  sampleSize
145
138
  } from "./chunk-EHSKB6DF.mjs";
146
- import {
147
- randomInt
148
- } from "./chunk-GIWAOOFY.mjs";
149
- import {
150
- random
151
- } from "./chunk-SYWMYQYJ.mjs";
152
139
  import {
153
140
  shuffle
154
141
  } from "./chunk-G7UQ5PUR.mjs";
155
142
  import {
156
- tail
157
- } from "./chunk-OF6NM4G7.mjs";
143
+ groupBy
144
+ } from "./chunk-E6E4RZLN.mjs";
158
145
  import {
159
- take
160
- } from "./chunk-ME352XO7.mjs";
146
+ head
147
+ } from "./chunk-HM2JT2RX.mjs";
161
148
  import {
162
149
  initial
163
150
  } from "./chunk-XPSOKBRZ.mjs";
@@ -174,11 +161,11 @@ import {
174
161
  keyBy
175
162
  } from "./chunk-AJKZMN2V.mjs";
176
163
  import {
177
- last
178
- } from "./chunk-KPBQ7OUY.mjs";
164
+ drop
165
+ } from "./chunk-S3CORED5.mjs";
179
166
  import {
180
- maxBy
181
- } from "./chunk-OOKNBU4V.mjs";
167
+ dropRight
168
+ } from "./chunk-JEKUA56R.mjs";
182
169
  import {
183
170
  dropRightWhile
184
171
  } from "./chunk-JE6JKZU3.mjs";
@@ -197,12 +184,6 @@ import {
197
184
  import {
198
185
  forEachRight
199
186
  } from "./chunk-IEA53J7P.mjs";
200
- import {
201
- groupBy
202
- } from "./chunk-E6E4RZLN.mjs";
203
- import {
204
- head
205
- } from "./chunk-HM2JT2RX.mjs";
206
187
  import {
207
188
  chunk
208
189
  } from "./chunk-E6C5EZQA.mjs";
@@ -221,12 +202,38 @@ import {
221
202
  import {
222
203
  differenceWith
223
204
  } from "./chunk-6NVQAHXP.mjs";
205
+ import "./chunk-TLVQSNOE.mjs";
224
206
  import {
225
- drop
226
- } from "./chunk-S3CORED5.mjs";
207
+ round
208
+ } from "./chunk-5PMKOZ2F.mjs";
227
209
  import {
228
- dropRight
229
- } from "./chunk-JEKUA56R.mjs";
210
+ clamp
211
+ } from "./chunk-MLCL773E.mjs";
212
+ import {
213
+ inRange
214
+ } from "./chunk-BH6HLGBA.mjs";
215
+ import {
216
+ meanBy
217
+ } from "./chunk-IZAD2S7R.mjs";
218
+ import {
219
+ mean
220
+ } from "./chunk-GDC64SYJ.mjs";
221
+ import {
222
+ sum
223
+ } from "./chunk-2SLTL4KL.mjs";
224
+ import {
225
+ randomInt
226
+ } from "./chunk-GIWAOOFY.mjs";
227
+ import {
228
+ random
229
+ } from "./chunk-SYWMYQYJ.mjs";
230
+ import {
231
+ range
232
+ } from "./chunk-DPH2KE6O.mjs";
233
+ import "./chunk-FZEZH22H.mjs";
234
+ import {
235
+ AbortError
236
+ } from "./chunk-DXB7EZUQ.mjs";
230
237
  import "./chunk-N6EM6ETS.mjs";
231
238
  import {
232
239
  debounce
@@ -240,10 +247,6 @@ import {
240
247
  import {
241
248
  throttle
242
249
  } from "./chunk-QOJGMVVR.mjs";
243
- import "./chunk-FZEZH22H.mjs";
244
- import {
245
- AbortError
246
- } from "./chunk-DXB7EZUQ.mjs";
247
250
  import "./chunk-2HIMLZE3.mjs";
248
251
  export {
249
252
  AbortError,
@@ -251,6 +254,7 @@ export {
251
254
  capitalize,
252
255
  chunk,
253
256
  clamp,
257
+ clone,
254
258
  compact,
255
259
  countBy,
256
260
  debounce,
@@ -1,7 +1,4 @@
1
1
  import "../chunk-TLVQSNOE.mjs";
2
- import {
3
- range
4
- } from "../chunk-DPH2KE6O.mjs";
5
2
  import {
6
3
  round
7
4
  } from "../chunk-5PMKOZ2F.mjs";
@@ -26,6 +23,9 @@ import {
26
23
  import {
27
24
  random
28
25
  } from "../chunk-SYWMYQYJ.mjs";
26
+ import {
27
+ range
28
+ } from "../chunk-DPH2KE6O.mjs";
29
29
  import "../chunk-2HIMLZE3.mjs";
30
30
  export {
31
31
  clamp,
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Creates a shallow clone of the given object.
3
+ *
4
+ * @template T - The type of the object.
5
+ * @param {T} obj - The object to clone.
6
+ * @returns {T} - A shallow clone of the given object.
7
+ *
8
+ * @example
9
+ * // Clone a primitive values
10
+ * const num = 29;
11
+ * const clonedNum = clone(num);
12
+ * console.log(clonedNum); // 29
13
+ * console.log(clonedNum === num) ; // true
14
+ *
15
+ * @example
16
+ * // Clone an array
17
+ * const arr = [1, 2, 3];
18
+ * const clonedArr = clone(arr);
19
+ * console.log(clonedArr); // [1, 2, 3]
20
+ * console.log(clonedArr === arr); // false
21
+ *
22
+ * @example
23
+ * // Clone an object
24
+ * const obj = { a: 1, b: 'es-toolkit', c: [1, 2, 3] };
25
+ * const clonedObj = clone(obj);
26
+ * console.log(clonedObj); // { a: 1, b: 'es-toolkit', c: [1, 2, 3] }
27
+ * console.log(clonedObj === obj); // false
28
+ */
29
+ declare function clone<T>(obj: T): T;
30
+
31
+ export { clone };
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Creates a shallow clone of the given object.
3
+ *
4
+ * @template T - The type of the object.
5
+ * @param {T} obj - The object to clone.
6
+ * @returns {T} - A shallow clone of the given object.
7
+ *
8
+ * @example
9
+ * // Clone a primitive values
10
+ * const num = 29;
11
+ * const clonedNum = clone(num);
12
+ * console.log(clonedNum); // 29
13
+ * console.log(clonedNum === num) ; // true
14
+ *
15
+ * @example
16
+ * // Clone an array
17
+ * const arr = [1, 2, 3];
18
+ * const clonedArr = clone(arr);
19
+ * console.log(clonedArr); // [1, 2, 3]
20
+ * console.log(clonedArr === arr); // false
21
+ *
22
+ * @example
23
+ * // Clone an object
24
+ * const obj = { a: 1, b: 'es-toolkit', c: [1, 2, 3] };
25
+ * const clonedObj = clone(obj);
26
+ * console.log(clonedObj); // { a: 1, b: 'es-toolkit', c: [1, 2, 3] }
27
+ * console.log(clonedObj === obj); // false
28
+ */
29
+ declare function clone<T>(obj: T): T;
30
+
31
+ export { clone };
@@ -0,0 +1,65 @@
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/clone.ts
21
+ var clone_exports = {};
22
+ __export(clone_exports, {
23
+ clone: () => clone
24
+ });
25
+ module.exports = __toCommonJS(clone_exports);
26
+ function clone(obj) {
27
+ if (isPrimitive(obj)) {
28
+ return obj;
29
+ }
30
+ if (Array.isArray(obj)) {
31
+ return obj.slice();
32
+ }
33
+ if (obj instanceof Date) {
34
+ return new Date(obj.getTime());
35
+ }
36
+ if (obj instanceof RegExp) {
37
+ return new RegExp(obj.source, obj.flags);
38
+ }
39
+ if (obj instanceof Map) {
40
+ const result = /* @__PURE__ */ new Map();
41
+ for (const [key, value] of obj) {
42
+ result.set(key, value);
43
+ }
44
+ return result;
45
+ }
46
+ if (obj instanceof Set) {
47
+ const result = /* @__PURE__ */ new Set();
48
+ for (const value of obj) {
49
+ result.add(value);
50
+ }
51
+ return result;
52
+ }
53
+ if (typeof obj === "object") {
54
+ return Object.assign({}, obj);
55
+ }
56
+ return obj;
57
+ }
58
+ function isPrimitive(value) {
59
+ return value == null || typeof value !== "object" && typeof value !== "function";
60
+ }
61
+ // Annotate the CommonJS export names for ESM import in node:
62
+ 0 && (module.exports = {
63
+ clone
64
+ });
65
+ //# sourceMappingURL=clone.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/object/clone.ts"],"sourcesContent":["/**\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;AA4BO,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":[]}
@@ -0,0 +1,8 @@
1
+ import {
2
+ clone
3
+ } from "../chunk-U4JGKZ56.mjs";
4
+ import "../chunk-2HIMLZE3.mjs";
5
+ export {
6
+ clone
7
+ };
8
+ //# sourceMappingURL=clone.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -3,3 +3,4 @@ export { omitBy } from './omitBy.mjs';
3
3
  export { pick } from './pick.mjs';
4
4
  export { pickBy } from './pickBy.mjs';
5
5
  export { invert } from './invert.mjs';
6
+ export { clone } from './clone.mjs';
@@ -3,3 +3,4 @@ export { omitBy } from './omitBy.js';
3
3
  export { pick } from './pick.js';
4
4
  export { pickBy } from './pickBy.js';
5
5
  export { invert } from './invert.js';
6
+ export { clone } from './clone.js';
@@ -34,6 +34,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
34
34
  // src/object/index.ts
35
35
  var object_exports = {};
36
36
  __export(object_exports, {
37
+ clone: () => clone,
37
38
  invert: () => invert,
38
39
  omit: () => omit,
39
40
  omitBy: () => omitBy,
@@ -93,8 +94,46 @@ function invert(obj) {
93
94
  }
94
95
  return result;
95
96
  }
97
+
98
+ // src/object/clone.ts
99
+ function clone(obj) {
100
+ if (isPrimitive(obj)) {
101
+ return obj;
102
+ }
103
+ if (Array.isArray(obj)) {
104
+ return obj.slice();
105
+ }
106
+ if (obj instanceof Date) {
107
+ return new Date(obj.getTime());
108
+ }
109
+ if (obj instanceof RegExp) {
110
+ return new RegExp(obj.source, obj.flags);
111
+ }
112
+ if (obj instanceof Map) {
113
+ const result = /* @__PURE__ */ new Map();
114
+ for (const [key, value] of obj) {
115
+ result.set(key, value);
116
+ }
117
+ return result;
118
+ }
119
+ if (obj instanceof Set) {
120
+ const result = /* @__PURE__ */ new Set();
121
+ for (const value of obj) {
122
+ result.add(value);
123
+ }
124
+ return result;
125
+ }
126
+ if (typeof obj === "object") {
127
+ return Object.assign({}, obj);
128
+ }
129
+ return obj;
130
+ }
131
+ function isPrimitive(value) {
132
+ return value == null || typeof value !== "object" && typeof value !== "function";
133
+ }
96
134
  // Annotate the CommonJS export names for ESM import in node:
97
135
  0 && (module.exports = {
136
+ clone,
98
137
  invert,
99
138
  omit,
100
139
  omitBy,
@@ -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"],"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';\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 for (const key in obj) {\n const value = obj[key as K] as V;\n result[value] = key;\n }\n\n return result;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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,aAAW,OAAO,KAAK;AACrB,UAAM,QAAQ,IAAI,GAAQ;AAC1B,WAAO,KAAK,IAAI;AAAA,EAClB;AAEA,SAAO;AACT;","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"],"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 for (const key in obj) {\n const value = obj[key as K] as V;\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,aAAW,OAAO,KAAK;AACrB,UAAM,QAAQ,IAAI,GAAQ;AAC1B,WAAO,KAAK,IAAI;AAAA,EAClB;AAEA,SAAO;AACT;;;ACCO,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,4 +1,7 @@
1
- import "../chunk-PMHULJNL.mjs";
1
+ import "../chunk-OSOLEQLZ.mjs";
2
+ import {
3
+ omit
4
+ } from "../chunk-4E4D3BMI.mjs";
2
5
  import {
3
6
  omitBy
4
7
  } from "../chunk-BCTYOXT7.mjs";
@@ -8,14 +11,15 @@ import {
8
11
  import {
9
12
  pickBy
10
13
  } from "../chunk-6CLH5YZ2.mjs";
14
+ import {
15
+ clone
16
+ } from "../chunk-U4JGKZ56.mjs";
11
17
  import {
12
18
  invert
13
19
  } from "../chunk-74WWMNZS.mjs";
14
- import {
15
- omit
16
- } from "../chunk-4E4D3BMI.mjs";
17
20
  import "../chunk-2HIMLZE3.mjs";
18
21
  export {
22
+ clone,
19
23
  invert,
20
24
  omit,
21
25
  omitBy,
@@ -1,4 +1,7 @@
1
1
  import "../chunk-MAJSPFA6.mjs";
2
+ import {
3
+ isUndefined
4
+ } from "../chunk-VH2PV426.mjs";
2
5
  import {
3
6
  isNil
4
7
  } from "../chunk-WMM7TZLG.mjs";
@@ -8,9 +11,6 @@ import {
8
11
  import {
9
12
  isNull
10
13
  } from "../chunk-AIRSKN47.mjs";
11
- import {
12
- isUndefined
13
- } from "../chunk-VH2PV426.mjs";
14
14
  import "../chunk-2HIMLZE3.mjs";
15
15
  export {
16
16
  isNil,
@@ -1,4 +1,7 @@
1
1
  import "../chunk-QKYYOLJ6.mjs";
2
+ import {
3
+ snakeCase
4
+ } from "../chunk-F3WCQQET.mjs";
2
5
  import {
3
6
  camelCase
4
7
  } from "../chunk-XGCYC4YA.mjs";
@@ -11,9 +14,6 @@ import {
11
14
  import {
12
15
  lowerCase
13
16
  } from "../chunk-5IKVJGHO.mjs";
14
- import {
15
- snakeCase
16
- } from "../chunk-F3WCQQET.mjs";
17
17
  import "../chunk-WVQ7YVRK.mjs";
18
18
  import "../chunk-2HIMLZE3.mjs";
19
19
  export {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "es-toolkit",
3
3
  "description": "A state-of-the-art, high-performance JavaScript utility library with a small bundle size and strong type annotations.",
4
- "version": "1.9.0-dev.195+eb0382ad",
4
+ "version": "1.9.0-dev.197+f5b66fe6",
5
5
  "homepage": "https://es-toolkit.slash.page",
6
6
  "bugs": "https://github.com/toss/es-toolkit/issues",
7
7
  "repository": {
@@ -1 +0,0 @@
1
- //# sourceMappingURL=chunk-PMHULJNL.mjs.map