es-toolkit 1.12.0 → 1.13.0-dev.290

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (171) hide show
  1. package/CHANGELOG.md +16 -5
  2. package/dist/array/chunk.mjs +1 -1
  3. package/dist/array/compact.mjs +1 -1
  4. package/dist/array/countBy.mjs +1 -1
  5. package/dist/array/difference.mjs +1 -1
  6. package/dist/array/differenceBy.mjs +1 -1
  7. package/dist/array/differenceWith.mjs +1 -1
  8. package/dist/array/drop.mjs +1 -1
  9. package/dist/array/dropRight.mjs +1 -1
  10. package/dist/array/dropRightWhile.mjs +1 -1
  11. package/dist/array/dropWhile.mjs +1 -1
  12. package/dist/array/fill.mjs +1 -1
  13. package/dist/array/flatMap.mjs +1 -1
  14. package/dist/array/flatten.mjs +1 -1
  15. package/dist/array/flattenDeep.mjs +1 -1
  16. package/dist/array/forEachRight.mjs +1 -1
  17. package/dist/array/groupBy.mjs +1 -1
  18. package/dist/array/head.mjs +1 -1
  19. package/dist/array/index.js.map +1 -1
  20. package/dist/array/index.mjs +2 -2
  21. package/dist/array/initial.mjs +1 -1
  22. package/dist/array/intersection.mjs +1 -1
  23. package/dist/array/intersectionBy.mjs +1 -1
  24. package/dist/array/intersectionWith.mjs +1 -1
  25. package/dist/array/keyBy.mjs +1 -1
  26. package/dist/array/last.mjs +1 -1
  27. package/dist/array/maxBy.mjs +1 -1
  28. package/dist/array/minBy.mjs +1 -1
  29. package/dist/array/orderBy.mjs +1 -1
  30. package/dist/array/partition.mjs +1 -1
  31. package/dist/array/sample.mjs +1 -1
  32. package/dist/array/sampleSize.mjs +1 -1
  33. package/dist/array/shuffle.mjs +1 -1
  34. package/dist/array/tail.d.mts +24 -0
  35. package/dist/array/tail.d.ts +24 -0
  36. package/dist/array/tail.js.map +1 -1
  37. package/dist/array/tail.mjs +2 -2
  38. package/dist/array/take.mjs +1 -1
  39. package/dist/array/takeRight.mjs +1 -1
  40. package/dist/array/takeRightWhile.mjs +1 -1
  41. package/dist/array/takeWhile.mjs +1 -1
  42. package/dist/array/toFilled.mjs +1 -1
  43. package/dist/array/union.mjs +1 -1
  44. package/dist/array/unionBy.mjs +1 -1
  45. package/dist/array/unionWith.mjs +1 -1
  46. package/dist/array/uniq.mjs +1 -1
  47. package/dist/array/uniqBy.mjs +1 -1
  48. package/dist/array/uniqWith.mjs +1 -1
  49. package/dist/array/unzip.mjs +1 -1
  50. package/dist/array/unzipWith.mjs +1 -1
  51. package/dist/array/without.mjs +1 -1
  52. package/dist/array/xor.mjs +1 -1
  53. package/dist/array/xorBy.mjs +1 -1
  54. package/dist/array/xorWith.mjs +1 -1
  55. package/dist/array/zip.mjs +1 -1
  56. package/dist/array/zipObject.mjs +1 -1
  57. package/dist/array/zipWith.mjs +1 -1
  58. package/dist/browser.d.mts +2 -0
  59. package/dist/browser.d.ts +2 -0
  60. package/dist/browser.js +1108 -0
  61. package/dist/browser.js.map +1 -0
  62. package/dist/browser.mjs +108 -0
  63. package/dist/browser.mjs.map +1 -0
  64. package/dist/{chunk-424M7IR7.mjs → chunk-24FKGR6U.mjs} +6 -1
  65. package/dist/chunk-27QMXBLJ.mjs +9 -0
  66. package/dist/chunk-27QMXBLJ.mjs.map +1 -0
  67. package/dist/chunk-54TK5BIS.mjs +1 -0
  68. package/dist/chunk-5JN3CIWZ.mjs +373 -0
  69. package/dist/chunk-5JN3CIWZ.mjs.map +1 -0
  70. package/dist/chunk-B645AYL4.mjs +1 -0
  71. package/dist/{chunk-J3GE7DEU.mjs → chunk-CVVZHOJX.mjs} +2 -2
  72. package/dist/{chunk-XWPCDIFC.mjs → chunk-IIDZ3KAJ.mjs} +3 -3
  73. package/dist/chunk-MIGAC7F4.mjs +25 -0
  74. package/dist/chunk-MIGAC7F4.mjs.map +1 -0
  75. package/dist/{chunk-OF6NM4G7.mjs → chunk-TJ4Z5I7M.mjs} +1 -1
  76. package/dist/{chunk-OF6NM4G7.mjs.map → chunk-TJ4Z5I7M.mjs.map} +1 -1
  77. package/dist/{chunk-U7V3G7CR.mjs → chunk-WFZXCGEG.mjs} +2 -2
  78. package/dist/chunk-XGQWTHW6.mjs +34 -0
  79. package/dist/chunk-XGQWTHW6.mjs.map +1 -0
  80. package/dist/compat/index.d.mts +59 -3
  81. package/dist/compat/index.d.ts +59 -3
  82. package/dist/compat/index.js +105 -1
  83. package/dist/compat/index.js.map +1 -1
  84. package/dist/compat/index.mjs +90 -36
  85. package/dist/compat/index.mjs.map +1 -1
  86. package/dist/error/AbortError.mjs +1 -1
  87. package/dist/error/TimeoutError.mjs +1 -1
  88. package/dist/error/index.mjs +1 -1
  89. package/dist/function/debounce.mjs +1 -1
  90. package/dist/function/index.mjs +1 -1
  91. package/dist/function/negate.mjs +1 -1
  92. package/dist/function/noop.mjs +1 -1
  93. package/dist/function/once.mjs +1 -1
  94. package/dist/function/throttle.mjs +1 -1
  95. package/dist/index.d.mts +3 -0
  96. package/dist/index.d.ts +3 -0
  97. package/dist/index.js +58 -0
  98. package/dist/index.js.map +1 -1
  99. package/dist/index.mjs +47 -35
  100. package/dist/math/clamp.mjs +1 -1
  101. package/dist/math/inRange.mjs +1 -1
  102. package/dist/math/index.mjs +7 -7
  103. package/dist/math/mean.mjs +1 -1
  104. package/dist/math/meanBy.mjs +1 -1
  105. package/dist/math/random.mjs +1 -1
  106. package/dist/math/randomInt.mjs +1 -1
  107. package/dist/math/range.mjs +1 -1
  108. package/dist/math/round.mjs +1 -1
  109. package/dist/math/sum.mjs +1 -1
  110. package/dist/math/sumBy.mjs +1 -1
  111. package/dist/object/clone.mjs +1 -1
  112. package/dist/object/flattenObject.d.mts +28 -0
  113. package/dist/object/flattenObject.d.ts +28 -0
  114. package/dist/object/flattenObject.js +77 -0
  115. package/dist/object/flattenObject.js.map +1 -0
  116. package/dist/object/flattenObject.mjs +9 -0
  117. package/dist/object/index.d.mts +1 -0
  118. package/dist/object/index.d.ts +1 -0
  119. package/dist/object/index.js +49 -0
  120. package/dist/object/index.js.map +1 -1
  121. package/dist/object/index.mjs +14 -9
  122. package/dist/object/invert.mjs +1 -1
  123. package/dist/object/omit.mjs +2 -2
  124. package/dist/object/omitBy.mjs +1 -1
  125. package/dist/object/pick.mjs +1 -1
  126. package/dist/object/pickBy.mjs +1 -1
  127. package/dist/predicate/index.d.mts +2 -0
  128. package/dist/predicate/index.d.ts +2 -0
  129. package/dist/predicate/index.js +30 -0
  130. package/dist/predicate/index.js.map +1 -1
  131. package/dist/predicate/index.mjs +15 -7
  132. package/dist/predicate/isEqual.mjs +1 -1
  133. package/dist/predicate/isLength.d.mts +3 -0
  134. package/dist/predicate/isLength.d.ts +3 -0
  135. package/dist/predicate/isLength.js +33 -0
  136. package/dist/predicate/isLength.js.map +1 -0
  137. package/dist/predicate/isLength.mjs +8 -0
  138. package/dist/predicate/isLength.mjs.map +1 -0
  139. package/dist/predicate/isNil.mjs +1 -1
  140. package/dist/predicate/isNotNil.mjs +1 -1
  141. package/dist/predicate/isNull.mjs +1 -1
  142. package/dist/predicate/isPlainObject.d.mts +16 -0
  143. package/dist/predicate/isPlainObject.d.ts +16 -0
  144. package/dist/predicate/isPlainObject.js +49 -0
  145. package/dist/predicate/isPlainObject.js.map +1 -0
  146. package/dist/predicate/isPlainObject.mjs +8 -0
  147. package/dist/predicate/isPlainObject.mjs.map +1 -0
  148. package/dist/predicate/isUndefined.mjs +1 -1
  149. package/dist/promise/delay.mjs +1 -1
  150. package/dist/promise/index.mjs +3 -3
  151. package/dist/promise/timeout.mjs +2 -2
  152. package/dist/promise/withTimeout.mjs +3 -3
  153. package/dist/string/camelCase.mjs +1 -1
  154. package/dist/string/capitalize.mjs +1 -1
  155. package/dist/string/index.mjs +7 -7
  156. package/dist/string/kebabCase.mjs +1 -1
  157. package/dist/string/lowerCase.mjs +1 -1
  158. package/dist/string/snakeCase.mjs +1 -1
  159. package/dist/string/startCase.mjs +1 -1
  160. package/package.json +3 -1
  161. package/umd/browser.global.js +2 -0
  162. package/dist/chunk-ASJF5D6C.mjs +0 -1
  163. package/dist/chunk-NKLIE2OI.mjs +0 -1
  164. package/dist/chunk-OSOLEQLZ.mjs +0 -1
  165. /package/dist/{chunk-424M7IR7.mjs.map → chunk-24FKGR6U.mjs.map} +0 -0
  166. /package/dist/{chunk-ASJF5D6C.mjs.map → chunk-54TK5BIS.mjs.map} +0 -0
  167. /package/dist/{chunk-NKLIE2OI.mjs.map → chunk-B645AYL4.mjs.map} +0 -0
  168. /package/dist/{chunk-J3GE7DEU.mjs.map → chunk-CVVZHOJX.mjs.map} +0 -0
  169. /package/dist/{chunk-XWPCDIFC.mjs.map → chunk-IIDZ3KAJ.mjs.map} +0 -0
  170. /package/dist/{chunk-U7V3G7CR.mjs.map → chunk-WFZXCGEG.mjs.map} +0 -0
  171. /package/dist/{chunk-OSOLEQLZ.mjs.map → object/flattenObject.mjs.map} +0 -0
