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.
@@ -1,4 +1,10 @@
1
1
  import "../chunk-2MRZANXZ.mjs";
2
+ import {
3
+ xorBy
4
+ } from "../chunk-Q47NGNXT.mjs";
5
+ import {
6
+ xorWith
7
+ } from "../chunk-QRSJBBFY.mjs";
2
8
  import {
3
9
  zip
4
10
  } from "../chunk-IDCUZVJL.mjs";
@@ -8,9 +14,15 @@ import {
8
14
  import {
9
15
  zipWith
10
16
  } from "../chunk-4KYXHZ4R.mjs";
17
+ import {
18
+ unionWith
19
+ } from "../chunk-2ZCITDMK.mjs";
11
20
  import {
12
21
  uniqBy
13
22
  } from "../chunk-OXAZEEGP.mjs";
23
+ import {
24
+ uniqWith
25
+ } from "../chunk-237HGSZS.mjs";
14
26
  import {
15
27
  unzip
16
28
  } from "../chunk-UYZKMBDO.mjs";
@@ -24,11 +36,11 @@ import {
24
36
  xor
25
37
  } from "../chunk-L7FQX5MN.mjs";
26
38
  import {
27
- xorBy
28
- } from "../chunk-Q47NGNXT.mjs";
39
+ tail
40
+ } from "../chunk-OF6NM4G7.mjs";
29
41
  import {
30
- xorWith
31
- } from "../chunk-QRSJBBFY.mjs";
42
+ take
43
+ } from "../chunk-ME352XO7.mjs";
32
44
  import {
33
45
  takeRight
34
46
  } from "../chunk-IQLKIDXF.mjs";
@@ -44,18 +56,18 @@ import {
44
56
  import {
45
57
  union
46
58
  } from "../chunk-R6QA7PLZ.mjs";
59
+ import {
60
+ uniq
61
+ } from "../chunk-DVK2N4KC.mjs";
47
62
  import {
48
63
  unionBy
49
64
  } from "../chunk-NFS7RWWE.mjs";
50
65
  import {
51
- unionWith
52
- } from "../chunk-2ZCITDMK.mjs";
53
- import {
54
- uniqWith
55
- } from "../chunk-237HGSZS.mjs";
66
+ last
67
+ } from "../chunk-KPBQ7OUY.mjs";
56
68
  import {
57
- uniq
58
- } from "../chunk-DVK2N4KC.mjs";
69
+ maxBy
70
+ } from "../chunk-OOKNBU4V.mjs";
59
71
  import {
60
72
  minBy
61
73
  } from "../chunk-IJD7FE2Z.mjs";
@@ -71,17 +83,15 @@ import {
71
83
  import {
72
84
  sampleSize
73
85
  } from "../chunk-EHSKB6DF.mjs";
74
- import "../chunk-GIWAOOFY.mjs";
75
- import "../chunk-SYWMYQYJ.mjs";
76
86
  import {
77
87
  shuffle
78
88
  } from "../chunk-G7UQ5PUR.mjs";
79
89
  import {
80
- tail
81
- } from "../chunk-OF6NM4G7.mjs";
90
+ groupBy
91
+ } from "../chunk-E6E4RZLN.mjs";
82
92
  import {
83
- take
84
- } from "../chunk-ME352XO7.mjs";
93
+ head
94
+ } from "../chunk-HM2JT2RX.mjs";
85
95
  import {
86
96
  initial
87
97
  } from "../chunk-XPSOKBRZ.mjs";
@@ -98,11 +108,11 @@ import {
98
108
  keyBy
99
109
  } from "../chunk-AJKZMN2V.mjs";
100
110
  import {
101
- last
102
- } from "../chunk-KPBQ7OUY.mjs";
111
+ drop
112
+ } from "../chunk-S3CORED5.mjs";
103
113
  import {
104
- maxBy
105
- } from "../chunk-OOKNBU4V.mjs";
114
+ dropRight
115
+ } from "../chunk-JEKUA56R.mjs";
106
116
  import {
107
117
  dropRightWhile
108
118
  } from "../chunk-JE6JKZU3.mjs";
