es-toolkit 1.7.1-dev.152 → 1.7.1-dev.154

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 (39) hide show
  1. package/dist/array/index.mjs +40 -40
  2. package/dist/chunk-BH6HLGBA.mjs +16 -0
  3. package/dist/chunk-BH6HLGBA.mjs.map +1 -0
  4. package/dist/chunk-FLTT2MGF.mjs +14 -0
  5. package/dist/chunk-FLTT2MGF.mjs.map +1 -0
  6. package/dist/chunk-PMHULJNL.mjs +1 -0
  7. package/dist/chunk-TLVQSNOE.mjs +1 -0
  8. package/dist/index.d.mts +2 -0
  9. package/dist/index.d.ts +2 -0
  10. package/dist/index.js +26 -0
  11. package/dist/index.js.map +1 -1
  12. package/dist/index.mjs +70 -62
  13. package/dist/math/inRange.d.mts +4 -0
  14. package/dist/math/inRange.d.ts +4 -0
  15. package/dist/math/inRange.js +40 -0
  16. package/dist/math/inRange.js.map +1 -0
  17. package/dist/math/inRange.mjs +8 -0
  18. package/dist/math/inRange.mjs.map +1 -0
  19. package/dist/math/index.d.mts +1 -0
  20. package/dist/math/index.d.ts +1 -0
  21. package/dist/math/index.js +14 -0
  22. package/dist/math/index.js.map +1 -1
  23. package/dist/math/index.mjs +5 -1
  24. package/dist/object/index.d.mts +1 -0
  25. package/dist/object/index.d.ts +1 -0
  26. package/dist/object/index.js +12 -0
  27. package/dist/object/index.js.map +1 -1
  28. package/dist/object/index.mjs +11 -7
  29. package/dist/object/invert.d.mts +24 -0
  30. package/dist/object/invert.d.ts +24 -0
  31. package/dist/object/invert.js +38 -0
  32. package/dist/object/invert.js.map +1 -0
  33. package/dist/object/invert.mjs +8 -0
  34. package/dist/object/invert.mjs.map +1 -0
  35. package/package.json +1 -1
  36. package/dist/chunk-T5JCRGXA.mjs +0 -1
  37. package/dist/chunk-TZE6EDCX.mjs +0 -1
  38. /package/dist/{chunk-T5JCRGXA.mjs.map → chunk-PMHULJNL.mjs.map} +0 -0
  39. /package/dist/{chunk-TZE6EDCX.mjs.map → chunk-TLVQSNOE.mjs.map} +0 -0
@@ -1,4 +1,16 @@
1
1
  import "../chunk-XJR5WV2Z.mjs";
2
+ import {
3
+ zip
4
+ } from "../chunk-IDCUZVJL.mjs";
5
+ import {
6
+ zipObject
7
+ } from "../chunk-6GWEY5EL.mjs";
8
+ import {
9
+ zipWith
10
+ } from "../chunk-4KYXHZ4R.mjs";
11
+ import {
12
+ uniqBy
13
+ } from "../chunk-OXAZEEGP.mjs";
2
14
  import {
3
15
  unzipWith
4
16
  } from "../chunk-IFNXROZR.mjs";
@@ -15,14 +27,14 @@ import {
15
27
  xorWith
16
28
  } from "../chunk-QRSJBBFY.mjs";
17
29
  import {
18
- zip
19
- } from "../chunk-IDCUZVJL.mjs";
30
+ shuffle
31
+ } from "../chunk-G7UQ5PUR.mjs";
20
32
  import {
21
- zipObject
22
- } from "../chunk-6GWEY5EL.mjs";
33
+ take
34
+ } from "../chunk-ME352XO7.mjs";
23
35
  import {
24
- zipWith
25
- } from "../chunk-4KYXHZ4R.mjs";
36
+ takeRight
37
+ } from "../chunk-IQLKIDXF.mjs";
26
38
  import {
27
39
  takeRightWhile
28
40
  } from "../chunk-NTLX2MPV.mjs";