@@ -1,6 +1,5 @@
1
1
  export { compact } from '../array/compact.js';
2
2
  export { countBy } from '../array/countBy.js';
3
- export { difference } from '../array/difference.js';
4
3
  export { differenceBy } from '../array/differenceBy.js';
5
4
  export { differenceWith } from '../array/differenceWith.js';
6
5
  export { drop } from '../array/drop.js';
@@ -43,7 +42,7 @@ export { zip } from '../array/zip.js';
43
42
  export { zipObject } from '../array/zipObject.js';
44
43
  export { zipWith } from '../array/zipWith.js';
45
44
  export { without } from '../array/without.js';
46
- export { head } from '../array/head.js';
45
+ export { head as first, head } from '../array/head.js';
47
46
  export { tail } from '../array/tail.js';
48
47
  export { toFilled } from '../array/toFilled.js';
49
48
  export { last } from '../array/last.js';
@@ -71,11 +70,13 @@ export { pick } from '../object/pick.js';
71
70
  export { pickBy } from '../object/pickBy.js';
72
71
  export { invert } from '../object/invert.js';
73
72
  export { clone } from '../object/clone.js';
73
+ export { flattenObject } from '../object/flattenObject.js';
74
74
  export { isEqual } from '../predicate/isEqual.js';
75
75
  export { isNil } from '../predicate/isNil.js';