@@ -121,12 +131,6 @@ import {
121
131
  import {
122
132
  forEachRight
123
133
  } from "../chunk-IEA53J7P.mjs";
124
- import {
125
- groupBy
126
- } from "../chunk-E6E4RZLN.mjs";
127
- import {
128
- head
129
- } from "../chunk-HM2JT2RX.mjs";
130
134
  import {
131
135
  chunk
132
136
  } from "../chunk-E6C5EZQA.mjs";
@@ -145,12 +149,8 @@ import {
145
149
  import {
146
150
  differenceWith
147
151
  } from "../chunk-6NVQAHXP.mjs";
148
- import {
149
- drop
150
- } from "../chunk-S3CORED5.mjs";
151
- import {
152
- dropRight
153
- } from "../chunk-JEKUA56R.mjs";
152
+ import "../chunk-GIWAOOFY.mjs";
153
+ import "../chunk-SYWMYQYJ.mjs";
154
154
  import "../chunk-2HIMLZE3.mjs";
155
155
  export {
156
156
  chunk,
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=chunk-OSOLEQLZ.mjs.map
@@ -0,0 +1,41 @@
1
+ // src/object/clone.ts
2
+ function clone(obj) {
3
+ if (isPrimitive(obj)) {
4
+ return obj;
5
+ }
6
+ if (Array.isArray(obj)) {
7
+ return obj.slice();
8
+ }
9
+ if (obj instanceof Date) {
10
+ return new Date(obj.getTime());
11
+ }
12
+ if (obj instanceof RegExp) {
13
+ return new RegExp(obj.source, obj.flags);
14
+ }
15
+ if (obj instanceof Map) {
16
+ const result = /* @__PURE__ */ new Map();
17
+ for (const [key, value] of obj) {
18
+ result.set(key, value);
19
+ }
20
+ return result;
21
+ }
22
+ if (obj instanceof Set) {
23
+ const result = /* @__PURE__ */ new Set();
24
+ for (const value of obj) {
25
+ result.add(value);
26
+ }
27
+ return result;
28
+ }
29
+ if (typeof obj === "object") {
30
+ return Object.assign({}, obj);
31
+ }
32
+ return obj;
33
+ }
34
+ function isPrimitive(value) {
35
+ return value == null || typeof value !== "object" && typeof value !== "function";
36
+ }
37
+
38
+ export {
39
+ clone
40
+ };
41
+ //# sourceMappingURL=chunk-U4JGKZ56.mjs.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":";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":[]}
package/dist/index.d.mts CHANGED
@@ -67,6 +67,7 @@ export { omitBy } from './object/omitBy.mjs';
67
67
  export { pick } from './object/pick.mjs';
68
68
  export { pickBy } from './object/pickBy.mjs';
69
69
  export { invert } from './object/invert.mjs';
70
+ export { clone } from './object/clone.mjs';
70
71
  export { isNil } from './predicate/isNil.mjs';
71
72
  export { isNotNil } from './predicate/isNotNil.mjs';
72
73
  export { isNull } from './predicate/isNull.mjs';
package/dist/index.d.ts CHANGED
@@ -67,6 +67,7 @@ export { omitBy } from './object/omitBy.js';
67
67
  export { pick } from './object/pick.js';
68
68
  export { pickBy } from './object/pickBy.js';
69
69
  export { invert } from './object/invert.js';
70
+ export { clone } from './object/clone.js';
70
71
  export { isNil } from './predicate/isNil.js';
71
72
  export { isNotNil } from './predicate/isNotNil.js';
72
73
  export { isNull } from './predicate/isNull.js';
package/dist/index.js CHANGED
@@ -3619,15 +3619,15 @@ var require_lodash = __commonJS({
3619
3619
  function wrapperPlant(value) {
3620
3620
  var result2, parent2 = this;
3621
3621
  while (parent2 instanceof baseLodash) {
3622
- var clone2 = wrapperClone(parent2);
3623
- clone2.__index__ = 0;
3624
- clone2.__values__ = undefined2;
3622
+ var clone3 = wrapperClone(parent2);
3623
+ clone3.__index__ = 0;
3624
+ clone3.__values__ = undefined2;
3625
3625
  if (result2) {
3626
- previous.__wrapped__ = clone2;
3626
+ previous.__wrapped__ = clone3;
3627
3627
  } else {
3628
- result2 = clone2;
3628
+ result2 = clone3;
3629
3629
  }
3630
- var previous = clone2;
3630
+ var previous = clone3;
3631
3631
  parent2 = parent2.__wrapped__;
3632
3632
  }
3633
3633
  previous.__wrapped__ = value;
@@ -4062,7 +4062,7 @@ var require_lodash = __commonJS({
4062
4062
  var value = arguments[0];
4063
4063
  return isArray(value) ? value : [value];
4064
4064
  }
4065
- function clone(value) {
4065
+ function clone2(value) {
4066
4066
  return baseClone(value, CLONE_SYMBOLS_FLAG);
4067
4067
  }
4068
4068
  function cloneWith(value, customizer) {
@@ -5194,7 +5194,7 @@ var require_lodash = __commonJS({
5194
5194
  lodash.capitalize = capitalize3;
5195
5195
  lodash.ceil = ceil;
5196
5196
  lodash.clamp = clamp2;
5197
- lodash.clone = clone;
5197
+ lodash.clone = clone2;
5198
5198
  lodash.cloneDeep = cloneDeep;
5199
5199
  lodash.cloneDeepWith = cloneDeepWith;
5200
5200
  lodash.cloneWith = cloneWith;
@@ -5533,6 +5533,7 @@ __export(src_exports, {
5533
5533
  capitalize: () => capitalize2,
5534
5534
  chunk: () => chunk,
5535
5535
  clamp: () => clamp,
5536
+ clone: () => clone,
5536
5537
  compact: () => compact,
5537
5538
  countBy: () => countBy,
5538
5539
  debounce: () => debounce,
@@ -6311,6 +6312,43 @@ function invert(obj) {
6311
6312
  return result;
6312
6313
  }
6313
6314
 
6315
+ // src/object/clone.ts
6316
+ function clone(obj) {
6317
+ if (isPrimitive(obj)) {
6318
+ return obj;
6319
+ }
6320
+ if (Array.isArray(obj)) {
6321
+ return obj.slice();
6322
+ }
6323
+ if (obj instanceof Date) {
6324
+ return new Date(obj.getTime());
6325
+ }
6326
+ if (obj instanceof RegExp) {
6327
+ return new RegExp(obj.source, obj.flags);
6328
+ }
6329
+ if (obj instanceof Map) {
6330
+ const result = /* @__PURE__ */ new Map();
6331
+ for (const [key, value] of obj) {
6332
+ result.set(key, value);
6333
+ }
6334
+ return result;
6335
+ }
6336
+ if (obj instanceof Set) {
6337
+ const result = /* @__PURE__ */ new Set();
6338
+ for (const value of obj) {
6339
+ result.add(value);
6340
+ }
6341
+ return result;
6342
+ }
6343
+ if (typeof obj === "object") {
6344
+ return Object.assign({}, obj);
6345
+ }
6346
+ return obj;
6347
+ }
6348
+ function isPrimitive(value) {
6349
+ return value == null || typeof value !== "object" && typeof value !== "function";
6350
+ }
6351
+
6314
6352
  // src/predicate/isNil.ts
6315
6353
  function isNil(x) {
6316
6354
  return x == null;
@@ -6398,6 +6436,7 @@ var capitalize2 = (str) => {
6398
6436
  capitalize,
6399
6437
  chunk,
6400
6438
  clamp,
6439
+ clone,
6401
6440
  compact,
6402
6441
  countBy,
6403
6442
  debounce,