@@ -32,21 +44,27 @@ import {
32
44
  import {
33
45
  union
34
46
  } from "../chunk-R6QA7PLZ.mjs";
47
+ import {
48
+ uniq
49
+ } from "../chunk-DVK2N4KC.mjs";
35
50
  import {
36
51
  unionBy
37
52
  } from "../chunk-NFS7RWWE.mjs";
38
53
  import {
39
54
  unionWith
40
55
  } from "../chunk-2ZCITDMK.mjs";
41
- import {
42
- uniq
43
- } from "../chunk-DVK2N4KC.mjs";
44
- import {
45
- uniqBy
46
- } from "../chunk-OXAZEEGP.mjs";
47
56
  import {
48
57
  uniqWith
49
58
  } from "../chunk-237HGSZS.mjs";
59
+ import {
60
+ intersectionBy
61
+ } from "../chunk-O6UXZR3U.mjs";
62
+ import {
63
+ intersectionWith
64
+ } from "../chunk-XI7KRD2C.mjs";
65
+ import {
66
+ keyBy
67
+ } from "../chunk-AJKZMN2V.mjs";
50
68
  import {
51
69
  maxBy
52
70
  } from "../chunk-OOKNBU4V.mjs";
@@ -65,14 +83,14 @@ import {
65
83
  import "../chunk-GIWAOOFY.mjs";
66
84
  import "../chunk-SYWMYQYJ.mjs";
67
85
  import {
68
- shuffle
69
- } from "../chunk-G7UQ5PUR.mjs";
86
+ dropRight
87
+ } from "../chunk-JEKUA56R.mjs";
70
88
  import {
71
- take
72
- } from "../chunk-ME352XO7.mjs";
89
+ dropRightWhile
90
+ } from "../chunk-JE6JKZU3.mjs";
73
91
  import {
74
- takeRight
75
- } from "../chunk-IQLKIDXF.mjs";
92
+ dropWhile
93
+ } from "../chunk-LJ2C6MVP.mjs";
76
94
  import {
77
95
  fill
78
96
  } from "../chunk-C4WE4GLC.mjs";
@@ -86,14 +104,11 @@ import {
86
104
  intersection
87
105
  } from "../chunk-FVVSE2F2.mjs";
88
106
  import {
89
- intersectionBy
90
- } from "../chunk-O6UXZR3U.mjs";
91
- import {
92
- intersectionWith
93
- } from "../chunk-XI7KRD2C.mjs";
107
+ chunk
108
+ } from "../chunk-E6C5EZQA.mjs";
94
109
  import {
95
- keyBy
96
- } from "../chunk-AJKZMN2V.mjs";
110
+ compact
111
+ } from "../chunk-DTJJIMKJ.mjs";
97
112
  import {
98
113
  countBy
99
114
  } from "../chunk-CRSKT4WW.mjs";