76
76
  export { isNotNil } from '../predicate/isNotNil.js';
77
77
  export { isNull } from '../predicate/isNull.js';
78
78
  export { isUndefined } from '../predicate/isUndefined.js';
79
+ export { isLength } from '../predicate/isLength.js';
79
80
  export { delay } from '../promise/delay.js';
80
81
  export { withTimeout } from '../promise/withTimeout.js';
81
82
  export { camelCase } from '../string/camelCase.js';
@@ -110,6 +111,37 @@ export { capitalize } from '../string/capitalize.js';
110
111
  */
111
112
  declare function chunk<T>(arr: readonly T[], size?: number): T[][];
112
113
 
114
+ /**
115
+ * Concatenates multiple arrays and values into a single array.
116
+ *
117
+ * @template T The type of elements in the array.
118
+ * @param {...(T | readonly T[])} values - The values and/or arrays to concatenate.
119
+ * @returns {T[]} A new array containing all the input values.
120
+ *
121
+ * @example
122
+ * // Concatenate individual values
123
+ * concat(1, 2, 3);
124
+ * // returns [1, 2, 3]
125
+ *
126
+ * @example
127
+ * // Concatenate arrays of values
128
+ * concat([1, 2], [3, 4]);
129
+ * // returns [1, 2, 3, 4]
130
+ *
131
+ * @example
132
+ * // Concatenate a mix of individual values and arrays
133
+ * concat(1, [2, 3], 4);
134
+ * // returns [1, 2, 3, 4]
135
+ *
136
+ * @example
137
+ * // Concatenate nested arrays
138
+ * concat([1, [2, 3]], 4);
139
+ * // returns [1, [2, 3], 4]
140
+ */
141
+ declare function concat<T>(...values: Array<T | readonly T[]>): T[];
142
+
143
+ declare function difference<T>(arr: readonly T[], ...values: Array<readonly T[]>): T[];
144
+
113
145
  /**
114
146
  * Creates a deeply nested object given arrays of paths and values.
115
147
  *
@@ -427,6 +459,30 @@ declare function get(object: unknown, path: PropertyKey | readonly PropertyKey[]
427
459
  */
