es-toolkit 1.6.1-dev.139 → 1.6.1-dev.141

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.
@@ -2,14 +2,14 @@ import {
2
2
  sampleSize
3
3
  } from "../chunk-LUIKU43M.mjs";
4
4
  import "../chunk-TZE6EDCX.mjs";
5
- import "../chunk-GIWAOOFY.mjs";
6
- import "../chunk-UNLX2F2Y.mjs";
7
- import "../chunk-5PMKOZ2F.mjs";
8
5
  import "../chunk-MLCL773E.mjs";
9
6
  import "../chunk-CXGIXTSH.mjs";
10
7
  import "../chunk-LT6E4Y4Z.mjs";
11
8
  import "../chunk-NOFHNJ5C.mjs";
9
+ import "../chunk-GIWAOOFY.mjs";
12
10
  import "../chunk-SYWMYQYJ.mjs";
11
+ import "../chunk-UNLX2F2Y.mjs";
12
+ import "../chunk-5PMKOZ2F.mjs";
13
13
  import "../chunk-2MM5EJJX.mjs";
14
14
  export {
15
15
  sampleSize
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Creates an array that excludes all specified values.
3
+ *
4
+ * It correctly excludes `NaN`, as it compares values using [SameValueZero](https://tc39.es/ecma262/multipage/abstract-operations.html#sec-samevaluezero).
5
+ *
6
+ * @template T The type of elements in the array.
7
+ * @param {T[]} array - The array to filter.
8
+ * @param {...T[]} values - The values to exclude.
9
+ * @returns {T[]} A new array without the specified values.
10
+ *
11
+ * @example
12
+ * // Removes the specified values from the array
13
+ * without([1, 2, 3, 4, 5], 2, 4);
14
+ * // Returns: [1, 3, 5]
15
+ *
16
+ * @example
17
+ * // Removes specified string values from the array
18
+ * without(['a', 'b', 'c', 'a'], 'a');
19
+ * // Returns: ['b', 'c']
20
+ */
21
+ declare function without<T>(array: readonly T[], ...values: T[]): T[];
22
+
23
+ export { without };
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Creates an array that excludes all specified values.
3
+ *
4
+ * It correctly excludes `NaN`, as it compares values using [SameValueZero](https://tc39.es/ecma262/multipage/abstract-operations.html#sec-samevaluezero).
5
+ *
6
+ * @template T The type of elements in the array.
7
+ * @param {T[]} array - The array to filter.
8
+ * @param {...T[]} values - The values to exclude.
9
+ * @returns {T[]} A new array without the specified values.
10
+ *
11
+ * @example
12
+ * // Removes the specified values from the array
13
+ * without([1, 2, 3, 4, 5], 2, 4);
14
+ * // Returns: [1, 3, 5]
15
+ *
16
+ * @example
17
+ * // Removes specified string values from the array
18
+ * without(['a', 'b', 'c', 'a'], 'a');
19
+ * // Returns: ['b', 'c']
20
+ */
21
+ declare function without<T>(array: readonly T[], ...values: T[]): T[];
22
+
23
+ export { without };
@@ -0,0 +1,34 @@
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/array/without.ts
21
+ var without_exports = {};
22
+ __export(without_exports, {
23
+ without: () => without
24
+ });
25
+ module.exports = __toCommonJS(without_exports);
26
+ function without(array, ...values) {
27
+ const valuesSet = new Set(values);
28
+ return array.filter((item) => !valuesSet.has(item));
29
+ }
30
+ // Annotate the CommonJS export names for ESM import in node:
31
+ 0 && (module.exports = {
32
+ without
33
+ });
34
+ //# sourceMappingURL=without.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/array/without.ts"],"sourcesContent":["/**\n * Creates an array that excludes all specified values.\n *\n * It correctly excludes `NaN`, as it compares values using [SameValueZero](https://tc39.es/ecma262/multipage/abstract-operations.html#sec-samevaluezero).\n *\n * @template T The type of elements in the array.\n * @param {T[]} array - The array to filter.\n * @param {...T[]} values - The values to exclude.\n * @returns {T[]} A new array without the specified values.\n *\n * @example\n * // Removes the specified values from the array\n * without([1, 2, 3, 4, 5], 2, 4);\n * // Returns: [1, 3, 5]\n *\n * @example\n * // Removes specified string values from the array\n * without(['a', 'b', 'c', 'a'], 'a');\n * // Returns: ['b', 'c']\n */\nexport function without<T>(array: readonly T[], ...values: T[]): T[] {\n const valuesSet = new Set(values);\n return array.filter(item => !valuesSet.has(item));\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAoBO,SAAS,QAAW,UAAwB,QAAkB;AACnE,QAAM,YAAY,IAAI,IAAI,MAAM;AAChC,SAAO,MAAM,OAAO,UAAQ,CAAC,UAAU,IAAI,IAAI,CAAC;AAClD;","names":[]}
@@ -0,0 +1,8 @@
1
+ import {
2
+ without
3
+ } from "../chunk-PYEYV7BY.mjs";
4
+ import "../chunk-2MM5EJJX.mjs";
5
+ export {
6
+ without
7
+ };
8
+ //# sourceMappingURL=without.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=chunk-56TFSD6O.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,15 @@
1
+ // src/array/countBy.ts
2
+ function countBy(arr, mapper) {
3
+ var _a;
4
+ const result = {};
5
+ for (const item of arr) {
6
+ const key = mapper(item);
7
+ result[key] = ((_a = result[key]) != null ? _a : 0) + 1;
8
+ }
9
+ return result;
10
+ }
11
+
12
+ export {
13
+ countBy
14
+ };
15
+ //# sourceMappingURL=chunk-CRSKT4WW.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/array/countBy.ts"],"sourcesContent":["/**\n * Count the occurrences of each item in an array\n * based on a transformation function.\n *\n * This function takes an array and a transformation function\n * that converts each item in the array to a string. It then\n * counts the occurrences of each transformed item and returns\n * an object with the transformed items as keys and the counts\n * as values.\n *\n * @template T - The type of the items in the input array.\n *\n * @param {T[]} arr - The input array to count occurrences.\n * @param {(item: T) => string} mapper - The transformation function that maps each item to a string key.\n * @returns {Record<string, number>} An object containing the transformed items as keys and the\n * counts as values.\n */\nexport function countBy<T>(arr: T[], mapper: (item: T) => string): Record<string, number> {\n const result: Record<string, number> = {};\n \n for (const item of arr) {\n const key = mapper(item);\n \n result[key] = (result[key] ?? 0) + 1;\n }\n \n return result;\n}\n"],"mappings":";AAiBO,SAAS,QAAW,KAAU,QAAqD;AAjB1F;AAkBE,QAAM,SAAiC,CAAC;AAExC,aAAW,QAAQ,KAAK;AACtB,UAAM,MAAM,OAAO,IAAI;AAEvB,WAAO,GAAG,MAAK,YAAO,GAAG,MAAV,YAAe,KAAK;AAAA,EACrC;AAEA,SAAO;AACT;","names":[]}
@@ -0,0 +1,10 @@
1
+ // src/array/without.ts
2
+ function without(array, ...values) {
3
+ const valuesSet = new Set(values);
4
+ return array.filter((item) => !valuesSet.has(item));
5
+ }
6
+
7
+ export {
8
+ without
9
+ };
10
+ //# sourceMappingURL=chunk-PYEYV7BY.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/array/without.ts"],"sourcesContent":["/**\n * Creates an array that excludes all specified values.\n *\n * It correctly excludes `NaN`, as it compares values using [SameValueZero](https://tc39.es/ecma262/multipage/abstract-operations.html#sec-samevaluezero).\n *\n * @template T The type of elements in the array.\n * @param {T[]} array - The array to filter.\n * @param {...T[]} values - The values to exclude.\n * @returns {T[]} A new array without the specified values.\n *\n * @example\n * // Removes the specified values from the array\n * without([1, 2, 3, 4, 5], 2, 4);\n * // Returns: [1, 3, 5]\n *\n * @example\n * // Removes specified string values from the array\n * without(['a', 'b', 'c', 'a'], 'a');\n * // Returns: ['b', 'c']\n */\nexport function without<T>(array: readonly T[], ...values: T[]): T[] {\n const valuesSet = new Set(values);\n return array.filter(item => !valuesSet.has(item));\n}\n"],"mappings":";AAoBO,SAAS,QAAW,UAAwB,QAAkB;AACnE,QAAM,YAAY,IAAI,IAAI,MAAM;AAChC,SAAO,MAAM,OAAO,UAAQ,CAAC,UAAU,IAAI,IAAI,CAAC;AAClD;","names":[]}
package/dist/index.d.mts CHANGED
@@ -1,5 +1,6 @@
1
1
  export { chunk } from './array/chunk.mjs';
2
2
  export { compact } from './array/compact.mjs';
3
+ export { countBy } from './array/countBy.mjs';
3
4
  export { difference } from './array/difference.mjs';
4
5
  export { differenceBy } from './array/differenceBy.mjs';
5
6
  export { differenceWith } from './array/differenceWith.mjs';
@@ -28,6 +29,7 @@ export { unionWith } from './array/unionWith.mjs';
28
29
  export { uniq } from './array/uniq.mjs';
29
30
  export { uniqBy } from './array/uniqBy.mjs';
30
31
  export { uniqWith } from './array/uniqWith.mjs';
32
+ export { without } from './array/without.mjs';
31
33
  export { xor } from './array/xor.mjs';
32
34
  export { xorBy } from './array/xorBy.mjs';
33
35
  export { xorWith } from './array/xorWith.mjs';
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export { chunk } from './array/chunk.js';
2
2
  export { compact } from './array/compact.js';
3
+ export { countBy } from './array/countBy.js';
3
4
  export { difference } from './array/difference.js';
4
5
  export { differenceBy } from './array/differenceBy.js';
5
6
  export { differenceWith } from './array/differenceWith.js';
@@ -28,6 +29,7 @@ export { unionWith } from './array/unionWith.js';
28
29
  export { uniq } from './array/uniq.js';
29
30
  export { uniqBy } from './array/uniqBy.js';
30
31
  export { uniqWith } from './array/uniqWith.js';
32
+ export { without } from './array/without.js';
31
33
  export { xor } from './array/xor.js';
32
34
  export { xorBy } from './array/xorBy.js';
33
35
  export { xorWith } from './array/xorWith.js';
package/dist/index.js CHANGED
@@ -38,6 +38,7 @@ __export(src_exports, {
38
38
  chunk: () => chunk,
39
39
  clamp: () => clamp,
40
40
  compact: () => compact,
41
+ countBy: () => countBy,
41
42
  debounce: () => debounce,
42
43
  delay: () => delay,
43
44
  difference: () => difference,
@@ -87,6 +88,7 @@ __export(src_exports, {
87
88
  uniq: () => uniq,
88
89
  uniqBy: () => uniqBy,
89
90
  uniqWith: () => uniqWith,
91
+ without: () => without,
90
92
  xor: () => xor,
91
93
  xorBy: () => xorBy,
92
94
  xorWith: () => xorWith,
@@ -122,6 +124,17 @@ function compact(arr) {
122
124
  return result;
123
125
  }
124
126
 
127
+ // src/array/countBy.ts
128
+ function countBy(arr, mapper) {
129
+ var _a;
130
+ const result = {};
131
+ for (const item of arr) {
132
+ const key = mapper(item);
133
+ result[key] = ((_a = result[key]) != null ? _a : 0) + 1;
134
+ }
135
+ return result;
136
+ }
137
+
125
138
  // src/array/difference.ts
126
139
  function difference(firstArr, secondArr) {
127
140
  const secondSet = new Set(secondArr);
@@ -453,6 +466,12 @@ function uniqBy(arr, mapper) {
453
466
  return Array.from(map.values());
454
467
  }
455
468
 
469
+ // src/array/without.ts
470
+ function without(array, ...values) {
471
+ const valuesSet = new Set(values);
472
+ return array.filter((item) => !valuesSet.has(item));
473
+ }
474
+
456
475
  // src/array/xor.ts
457
476
  function xor(arr1, arr2) {
458
477
  return difference(union(arr1, arr2), intersection(arr1, arr2));
@@ -671,6 +690,7 @@ function delay(ms, { signal } = {}) {
671
690
  chunk,
672
691
  clamp,
673
692
  compact,
693
+ countBy,
674
694
  debounce,
675
695
  delay,
676
696
  difference,
@@ -720,6 +740,7 @@ function delay(ms, { signal } = {}) {
720
740
  uniq,
721
741
  uniqBy,
722
742
  uniqWith,
743
+ without,
723
744
  xor,
724
745
  xorBy,
725
746
  xorWith,