es-toolkit 1.9.0-dev.196 → 1.9.0-dev.198

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,10 +1,4 @@
1
1
  import "../chunk-2MRZANXZ.mjs";
2
- import {
3
- xorBy
4
- } from "../chunk-Q47NGNXT.mjs";
5
- import {
6
- xorWith
7
- } from "../chunk-QRSJBBFY.mjs";
8
2
  import {
9
3
  zip
10
4
  } from "../chunk-IDCUZVJL.mjs";
@@ -14,15 +8,9 @@ import {
14
8
  import {
15
9
  zipWith
16
10
  } from "../chunk-4KYXHZ4R.mjs";
17
- import {
18
- unionWith
19
- } from "../chunk-2ZCITDMK.mjs";
20
11
  import {
21
12
  uniqBy
22
13
  } from "../chunk-OXAZEEGP.mjs";
23
- import {
24
- uniqWith
25
- } from "../chunk-237HGSZS.mjs";
26
14
  import {
27
15
  unzip
28
16
  } from "../chunk-UYZKMBDO.mjs";
@@ -36,11 +24,11 @@ import {
36
24
  xor
37
25
  } from "../chunk-L7FQX5MN.mjs";
38
26
  import {
39
- tail
40
- } from "../chunk-OF6NM4G7.mjs";
27
+ xorBy
28
+ } from "../chunk-Q47NGNXT.mjs";
41
29
  import {
42
- take
43
- } from "../chunk-ME352XO7.mjs";
30
+ xorWith
31
+ } from "../chunk-QRSJBBFY.mjs";
44
32
  import {
45
33
  takeRight
46
34
  } from "../chunk-IQLKIDXF.mjs";
@@ -56,18 +44,18 @@ import {
56
44
  import {
57
45
  union
58
46
  } from "../chunk-R6QA7PLZ.mjs";
59
- import {
60
- uniq
61
- } from "../chunk-DVK2N4KC.mjs";
62
47
  import {
63
48
  unionBy
64
49
  } from "../chunk-NFS7RWWE.mjs";
65
50
  import {
66
- last
67
- } from "../chunk-KPBQ7OUY.mjs";
51
+ unionWith
52
+ } from "../chunk-2ZCITDMK.mjs";
68
53
  import {
69
- maxBy
70
- } from "../chunk-OOKNBU4V.mjs";
54
+ uniqWith
55
+ } from "../chunk-237HGSZS.mjs";
56
+ import {
57
+ uniq
58
+ } from "../chunk-DVK2N4KC.mjs";
71
59
  import {
72
60
  minBy
73
61
  } from "../chunk-IJD7FE2Z.mjs";
@@ -83,15 +71,17 @@ import {
83
71
  import {
84
72
  sampleSize
85
73
  } from "../chunk-EHSKB6DF.mjs";
74
+ import "../chunk-GIWAOOFY.mjs";
75
+ import "../chunk-SYWMYQYJ.mjs";
86
76
  import {
87
77
  shuffle
88
78
  } from "../chunk-G7UQ5PUR.mjs";
89
79
  import {
90
- groupBy
91
- } from "../chunk-E6E4RZLN.mjs";
80
+ tail
81
+ } from "../chunk-OF6NM4G7.mjs";
92
82
  import {
93
- head
94
- } from "../chunk-HM2JT2RX.mjs";
83
+ take
84
+ } from "../chunk-ME352XO7.mjs";
95
85
  import {
96
86
  initial
97
87
  } from "../chunk-XPSOKBRZ.mjs";
@@ -108,11 +98,11 @@ import {
108
98
  keyBy
109
99
  } from "../chunk-AJKZMN2V.mjs";
110
100
  import {
111
- drop
112
- } from "../chunk-S3CORED5.mjs";
101
+ last
102
+ } from "../chunk-KPBQ7OUY.mjs";
113
103
  import {
114
- dropRight
115
- } from "../chunk-JEKUA56R.mjs";
104
+ maxBy
105
+ } from "../chunk-OOKNBU4V.mjs";
116
106
  import {
117
107
  dropRightWhile
118
108
  } from "../chunk-JE6JKZU3.mjs";