428
460
  declare function set<T>(obj: object, path: PropertyKey | readonly PropertyKey[], value: unknown): T;
429
461
 
462
+ /**
463
+ * Checks if a given value is a plain object.
464
+ *
465
+ * A plain object is an object created by the `{}` literal, `new Object()`, or
466
+ * `Object.create(null)`.
467
+ *
468
+ * This function also handles objects with custom
469
+ * `Symbol.toStringTag` properties.
470
+ *
471
+ * `Symbol.toStringTag` is a built-in symbol that a constructor can use to customize the
472
+ * default string description of objects.
473
+ *
474
+ * @param {unknown} [object] - The value to check.
475
+ * @returns {boolean} - True if the value is a plain object, otherwise false.
476
+ *
477
+ * @example
478
+ * console.log(isPlainObject({})); // true
479
+ * console.log(isPlainObject([])); // false
480
+ * console.log(isPlainObject(null)); // false
481
+ * console.log(isPlainObject(Object.create(null))); // true
482
+ * console.log(isPlainObject(new Map())); // false
483
+ */
484
+ declare function isPlainObject(object?: unknown): boolean;
485
+
430
486
  /**
431
487
  * Checks if a string contains another string at the beginning of the string.
432
488
  *
@@ -497,4 +553,4 @@ declare function max<T>(items?: readonly T[]): T;
497
553
  */