@@ -109,21 +124,6 @@ import {
109
124
  import {
110
125
  drop
111
126
  } from "../chunk-S3CORED5.mjs";
112
- import {
113
- dropRight
114
- } from "../chunk-JEKUA56R.mjs";
115
- import {
116
- dropRightWhile
117
- } from "../chunk-JE6JKZU3.mjs";
118
- import {
119
- dropWhile
120
- } from "../chunk-LJ2C6MVP.mjs";
121
- import {
122
- chunk
123
- } from "../chunk-E6C5EZQA.mjs";
124
- import {
125
- compact
126
- } from "../chunk-DTJJIMKJ.mjs";
127
127
  import "../chunk-2MM5EJJX.mjs";
128
128
  export {
129
129
  chunk,
@@ -0,0 +1,16 @@
1
+ // src/math/inRange.ts
2
+ function inRange(value, minimum, maximum) {
3
+ if (maximum == null) {
4
+ maximum = minimum;
5
+ minimum = 0;
6
+ }
7
+ if (minimum >= maximum) {
8
+ throw new Error("The maximum value must be greater than the minimum value.");
9
+ }
10
+ return minimum <= value && value < maximum;
11
+ }
12
+
13
+ export {
14
+ inRange
15
+ };
16
+ //# sourceMappingURL=chunk-BH6HLGBA.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/math/inRange.ts"],"sourcesContent":["export function inRange(value: number, maximum: number): boolean;\nexport function inRange(value: number, minimum: number, maximum: number): boolean;\n/**\n * Checks if the value is within a specified range.\n *\n * @param {number} value The value to check.\n * @param {number} minimum The lower bound of the range (inclusive).\n * @param {number} maximum The upper bound of the range (exclusive).\n * @returns {boolean} `true` if the value is within the specified range, otherwise `false`.\n * @throws {Error} Throws an error if the `minimum` is greater or equal than the `maximum`.\n *\n * @example\n * const result1 = inRange(3, 5); // result1 will be true.\n * const result2 = inRange(1, 2, 5); // result2 will be false.\n * const result3 = inRange(1, 5, 2); // If the minimum is greater or equal than the maximum, an error is thrown.\n */\nexport function inRange(value: number, minimum: number, maximum?: number): boolean {\n if (maximum == null) {\n maximum = minimum;\n minimum = 0;\n }\n\n if (minimum >= maximum) {\n throw new Error('The maximum value must be greater than the minimum value.');\n }\n\n return minimum <= value && value < maximum;\n}\n"],"mappings":";AAgBO,SAAS,QAAQ,OAAe,SAAiB,SAA2B;AACjF,MAAI,WAAW,MAAM;AACnB,cAAU;AACV,cAAU;AAAA,EACZ;AAEA,MAAI,WAAW,SAAS;AACtB,UAAM,IAAI,MAAM,2DAA2D;AAAA,EAC7E;AAEA,SAAO,WAAW,SAAS,QAAQ;AACrC;","names":[]}
@@ -0,0 +1,14 @@
1
+ // src/object/invert.ts
2
+ function invert(obj) {
3
+ const result = {};
4
+ for (const key in obj) {
5
+ const value = obj[key];
6
+ result[value] = key;
7
+ }
8
+ return result;
9
+ }
10
+
11
+ export {
12
+ invert
13
+ };
14
+ //# sourceMappingURL=chunk-FLTT2MGF.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/object/invert.ts"],"sourcesContent":["/**\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 */\n\ntype PropertyKey = string | number | symbol;\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":";AAqBO,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":[]}
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=chunk-PMHULJNL.mjs.map
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=chunk-TLVQSNOE.mjs.map
package/dist/index.d.mts CHANGED
@@ -45,6 +45,7 @@ export { noop } from './function/noop.mjs';
45
45
  export { once } from './function/once.mjs';
46
46
  export { throttle } from './function/throttle.mjs';
47
47
  export { clamp } from './math/clamp.mjs';
48
+ export { inRange } from './math/inRange.mjs';
48
49
  export { mean } from './math/mean.mjs';
49
50
  export { meanBy } from './math/meanBy.mjs';
50
51
  export { random } from './math/random.mjs';
@@ -56,6 +57,7 @@ export { omit } from './object/omit.mjs';
56
57
  export { omitBy } from './object/omitBy.mjs';
57
58
  export { pick } from './object/pick.mjs';
58
59
  export { pickBy } from './object/pickBy.mjs';
60
+ export { invert } from './object/invert.mjs';
59
61
  export { isNil } from './predicate/isNil.mjs';
60
62
  export { isNotNil } from './predicate/isNotNil.mjs';
61
63
  export { isNull } from './predicate/isNull.mjs';
package/dist/index.d.ts CHANGED
@@ -45,6 +45,7 @@ export { noop } from './function/noop.js';
45
45
  export { once } from './function/once.js';
46
46
  export { throttle } from './function/throttle.js';
47
47
  export { clamp } from './math/clamp.js';
48
+ export { inRange } from './math/inRange.js';
48
49
  export { mean } from './math/mean.js';
49
50
  export { meanBy } from './math/meanBy.js';
50
51
  export { random } from './math/random.js';
@@ -56,6 +57,7 @@ export { omit } from './object/omit.js';
56
57
  export { omitBy } from './object/omitBy.js';
57
58
  export { pick } from './object/pick.js';
58
59
  export { pickBy } from './object/pickBy.js';
60
+ export { invert } from './object/invert.js';
59
61
  export { isNil } from './predicate/isNil.js';
60
62
  export { isNotNil } from './predicate/isNotNil.js';
61
63
  export { isNull } from './predicate/isNull.js';
package/dist/index.js CHANGED
@@ -51,9 +51,11 @@ __export(src_exports, {
51
51
  fill: () => fill,
52
52
  forEachRight: () => forEachRight,
53
53
  groupBy: () => groupBy,
54
+ inRange: () => inRange,
54
55
  intersection: () => intersection,
55
56
  intersectionBy: () => intersectionBy,
56
57
  intersectionWith: () => intersectionWith,
58
+ invert: () => invert,
57
59
  isNil: () => isNil,
58
60
  isNotNil: () => isNotNil,
59
61
  isNull: () => isNull,
@@ -580,6 +582,18 @@ function clamp(value, bound1, bound2) {
580
582
  return Math.min(Math.max(value, bound1), bound2);
581
583
  }
582
584
 
585
+ // src/math/inRange.ts
586
+ function inRange(value, minimum, maximum) {
587
+ if (maximum == null) {
588
+ maximum = minimum;
589
+ minimum = 0;
590
+ }
591
+ if (minimum >= maximum) {
592
+ throw new Error("The maximum value must be greater than the minimum value.");
593
+ }
594
+ return minimum <= value && value < maximum;
595
+ }
596
+
583
597
  // src/math/sum.ts
584
598
  function sum(nums) {
585
599
  let result = 0;
@@ -671,6 +685,16 @@ function pickBy(obj, shouldPick) {
671
685
  return result;
672
686
  }
673
687
 
688
+ // src/object/invert.ts
689
+ function invert(obj) {
690
+ const result = {};
691
+ for (const key in obj) {
692
+ const value = obj[key];
693
+ result[value] = key;
694
+ }
695
+ return result;
696
+ }
697
+
674
698
  // src/predicate/isNil.ts
675
699
  function isNil(x) {
676
700
  return x === null || x === void 0;
@@ -727,9 +751,11 @@ function delay(ms, { signal } = {}) {
727
751
  fill,
728
752
  forEachRight,
729
753
  groupBy,
754
+ inRange,
730
755
  intersection,
731
756
  intersectionBy,
732
757
  intersectionWith,
758
+ invert,
733
759
  isNil,
734
760
  isNotNil,
735
761
  isNull,