@@ -131,6 +121,12 @@ import {
131
121
  import {
132
122
  forEachRight
133
123
  } from "../chunk-IEA53J7P.mjs";
124
+ import {
125
+ groupBy
126
+ } from "../chunk-E6E4RZLN.mjs";
127
+ import {
128
+ head
129
+ } from "../chunk-HM2JT2RX.mjs";
134
130
  import {
135
131
  chunk
136
132
  } from "../chunk-E6C5EZQA.mjs";
@@ -149,8 +145,12 @@ import {
149
145
  import {
150
146
  differenceWith
151
147
  } from "../chunk-6NVQAHXP.mjs";
152
- import "../chunk-GIWAOOFY.mjs";
153
- import "../chunk-SYWMYQYJ.mjs";
148
+ import {
149
+ drop
150
+ } from "../chunk-S3CORED5.mjs";
151
+ import {
152
+ dropRight
153
+ } from "../chunk-JEKUA56R.mjs";
154
154
  import "../chunk-2HIMLZE3.mjs";
155
155
  export {
156
156
  chunk,
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=chunk-ASJF5D6C.mjs.map
@@ -0,0 +1,41 @@
1
+ import {
2
+ union
3
+ } from "./chunk-R6QA7PLZ.mjs";
4
+
5
+ // src/predicate/isEqual.ts
6
+ function isEqual(a, b) {
7
+ if (Object.is(a, b)) {
8
+ return true;
9
+ }
10
+ if (a instanceof Date && b instanceof Date) {
11
+ return a.getTime() === b.getTime();
12
+ }
13
+ if (a instanceof RegExp && b instanceof RegExp) {
14
+ return a.source === b.source && a.flags === b.flags;
15
+ }
16
+ if (typeof a !== "object" || typeof b !== "object" || a === null || b === null) {
17
+ return false;
18
+ }
19
+ const aKeys = Object.keys(a);
20
+ const bKeys = Object.keys(b);
21
+ if (aKeys.length !== bKeys.length) {
22
+ return false;
23
+ }
24
+ if (union(aKeys, bKeys).length !== aKeys.length) {
25
+ return false;
26
+ }
27
+ for (let i = 0; i < aKeys.length; i++) {
28
+ const propKey = aKeys[i];
29
+ const aProp = a[propKey];
30
+ const bProp = b[propKey];
31
+ if (!isEqual(aProp, bProp)) {
32
+ return false;
33
+ }
34
+ }
35
+ return true;
36
+ }
37
+
38
+ export {
39
+ isEqual
40
+ };
41
+ //# sourceMappingURL=chunk-JYSV56US.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/predicate/isEqual.ts"],"sourcesContent":["import { union } from \"../array/union.ts\";\n\n/**\n * Checks if two values are equal, including support for `Date`, `RegExp`, and deep object comparison.\n *\n * @param {unknown} a - The first value to compare.\n * @param {unknown} b - The second value to compare.\n * @returns {boolean} `true` if the values are equal, otherwise `false`.\n *\n * @example\n * isEqual(1, 1); // true\n * isEqual({ a: 1 }, { a: 1 }); // true\n * isEqual(/abc/g, /abc/g); // true\n * isEqual(new Date('2020-01-01'), new Date('2020-01-01')); // true\n * isEqual([1, 2, 3], [1, 2, 3]); // true\n */\nexport function isEqual(a: unknown, b: unknown): boolean {\n if (Object.is(a, b)) {\n return true;\n }\n\n if (a instanceof Date && b instanceof Date) {\n return a.getTime() === b.getTime();\n }\n\n if (a instanceof RegExp && b instanceof RegExp) {\n return a.source === b.source && a.flags === b.flags;\n }\n\n if (typeof a !== 'object' || typeof b !== 'object' || a === null || b === null) {\n return false;\n }\n\n const aKeys = Object.keys(a as object);\n const bKeys = Object.keys(b as object);\n\n if (aKeys.length !== bKeys.length) {\n return false;\n }\n\n // check if all keys in both arrays match\n if (union(aKeys, bKeys).length !== aKeys.length) {\n return false;\n }\n\n for (let i = 0; i < aKeys.length; i++) {\n const propKey = aKeys[i];\n const aProp = (a as any)[propKey];\n const bProp = (b as any)[propKey];\n \n if (!isEqual(aProp, bProp)) {\n return false;\n }\n }\n\n return true;\n}\n"],"mappings":";;;;;AAgBO,SAAS,QAAQ,GAAY,GAAqB;AACvD,MAAI,OAAO,GAAG,GAAG,CAAC,GAAG;AACnB,WAAO;AAAA,EACT;AAEA,MAAI,aAAa,QAAQ,aAAa,MAAM;AAC1C,WAAO,EAAE,QAAQ,MAAM,EAAE,QAAQ;AAAA,EACnC;AAEA,MAAI,aAAa,UAAU,aAAa,QAAQ;AAC9C,WAAO,EAAE,WAAW,EAAE,UAAU,EAAE,UAAU,EAAE;AAAA,EAChD;AAEA,MAAI,OAAO,MAAM,YAAY,OAAO,MAAM,YAAY,MAAM,QAAQ,MAAM,MAAM;AAC9E,WAAO;AAAA,EACT;AAEA,QAAM,QAAQ,OAAO,KAAK,CAAW;AACrC,QAAM,QAAQ,OAAO,KAAK,CAAW;AAErC,MAAI,MAAM,WAAW,MAAM,QAAQ;AACjC,WAAO;AAAA,EACT;AAGA,MAAI,MAAM,OAAO,KAAK,EAAE,WAAW,MAAM,QAAQ;AAC/C,WAAO;AAAA,EACT;AAEA,WAAS,IAAI,GAAG,IAAI,MAAM,QAAQ,KAAK;AACrC,UAAM,UAAU,MAAM,CAAC;AACvB,UAAM,QAAS,EAAU,OAAO;AAChC,UAAM,QAAS,EAAU,OAAO;AAEhC,QAAI,CAAC,QAAQ,OAAO,KAAK,GAAG;AAC1B,aAAO;AAAA,IACT;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
@@ -12,6 +12,20 @@ function clone(obj) {
12
12
  if (obj instanceof RegExp) {
13
13
  return new RegExp(obj.source, obj.flags);
14
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
+ }
15
29
  if (typeof obj === "object") {
16
30
  return Object.assign({}, obj);
17
31
  }
@@ -24,4 +38,4 @@ function isPrimitive(value) {
24
38
  export {
25
39
  clone
26
40
  };
27
- //# sourceMappingURL=chunk-NY33CVEY.mjs.map
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
@@ -68,6 +68,7 @@ export { pick } from './object/pick.mjs';
68
68
  export { pickBy } from './object/pickBy.mjs';
69
69
  export { invert } from './object/invert.mjs';
70
70
  export { clone } from './object/clone.mjs';
71
+ export { isEqual } from './predicate/isEqual.mjs';
71
72
  export { isNil } from './predicate/isNil.mjs';
72
73
  export { isNotNil } from './predicate/isNotNil.mjs';
73
74
  export { isNull } from './predicate/isNull.mjs';
package/dist/index.d.ts CHANGED
@@ -68,6 +68,7 @@ export { pick } from './object/pick.js';
68
68
  export { pickBy } from './object/pickBy.js';
69
69
  export { invert } from './object/invert.js';
70
70
  export { clone } from './object/clone.js';
71
+ export { isEqual } from './predicate/isEqual.js';
71
72
  export { isNil } from './predicate/isNil.js';
72
73
  export { isNotNil } from './predicate/isNotNil.js';
73
74
  export { isNull } from './predicate/isNull.js';
package/dist/index.js CHANGED
@@ -4128,7 +4128,7 @@ var require_lodash = __commonJS({
4128
4128
  }
4129
4129
  return true;
4130
4130
  }
4131
- function isEqual(value, other) {
4131
+ function isEqual2(value, other) {
4132
4132
  return baseIsEqual(value, other);
4133
4133
  }
4134
4134
  function isEqualWith(value, other, customizer) {
@@ -5241,7 +5241,7 @@ var require_lodash = __commonJS({
5241
5241
  lodash.isDate = isDate;
5242
5242
  lodash.isElement = isElement;
5243
5243
  lodash.isEmpty = isEmpty;
5244
- lodash.isEqual = isEqual;
5244
+ lodash.isEqual = isEqual2;
5245
5245
  lodash.isEqualWith = isEqualWith;
5246
5246
  lodash.isError = isError;
5247
5247
  lodash.isFinite = isFinite;
@@ -5557,6 +5557,7 @@ __export(src_exports, {
5557
5557
  intersectionBy: () => intersectionBy,
5558
5558
  intersectionWith: () => intersectionWith,
5559
5559
  invert: () => invert,
5560
+ isEqual: () => isEqual,
5560
5561
  isNil: () => isNil,
5561
5562
  isNotNil: () => isNotNil,
5562
5563
  isNull: () => isNull,
@@ -6326,6 +6327,20 @@ function clone(obj) {
6326
6327
  if (obj instanceof RegExp) {
6327
6328
  return new RegExp(obj.source, obj.flags);
6328
6329
  }
6330
+ if (obj instanceof Map) {
6331
+ const result = /* @__PURE__ */ new Map();
6332
+ for (const [key, value] of obj) {
6333
+ result.set(key, value);
6334
+ }
6335
+ return result;
6336
+ }
6337
+ if (obj instanceof Set) {
6338
+ const result = /* @__PURE__ */ new Set();
6339
+ for (const value of obj) {
6340
+ result.add(value);
6341
+ }
6342
+ return result;
6343
+ }
6329
6344
  if (typeof obj === "object") {
6330
6345
  return Object.assign({}, obj);
6331
6346
  }
@@ -6335,6 +6350,39 @@ function isPrimitive(value) {
6335
6350
  return value == null || typeof value !== "object" && typeof value !== "function";
6336
6351
  }
6337
6352
 
6353
+ // src/predicate/isEqual.ts
6354
+ function isEqual(a, b) {
6355
+ if (Object.is(a, b)) {
6356
+ return true;
6357
+ }
6358
+ if (a instanceof Date && b instanceof Date) {
6359
+ return a.getTime() === b.getTime();
6360
+ }
6361
+ if (a instanceof RegExp && b instanceof RegExp) {
6362
+ return a.source === b.source && a.flags === b.flags;
6363
+ }
6364
+ if (typeof a !== "object" || typeof b !== "object" || a === null || b === null) {
6365
+ return false;
6366
+ }
6367
+ const aKeys = Object.keys(a);
6368
+ const bKeys = Object.keys(b);
6369
+ if (aKeys.length !== bKeys.length) {
6370
+ return false;
6371
+ }
6372
+ if (union(aKeys, bKeys).length !== aKeys.length) {
6373
+ return false;
6374
+ }
6375
+ for (let i = 0; i < aKeys.length; i++) {
6376
+ const propKey = aKeys[i];
6377
+ const aProp = a[propKey];
6378
+ const bProp = b[propKey];
6379
+ if (!isEqual(aProp, bProp)) {
6380
+ return false;
6381
+ }
6382
+ }
6383
+ return true;
6384
+ }
6385
+
6338
6386
  // src/predicate/isNil.ts
6339
6387
  function isNil(x) {
6340
6388
  return x == null;
@@ -6446,6 +6494,7 @@ var capitalize2 = (str) => {
6446
6494
  intersectionBy,
6447
6495
  intersectionWith,
6448
6496
  invert,
6497
+ isEqual,
6449
6498
  isNil,
6450
6499
  isNotNil,
6451
6500
  isNull,