498
554
  declare function min<T>(items?: readonly T[]): T;
499
555
 
500
- export { chunk, endsWith, get, max, min, set, startsWith, zipObjectDeep };
556
+ export { chunk, concat, difference, endsWith, get, isPlainObject, max, min, set, startsWith, zipObjectDeep };
@@ -62,10 +62,11 @@ __export(compat_exports, {
62
62
  clamp: () => clamp,
63
63
  clone: () => clone,
64
64
  compact: () => compact,
65
+ concat: () => concat,
65
66
  countBy: () => countBy,
66
67
  debounce: () => debounce,
67
68
  delay: () => delay,
68
- difference: () => difference,
69
+ difference: () => difference2,
69
70
  differenceBy: () => differenceBy,
70
71
  differenceWith: () => differenceWith,
71
72
  drop: () => drop,
@@ -74,9 +75,11 @@ __export(compat_exports, {
74
75
  dropWhile: () => dropWhile,
75
76
  endsWith: () => endsWith,
76
77
  fill: () => fill,
78
+ first: () => head,
77
79
  flatMap: () => flatMap,
78
80
  flatten: () => flatten,
79
81
  flattenDeep: () => flattenDeep,
82
+ flattenObject: () => flattenObject,
80
83
  forEachRight: () => forEachRight,
81
84
  get: () => get,
82
85
  groupBy: () => groupBy,
@@ -88,9 +91,11 @@ __export(compat_exports, {
88
91
  intersectionWith: () => intersectionWith,
89
92
  invert: () => invert,
90
93
  isEqual: () => isEqual,
94
+ isLength: () => isLength,
91
95
  isNil: () => isNil,
92
96
  isNotNil: () => isNotNil,
93
97
  isNull: () => isNull,
98
+ isPlainObject: () => isPlainObject2,
94
99
  isUndefined: () => isUndefined,
95
100
  kebabCase: () => kebabCase,
96
101
  keyBy: () => keyBy,
@@ -924,6 +929,53 @@ function isPrimitive(value) {
924
929
  return value == null || typeof value !== "object" && typeof value !== "function";
925
930
  }
926
931
 
932
+ // src/predicate/isPlainObject.ts
933
+ function isPlainObject(object) {
934
+ if (typeof object !== "object") {
935
+ return false;
936
+ }
937
+ if (object == null) {
938
+ return false;
939
+ }
940
+ if (Object.getPrototypeOf(object) === null) {
941
+ return true;
942
+ }
943
+ if (object.toString() !== "[object Object]") {
944
+ return false;
945
+ }
946
+ let proto = object;
947
+ while (Object.getPrototypeOf(proto) !== null) {
948
+ proto = Object.getPrototypeOf(proto);
949
+ }
950
+ return Object.getPrototypeOf(object) === proto;
951
+ }
952
+
953
+ // src/object/flattenObject.ts
954
+ function flattenObject(object) {
955
+ return flattenObjectImpl(object);
956
+ }
957
+ function flattenObjectImpl(object, prefix = "") {
958
+ const result = {};
959
+ const keys = Object.keys(object);
960
+ for (let i = 0; i < keys.length; i++) {
961
+ const key = keys[i];
962
+ const value = object[key];
963
+ const prefixedKey = prefix ? `${prefix}.${key}` : key;
964
+ if (isPlainObject(value) && Object.keys(value).length > 0) {
965
+ Object.assign(result, flattenObjectImpl(value, prefixedKey));
966
+ continue;
967
+ }
968
+ if (Array.isArray(value)) {
969
+ for (let index = 0; index < value.length; index++) {
970
+ result[`${prefixedKey}.${index}`] = value[index];
971
+ }
972
+ continue;
973
+ }
974
+ result[prefixedKey] = value;
975
+ }
976
+ return result;
977
+ }
978
+
927
979
  // src/predicate/isEqual.ts
928
980
  function isEqual(a, b) {
929
981
  if (Object.is(a, b)) {
@@ -977,6 +1029,11 @@ function isUndefined(x) {
977
1029
  return x === void 0;
978
1030
  }
979
1031
 
1032
+ // src/predicate/isLength.ts
1033
+ function isLength(value) {
1034
+ return typeof value === "number" && value > -1 && value % 1 === 0 && value <= Number.MAX_SAFE_INTEGER;
1035
+ }
1036
+
980
1037
  // src/promise/delay.ts
981
1038
  function delay(ms, { signal } = {}) {
982
1039
  return new Promise((resolve, reject) => {
@@ -1076,6 +1133,18 @@ function chunk2(arr, size = 1) {
1076
1133
  return chunk(arr, size);
1077
1134
  }
1078
1135
 
1136
+ // src/compat/array/concat.ts
1137
+ function concat(...values) {
1138
+ return flatten(values);
1139
+ }
1140
+
1141
+ // src/compat/array/difference.ts
1142
+ function difference2(arr, ...values) {
1143
+ const arr1 = arr;
1144
+ const arr2 = flatten(values);
1145
+ return difference(arr1, arr2);
1146
+ }
1147
+
1079
1148
  // src/compat/_internal/isIndex.ts
1080
1149
  var IS_UNSIGNED_INTEGER = /^(?:0|[1-9]\d*)$/;
1081
1150
  function isIndex(value) {
@@ -1197,6 +1266,36 @@ function get(object, path, defaultValue) {
1197
1266
  return current != null ? current : defaultValue;
1198
1267
  }
1199
1268
 
1269
+ // src/compat/predicate/isPlainObject.ts
1270
+ function isPlainObject2(object) {
1271
+ var _a;
1272
+ if (typeof object !== "object") {
1273
+ return false;
1274
+ }
1275
+ if (object == null) {
1276
+ return false;
1277
+ }
1278
+ if (Object.getPrototypeOf(object) === null) {
1279
+ return true;
1280
+ }
1281
+ if (object.toString() !== "[object Object]") {
1282
+ const tag = object[Symbol.toStringTag];
1283
+ if (tag == null) {
1284
+ return false;
1285
+ }
1286
+ const isTagReadonly = !((_a = Object.getOwnPropertyDescriptor(object, Symbol.toStringTag)) == null ? void 0 : _a.writable);
1287
+ if (isTagReadonly) {
1288
+ return false;
1289
+ }
1290
+ return object.toString() === `[object ${tag}]`;
1291
+ }
1292
+ let proto = object;
1293
+ while (Object.getPrototypeOf(proto) !== null) {
1294
+ proto = Object.getPrototypeOf(proto);
1295
+ }
1296
+ return Object.getPrototypeOf(object) === proto;
1297
+ }
1298
+
1200
1299
  // src/compat/string/startsWith.ts
1201
1300
  var startsWith = (str, target, position = 0) => {
1202
1301
  return str.startsWith(target, position);
@@ -1242,6 +1341,7 @@ function min(items = []) {
1242
1341
  clamp,
1243
1342
  clone,
1244
1343
  compact,
1344
+ concat,
1245
1345
  countBy,
1246
1346
  debounce,
1247
1347
  delay,
@@ -1254,9 +1354,11 @@ function min(items = []) {
1254
1354
  dropWhile,
1255
1355
  endsWith,
1256
1356
  fill,
1357
+ first,
1257
1358
  flatMap,
1258
1359
  flatten,
1259
1360
  flattenDeep,
1361
+ flattenObject,
1260
1362
  forEachRight,
1261
1363
  get,
1262
1364
  groupBy,
@@ -1268,9 +1370,11 @@ function min(items = []) {
1268
1370
  intersectionWith,
1269
1371
  invert,
1270
1372
  isEqual,
1373
+ isLength,
1271
1374
  isNil,
1272
1375
  isNotNil,
1273
1376
  isNull,
1377
+ isPlainObject,
1274
1378
  isUndefined,
1275
1379
  kebabCase,
1276
1380
  keyBy,