es-toolkit 1.7.1 → 1.8.0-dev.159

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 (64) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/array/head.d.mts +22 -0
  3. package/dist/array/head.d.ts +22 -0
  4. package/dist/array/head.js +33 -0
  5. package/dist/array/head.js.map +1 -0
  6. package/dist/array/head.mjs +8 -0
  7. package/dist/array/index.d.mts +2 -0
  8. package/dist/array/index.d.ts +2 -0
  9. package/dist/array/index.js +34 -0
  10. package/dist/array/index.js.map +1 -1
  11. package/dist/array/index.mjs +32 -24
  12. package/dist/array/orderBy.d.mts +35 -0
  13. package/dist/array/orderBy.d.ts +35 -0
  14. package/dist/array/orderBy.js +53 -0
  15. package/dist/array/orderBy.js.map +1 -0
  16. package/dist/array/orderBy.mjs +8 -0
  17. package/dist/chunk-7B7W36UP.mjs +29 -0
  18. package/dist/chunk-7B7W36UP.mjs.map +1 -0
  19. package/dist/chunk-BH6HLGBA.mjs +16 -0
  20. package/dist/chunk-BH6HLGBA.mjs.map +1 -0
  21. package/dist/chunk-FLTT2MGF.mjs +14 -0
  22. package/dist/chunk-FLTT2MGF.mjs.map +1 -0
  23. package/dist/chunk-HM2JT2RX.mjs +9 -0
  24. package/dist/chunk-HM2JT2RX.mjs.map +1 -0
  25. package/dist/chunk-O5QHO3W7.mjs +1 -0
  26. package/dist/chunk-PMHULJNL.mjs +1 -0
  27. package/dist/chunk-PMHULJNL.mjs.map +1 -0
  28. package/dist/chunk-TLVQSNOE.mjs +1 -0
  29. package/dist/chunk-TLVQSNOE.mjs.map +1 -0
  30. package/dist/index.d.mts +4 -0
  31. package/dist/index.d.ts +4 -0
  32. package/dist/index.js +60 -0
  33. package/dist/index.js.map +1 -1
  34. package/dist/index.mjs +59 -43
  35. package/dist/math/inRange.d.mts +4 -0
  36. package/dist/math/inRange.d.ts +4 -0
  37. package/dist/math/inRange.js +40 -0
  38. package/dist/math/inRange.js.map +1 -0
  39. package/dist/math/inRange.mjs +8 -0
  40. package/dist/math/inRange.mjs.map +1 -0
  41. package/dist/math/index.d.mts +1 -0
  42. package/dist/math/index.d.ts +1 -0
  43. package/dist/math/index.js +14 -0
  44. package/dist/math/index.js.map +1 -1
  45. package/dist/math/index.mjs +7 -3
  46. package/dist/object/index.d.mts +1 -0
  47. package/dist/object/index.d.ts +1 -0
  48. package/dist/object/index.js +12 -0
  49. package/dist/object/index.js.map +1 -1
  50. package/dist/object/index.mjs +5 -1
  51. package/dist/object/invert.d.mts +24 -0
  52. package/dist/object/invert.d.ts +24 -0
  53. package/dist/object/invert.js +38 -0
  54. package/dist/object/invert.js.map +1 -0
  55. package/dist/object/invert.mjs +8 -0
  56. package/dist/object/invert.mjs.map +1 -0
  57. package/dist/predicate/index.mjs +3 -3
  58. package/package.json +1 -1
  59. package/dist/chunk-T5JCRGXA.mjs +0 -1
  60. package/dist/chunk-TZE6EDCX.mjs +0 -1
  61. package/dist/chunk-XJR5WV2Z.mjs +0 -1
  62. /package/dist/{chunk-T5JCRGXA.mjs.map → array/head.mjs.map} +0 -0
  63. /package/dist/{chunk-TZE6EDCX.mjs.map → array/orderBy.mjs.map} +0 -0
  64. /package/dist/{chunk-XJR5WV2Z.mjs.map → chunk-O5QHO3W7.mjs.map} +0 -0
package/dist/index.mjs CHANGED
@@ -1,4 +1,11 @@
1
+ import "./chunk-ARZ5BDR6.mjs";
2
+ import {
3
+ delay
4
+ } from "./chunk-O64NE2P4.mjs";
1
5
  import "./chunk-MAJSPFA6.mjs";
6
+ import {
7
+ isUndefined
8
+ } from "./chunk-VH2PV426.mjs";
2
9
  import {
3
10
  isNil
4
11
  } from "./chunk-OHQAR5AU.mjs";
@@ -8,14 +15,7 @@ import {
8
15
  import {
9
16
  isNull
10
17
  } from "./chunk-AIRSKN47.mjs";
11
- import {
12
- isUndefined
13
- } from "./chunk-VH2PV426.mjs";
14
- import "./chunk-ARZ5BDR6.mjs";
15
- import {
16
- delay
17
- } from "./chunk-O64NE2P4.mjs";
18
- import "./chunk-T5JCRGXA.mjs";
18
+ import "./chunk-PMHULJNL.mjs";
19
19
  import {
20
20
  omit
21
21
  } from "./chunk-QZITBKWX.mjs";
@@ -28,7 +28,13 @@ import {
28
28
  import {
29
29
  pickBy
30
30
  } from "./chunk-6CLH5YZ2.mjs";
31
- import "./chunk-TZE6EDCX.mjs";
31
+ import {
32
+ invert
33
+ } from "./chunk-FLTT2MGF.mjs";
34
+ import "./chunk-TLVQSNOE.mjs";
35
+ import {
36
+ meanBy
37
+ } from "./chunk-SDIMTYZW.mjs";
32
38
  import {
33
39
  range
34
40
  } from "./chunk-UNLX2F2Y.mjs";
@@ -39,24 +45,36 @@ import {
39
45
  clamp
40
46
  } from "./chunk-MLCL773E.mjs";
41
47
  import {
42
- meanBy
43
- } from "./chunk-SDIMTYZW.mjs";
48
+ inRange
49
+ } from "./chunk-BH6HLGBA.mjs";
44
50
  import {
45
51
  mean
46
52
  } from "./chunk-LT6E4Y4Z.mjs";
47
53
  import {
48
54
  sum
49
55
  } from "./chunk-NOFHNJ5C.mjs";
50
- import "./chunk-XJR5WV2Z.mjs";
56
+ import "./chunk-O5QHO3W7.mjs";
57
+ import {
58
+ xorWith
59
+ } from "./chunk-QRSJBBFY.mjs";
60
+ import {
61
+ zip
62
+ } from "./chunk-IDCUZVJL.mjs";
51
63
  import {
52
64
  zipObject
53
65
  } from "./chunk-6GWEY5EL.mjs";
54
66
  import {
55
67
  zipWith
56
68
  } from "./chunk-4KYXHZ4R.mjs";
69
+ import {
70
+ unionWith
71
+ } from "./chunk-2ZCITDMK.mjs";
57
72
  import {
58
73
  uniqBy
59
74
  } from "./chunk-OXAZEEGP.mjs";
75
+ import {
76
+ uniqWith
77
+ } from "./chunk-237HGSZS.mjs";
60
78
  import {
61
79
  unzipWith
62
80
  } from "./chunk-IFNXROZR.mjs";
@@ -70,11 +88,17 @@ import {
70
88
  xorBy
71
89
  } from "./chunk-Q47NGNXT.mjs";
72
90
  import {
73
- xorWith
74
- } from "./chunk-QRSJBBFY.mjs";
91
+ sampleSize
92
+ } from "./chunk-EHSKB6DF.mjs";
75
93
  import {
76
- zip
77
- } from "./chunk-IDCUZVJL.mjs";
94
+ randomInt
95
+ } from "./chunk-GIWAOOFY.mjs";
96
+ import {
97
+ random
98
+ } from "./chunk-SYWMYQYJ.mjs";
99
+ import {
100
+ shuffle
101
+ } from "./chunk-G7UQ5PUR.mjs";
78
102
  import {
79
103
  take
80
104
  } from "./chunk-ME352XO7.mjs";
@@ -90,18 +114,15 @@ import {
90
114
  import {
91
115
  union
92
116
  } from "./chunk-R6QA7PLZ.mjs";
117
+ import {
118
+ uniq
119
+ } from "./chunk-DVK2N4KC.mjs";
93
120
  import {
94
121
  unionBy
95
122
  } from "./chunk-NFS7RWWE.mjs";
96
123
  import {
97
- unionWith
98
- } from "./chunk-2ZCITDMK.mjs";
99
- import {
100
- uniqWith
101
- } from "./chunk-237HGSZS.mjs";
102
- import {
103
- uniq
104
- } from "./chunk-DVK2N4KC.mjs";
124
+ intersectionBy
125
+ } from "./chunk-O6UXZR3U.mjs";
105
126
  import {
106
127
  intersectionWith
107
128
  } from "./chunk-XI7KRD2C.mjs";
@@ -114,24 +135,15 @@ import {
114
135
  import {
115
136
  minBy
116
137
  } from "./chunk-IJD7FE2Z.mjs";
138
+ import {
139
+ orderBy
140
+ } from "./chunk-7B7W36UP.mjs";
117
141
  import {
118
142
  partition
119
143
  } from "./chunk-DN3NOZ3H.mjs";
120
144
  import {
121
145
  sample
122
146
  } from "./chunk-2KNLZB7V.mjs";
123
- import {
124
- sampleSize
125
- } from "./chunk-EHSKB6DF.mjs";
126
- import {
127
- randomInt
128
- } from "./chunk-GIWAOOFY.mjs";
129
- import {
130
- random
131
- } from "./chunk-SYWMYQYJ.mjs";
132
- import {
133
- shuffle
134
- } from "./chunk-G7UQ5PUR.mjs";
135
147
  import {
136
148
  dropRightWhile
137
149
  } from "./chunk-JE6JKZU3.mjs";
@@ -147,12 +159,12 @@ import {
147
159
  import {
148
160
  groupBy
149
161
  } from "./chunk-E6E4RZLN.mjs";
162
+ import {
163
+ head
164
+ } from "./chunk-HM2JT2RX.mjs";
150
165
  import {
151
166
  intersection
152
167
  } from "./chunk-FVVSE2F2.mjs";
153
- import {
154
- intersectionBy
155
- } from "./chunk-O6UXZR3U.mjs";
156
168
  import {
157
169
  chunk
158
170
  } from "./chunk-E6C5EZQA.mjs";
@@ -177,6 +189,10 @@ import {
177
189
  import {
178
190
  dropRight
179
191
  } from "./chunk-JEKUA56R.mjs";
192
+ import "./chunk-FZEZH22H.mjs";
193
+ import {
194
+ AbortError
195
+ } from "./chunk-DXB7EZUQ.mjs";
180
196
  import "./chunk-N6EM6ETS.mjs";
181
197
  import {
182
198
  debounce
@@ -190,10 +206,6 @@ import {
190
206
  import {
191
207
  throttle
192
208
  } from "./chunk-QOJGMVVR.mjs";
193
- import "./chunk-FZEZH22H.mjs";
194
- import {
195
- AbortError
196
- } from "./chunk-DXB7EZUQ.mjs";
197
209
  import "./chunk-2MM5EJJX.mjs";
198
210
  export {
199
211
  AbortError,
@@ -213,9 +225,12 @@ export {
213
225
  fill,
214
226
  forEachRight,
215
227
  groupBy,
228
+ head,
229
+ inRange,
216
230
  intersection,
217
231
  intersectionBy,
218
232
  intersectionWith,
233
+ invert,
219
234
  isNil,
220
235
  isNotNil,
221
236
  isNull,
@@ -229,6 +244,7 @@ export {
229
244
  omit,
230
245
  omitBy,
231
246
  once,
247
+ orderBy,
232
248
  partition,
233
249
  pick,
234
250
  pickBy,
@@ -0,0 +1,4 @@
1
+ declare function inRange(value: number, maximum: number): boolean;
2
+ declare function inRange(value: number, minimum: number, maximum: number): boolean;
3
+
4
+ export { inRange };
@@ -0,0 +1,4 @@
1
+ declare function inRange(value: number, maximum: number): boolean;
2
+ declare function inRange(value: number, minimum: number, maximum: number): boolean;
3
+
4
+ export { inRange };
@@ -0,0 +1,40 @@
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/math/inRange.ts
21
+ var inRange_exports = {};
22
+ __export(inRange_exports, {
23
+ inRange: () => inRange
24
+ });
25
+ module.exports = __toCommonJS(inRange_exports);
26
+ function inRange(value, minimum, maximum) {
27
+ if (maximum == null) {
28
+ maximum = minimum;
29
+ minimum = 0;
30
+ }
31
+ if (minimum >= maximum) {
32
+ throw new Error("The maximum value must be greater than the minimum value.");
33
+ }
34
+ return minimum <= value && value < maximum;
35
+ }
36
+ // Annotate the CommonJS export names for ESM import in node:
37
+ 0 && (module.exports = {
38
+ inRange
39
+ });
40
+ //# sourceMappingURL=inRange.js.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":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;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,8 @@
1
+ import {
2
+ inRange
3
+ } from "../chunk-BH6HLGBA.mjs";
4
+ import "../chunk-2MM5EJJX.mjs";
5
+ export {
6
+ inRange
7
+ };
8
+ //# sourceMappingURL=inRange.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -1,4 +1,5 @@
1
1
  export { clamp } from './clamp.mjs';
2
+ export { inRange } from './inRange.mjs';
2
3
  export { mean } from './mean.mjs';
3
4
  export { meanBy } from './meanBy.mjs';
4
5
  export { random } from './random.mjs';
@@ -1,4 +1,5 @@
1
1
  export { clamp } from './clamp.js';
2
+ export { inRange } from './inRange.js';
2
3
  export { mean } from './mean.js';
3
4
  export { meanBy } from './meanBy.js';
4
5
  export { random } from './random.js';
@@ -21,6 +21,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  var math_exports = {};
22
22
  __export(math_exports, {
23
23
  clamp: () => clamp,
24
+ inRange: () => inRange,
24
25
  mean: () => mean,
25
26
  meanBy: () => meanBy,
26
27
  random: () => random,
@@ -39,6 +40,18 @@ function clamp(value, bound1, bound2) {
39
40
  return Math.min(Math.max(value, bound1), bound2);
40
41
  }
41
42
 
43
+ // src/math/inRange.ts
44
+ function inRange(value, minimum, maximum) {
45
+ if (maximum == null) {
46
+ maximum = minimum;
47
+ minimum = 0;
48
+ }
49
+ if (minimum >= maximum) {
50
+ throw new Error("The maximum value must be greater than the minimum value.");
51
+ }
52
+ return minimum <= value && value < maximum;
53
+ }
54
+
42
55
  // src/math/sum.ts
43
56
  function sum(nums) {
44
57
  let result = 0;
@@ -107,6 +120,7 @@ function range(start, end, step) {
107
120
  // Annotate the CommonJS export names for ESM import in node:
108
121
  0 && (module.exports = {
109
122
  clamp,
123
+ inRange,
110
124
  mean,
111
125
  meanBy,
112
126
  random,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/math/index.ts","../../src/math/clamp.ts","../../src/math/sum.ts","../../src/math/mean.ts","../../src/math/meanBy.ts","../../src/math/random.ts","../../src/math/randomInt.ts","../../src/math/round.ts","../../src/math/range.ts"],"sourcesContent":["export { clamp } from './clamp.ts';\nexport { mean } from './mean.ts';\nexport { meanBy } from './meanBy.ts';\nexport { random } from './random.ts';\nexport { randomInt } from './randomInt.ts';\nexport { round } from './round.ts';\nexport { sum } from './sum.ts';\nexport { range } from './range.ts';\n","/**\n * Clamps a number within the inclusive lower and upper bounds.\n *\n * This function takes a number and two bounds, and returns the number clamped within the specified bounds.\n * If only one bound is provided, it returns the minimum of the value and the bound.\n *\n * @param {number} value - The number to clamp.\n * @param {number} minimum - The minimum bound to clamp the number.\n * @param {number} maximum - The maximum bound to clamp the number.\n * @returns {number} The clamped number within the specified bounds.\n *\n * @example\n * const result1 = clamp(10, 5); // result1 will be 5, as 10 is clamped to the bound 5\n * const result2 = clamp(10, 5, 15); // result2 will be 10, as it is within the bounds 5 and 15\n * const result3 = clamp(2, 5, 15); // result3 will be 5, as 2 is clamped to the lower bound 5\n * const result4 = clamp(20, 5, 15); // result4 will be 15, as 20 is clamped to the upper bound 15\n */\nexport function clamp(value: number, maximum: number): number;\nexport function clamp(value: number, minimum: number, maximum: number): number;\nexport function clamp(value: number, bound1: number, bound2?: number): number {\n if (bound2 == null) {\n return Math.min(value, bound1);\n }\n\n return Math.min(Math.max(value, bound1), bound2);\n}\n","/**\n * Calculates the sum of an array of numbers.\n *\n * This function takes an array of numbers and returns the sum of all the elements in the array.\n *\n * @param {number[]} nums - An array of numbers to be summed.\n * @returns {number} The sum of all the numbers in the array.\n *\n * @example\n * const numbers = [1, 2, 3, 4, 5];\n * const result = sum(numbers);\n * // result will be 15\n */\nexport function sum(nums: readonly number[]): number {\n let result = 0;\n\n for (const num of nums) {\n result += num;\n }\n\n return result;\n}\n","import { sum } from './sum.ts';\n\n/**\n * Calculates the average of an array of numbers.\n *\n * If the array is empty, this function returns `NaN`.\n *\n * @param {number[]} nums - An array of numbers to calculate the average.\n * @returns {number} The average of all the numbers in the array.\n *\n * @example\n * const numbers = [1, 2, 3, 4, 5];\n * const result = average(numbers);\n * // result will be 3\n */\nexport function mean(nums: readonly number[]): number {\n return sum(nums) / nums.length;\n}\n","import { mean } from './mean.ts';\n\n/**\n * Calculates the average of an array of numbers when applying\n * the `getValue` function to each element.\n *\n * If the array is empty, this function returns `NaN`.\n *\n * @template T - The type of elements in the array.\n * @param {T[]} items An array to calculate the average.\n * @param {(element: T) => number} getValue A function that selects a numeric value from each element.\n * @returns {number} The average of all the numbers as determined by the `getValue` function.\n *\n * @example\n * meanBy([{ a: 1 }, { a: 2 }, { a: 3 }], x => x.a); // Returns: 2\n * meanBy([], x => x.a); // Returns: NaN\n */\nexport function meanBy<T>(items: readonly T[], getValue: (element: T) => number): number {\n const nums = items.map(x => getValue(x));\n\n return mean(nums);\n}\n","/**\n * Generate a random number within the given range.\n *\n * If only one argument is provided, a number between `0` and the given number is returned.\n *\n * @param {number} minimum - The lower bound (inclusive).\n * @param {number} maximum - The upper bound (exclusive).\n * @returns {number} A random number between minimum (inclusive) and maximum (exclusive). The number can be an integer or a decimal.\n * @throws {Error} Throws an error if `maximum` is not greater than `minimum`.\n *\n * @example\n * const result1 = random(0, 5); // Returns a random number between 0 and 5.\n * const result2 = random(5, 0); // If the minimum is greater than the maximum, an error is thrown\n * const result3 = random(5, 5); // If the minimum is equal to the maximum, an error is thrown.\n */\nexport function random(maximum: number): number;\nexport function random(minimum: number, maximum: number): number;\nexport function random(minimum: number, maximum?: number): number {\n if (maximum == null) {\n maximum = minimum;\n minimum = 0;\n }\n\n if (minimum >= maximum) {\n throw new Error('Invalid input: The maximum value must be greater than the minimum value.');\n }\n\n return Math.random() * (maximum - minimum) + minimum;\n}\n","import { random } from './random.ts';\n\n/**\n * Generates a random integer between minimum (inclusive) and maximum (exclusive).\n *\n * If only one argument is provided, a number between `0` and the given number is returned.\n *\n * @param {number} minimum - The lower bound (inclusive).\n * @param {number} maximum - The upper bound (exclusive).\n * @returns {number} A random integer between minimum (inclusive) and maximum (exclusive).\n * @throws {Error} Throws an error if `maximum` is not greater than `minimum`.\n *\n * @example\n * const result = randomInt(0, 5); // result will be a random integer between 0 (inclusive) and 5 (exclusive)\n * const result2 = randomInt(5, 0); // This will throw an error\n */\nexport function randomInt(maximum: number): number;\nexport function randomInt(minimum: number, maximum: number): number;\nexport function randomInt(minimum: number, maximum?: number): number {\n return Math.floor(random(minimum, maximum!));\n}\n","/**\n * Rounds a number to a specified precision.\n *\n * This function takes a number and an optional precision value, and returns the number rounded\n * to the specified number of decimal places.\n *\n * @param {number} value - The number to round.\n * @param {number} [precision=0] - The number of decimal places to round to. Defaults to 0.\n * @returns {number} The rounded number.\n * @throws {Error} Throws an error if `Precision` is not integer.\n *\n * @example\n * const result1 = round(1.2345); // result1 will be 1\n * const result2 = round(1.2345, 2); // result2 will be 1.23\n * const result3 = round(1.2345, 3); // result3 will be 1.235\n * const result4 = round(1.2345, 3.1); // This will throw an error\n */\nexport function round(value: number, precision = 0): number {\n if (!Number.isInteger(precision)) {\n throw new Error('Precision must be an integer.');\n }\n const multiplier = Math.pow(10, precision);\n return Math.round(value * multiplier) / multiplier;\n}\n","/**\n * Returns an array of numbers from `start` to `end`, incrementing by `step`.\n *\n * If `step` is not provided, it defaults to `1` for an\n * ascending range and `-1` for a descending range.\n *\n * @param {number} start - The starting number of the range.\n * @param {number} [end] - The end number of the range.\n * @param {number} [step] - The step value for the range.\n * @returns {number[]} An array of numbers from `start` to `end` with the specified `step`.\n *\n * @example\n * // Returns [0, 1, 2, 3]\n * range(4);\n *\n * @example\n * // Returns [0, 5, 10, 15]\n * range(0, 20, 5);\n *\n * @example\n * // Returns []\n * range(0, -4, -1);\n *\n * @example\n * // Throws an error: The step value must be a non-zero integer.\n * range(1, 4, 0);\n */\nexport function range(end: number): number[];\nexport function range(start: number, end: number): number[];\nexport function range(start: number, end: number, step: number): number[];\nexport function range(start: number, end?: number, step?: number): number[] {\n if (end == null) {\n end = start;\n start = 0;\n }\n\n if (step == null) {\n step = 1;\n }\n\n if (!Number.isInteger(step) || step === 0) {\n throw new Error(`The step value must be a non-zero integer.`);\n }\n\n const length = Math.max(Math.ceil((end - start) / step), 0);\n const result = new Array(length);\n\n for (let i = 0; i < length; i++) {\n result[i] = start + i * step;\n }\n\n return result;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACmBO,SAAS,MAAM,OAAe,QAAgB,QAAyB;AAC5E,MAAI,UAAU,MAAM;AAClB,WAAO,KAAK,IAAI,OAAO,MAAM;AAAA,EAC/B;AAEA,SAAO,KAAK,IAAI,KAAK,IAAI,OAAO,MAAM,GAAG,MAAM;AACjD;;;ACZO,SAAS,IAAI,MAAiC;AACnD,MAAI,SAAS;AAEb,aAAW,OAAO,MAAM;AACtB,cAAU;AAAA,EACZ;AAEA,SAAO;AACT;;;ACNO,SAAS,KAAK,MAAiC;AACpD,SAAO,IAAI,IAAI,IAAI,KAAK;AAC1B;;;ACAO,SAAS,OAAU,OAAqB,UAA0C;AACvF,QAAM,OAAO,MAAM,IAAI,OAAK,SAAS,CAAC,CAAC;AAEvC,SAAO,KAAK,IAAI;AAClB;;;ACJO,SAAS,OAAO,SAAiB,SAA0B;AAChE,MAAI,WAAW,MAAM;AACnB,cAAU;AACV,cAAU;AAAA,EACZ;AAEA,MAAI,WAAW,SAAS;AACtB,UAAM,IAAI,MAAM,0EAA0E;AAAA,EAC5F;AAEA,SAAO,KAAK,OAAO,KAAK,UAAU,WAAW;AAC/C;;;ACVO,SAAS,UAAU,SAAiB,SAA0B;AACnE,SAAO,KAAK,MAAM,OAAO,SAAS,OAAQ,CAAC;AAC7C;;;ACHO,SAAS,MAAM,OAAe,YAAY,GAAW;AAC1D,MAAI,CAAC,OAAO,UAAU,SAAS,GAAG;AAChC,UAAM,IAAI,MAAM,+BAA+B;AAAA,EACjD;AACA,QAAM,aAAa,KAAK,IAAI,IAAI,SAAS;AACzC,SAAO,KAAK,MAAM,QAAQ,UAAU,IAAI;AAC1C;;;ACOO,SAAS,MAAM,OAAe,KAAc,MAAyB;AAC1E,MAAI,OAAO,MAAM;AACf,UAAM;AACN,YAAQ;AAAA,EACV;AAEA,MAAI,QAAQ,MAAM;AAChB,WAAO;AAAA,EACT;AAEA,MAAI,CAAC,OAAO,UAAU,IAAI,KAAK,SAAS,GAAG;AACzC,UAAM,IAAI,MAAM,4CAA4C;AAAA,EAC9D;AAEA,QAAM,SAAS,KAAK,IAAI,KAAK,MAAM,MAAM,SAAS,IAAI,GAAG,CAAC;AAC1D,QAAM,SAAS,IAAI,MAAM,MAAM;AAE/B,WAAS,IAAI,GAAG,IAAI,QAAQ,KAAK;AAC/B,WAAO,CAAC,IAAI,QAAQ,IAAI;AAAA,EAC1B;AAEA,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../../src/math/index.ts","../../src/math/clamp.ts","../../src/math/inRange.ts","../../src/math/sum.ts","../../src/math/mean.ts","../../src/math/meanBy.ts","../../src/math/random.ts","../../src/math/randomInt.ts","../../src/math/round.ts","../../src/math/range.ts"],"sourcesContent":["export { clamp } from './clamp.ts';\nexport { inRange } from './inRange.ts';\nexport { mean } from './mean.ts';\nexport { meanBy } from './meanBy.ts';\nexport { random } from './random.ts';\nexport { randomInt } from './randomInt.ts';\nexport { round } from './round.ts';\nexport { sum } from './sum.ts';\nexport { range } from './range.ts';\n","/**\n * Clamps a number within the inclusive lower and upper bounds.\n *\n * This function takes a number and two bounds, and returns the number clamped within the specified bounds.\n * If only one bound is provided, it returns the minimum of the value and the bound.\n *\n * @param {number} value - The number to clamp.\n * @param {number} minimum - The minimum bound to clamp the number.\n * @param {number} maximum - The maximum bound to clamp the number.\n * @returns {number} The clamped number within the specified bounds.\n *\n * @example\n * const result1 = clamp(10, 5); // result1 will be 5, as 10 is clamped to the bound 5\n * const result2 = clamp(10, 5, 15); // result2 will be 10, as it is within the bounds 5 and 15\n * const result3 = clamp(2, 5, 15); // result3 will be 5, as 2 is clamped to the lower bound 5\n * const result4 = clamp(20, 5, 15); // result4 will be 15, as 20 is clamped to the upper bound 15\n */\nexport function clamp(value: number, maximum: number): number;\nexport function clamp(value: number, minimum: number, maximum: number): number;\nexport function clamp(value: number, bound1: number, bound2?: number): number {\n if (bound2 == null) {\n return Math.min(value, bound1);\n }\n\n return Math.min(Math.max(value, bound1), bound2);\n}\n","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","/**\n * Calculates the sum of an array of numbers.\n *\n * This function takes an array of numbers and returns the sum of all the elements in the array.\n *\n * @param {number[]} nums - An array of numbers to be summed.\n * @returns {number} The sum of all the numbers in the array.\n *\n * @example\n * const numbers = [1, 2, 3, 4, 5];\n * const result = sum(numbers);\n * // result will be 15\n */\nexport function sum(nums: readonly number[]): number {\n let result = 0;\n\n for (const num of nums) {\n result += num;\n }\n\n return result;\n}\n","import { sum } from './sum.ts';\n\n/**\n * Calculates the average of an array of numbers.\n *\n * If the array is empty, this function returns `NaN`.\n *\n * @param {number[]} nums - An array of numbers to calculate the average.\n * @returns {number} The average of all the numbers in the array.\n *\n * @example\n * const numbers = [1, 2, 3, 4, 5];\n * const result = average(numbers);\n * // result will be 3\n */\nexport function mean(nums: readonly number[]): number {\n return sum(nums) / nums.length;\n}\n","import { mean } from './mean.ts';\n\n/**\n * Calculates the average of an array of numbers when applying\n * the `getValue` function to each element.\n *\n * If the array is empty, this function returns `NaN`.\n *\n * @template T - The type of elements in the array.\n * @param {T[]} items An array to calculate the average.\n * @param {(element: T) => number} getValue A function that selects a numeric value from each element.\n * @returns {number} The average of all the numbers as determined by the `getValue` function.\n *\n * @example\n * meanBy([{ a: 1 }, { a: 2 }, { a: 3 }], x => x.a); // Returns: 2\n * meanBy([], x => x.a); // Returns: NaN\n */\nexport function meanBy<T>(items: readonly T[], getValue: (element: T) => number): number {\n const nums = items.map(x => getValue(x));\n\n return mean(nums);\n}\n","/**\n * Generate a random number within the given range.\n *\n * If only one argument is provided, a number between `0` and the given number is returned.\n *\n * @param {number} minimum - The lower bound (inclusive).\n * @param {number} maximum - The upper bound (exclusive).\n * @returns {number} A random number between minimum (inclusive) and maximum (exclusive). The number can be an integer or a decimal.\n * @throws {Error} Throws an error if `maximum` is not greater than `minimum`.\n *\n * @example\n * const result1 = random(0, 5); // Returns a random number between 0 and 5.\n * const result2 = random(5, 0); // If the minimum is greater than the maximum, an error is thrown\n * const result3 = random(5, 5); // If the minimum is equal to the maximum, an error is thrown.\n */\nexport function random(maximum: number): number;\nexport function random(minimum: number, maximum: number): number;\nexport function random(minimum: number, maximum?: number): number {\n if (maximum == null) {\n maximum = minimum;\n minimum = 0;\n }\n\n if (minimum >= maximum) {\n throw new Error('Invalid input: The maximum value must be greater than the minimum value.');\n }\n\n return Math.random() * (maximum - minimum) + minimum;\n}\n","import { random } from './random.ts';\n\n/**\n * Generates a random integer between minimum (inclusive) and maximum (exclusive).\n *\n * If only one argument is provided, a number between `0` and the given number is returned.\n *\n * @param {number} minimum - The lower bound (inclusive).\n * @param {number} maximum - The upper bound (exclusive).\n * @returns {number} A random integer between minimum (inclusive) and maximum (exclusive).\n * @throws {Error} Throws an error if `maximum` is not greater than `minimum`.\n *\n * @example\n * const result = randomInt(0, 5); // result will be a random integer between 0 (inclusive) and 5 (exclusive)\n * const result2 = randomInt(5, 0); // This will throw an error\n */\nexport function randomInt(maximum: number): number;\nexport function randomInt(minimum: number, maximum: number): number;\nexport function randomInt(minimum: number, maximum?: number): number {\n return Math.floor(random(minimum, maximum!));\n}\n","/**\n * Rounds a number to a specified precision.\n *\n * This function takes a number and an optional precision value, and returns the number rounded\n * to the specified number of decimal places.\n *\n * @param {number} value - The number to round.\n * @param {number} [precision=0] - The number of decimal places to round to. Defaults to 0.\n * @returns {number} The rounded number.\n * @throws {Error} Throws an error if `Precision` is not integer.\n *\n * @example\n * const result1 = round(1.2345); // result1 will be 1\n * const result2 = round(1.2345, 2); // result2 will be 1.23\n * const result3 = round(1.2345, 3); // result3 will be 1.235\n * const result4 = round(1.2345, 3.1); // This will throw an error\n */\nexport function round(value: number, precision = 0): number {\n if (!Number.isInteger(precision)) {\n throw new Error('Precision must be an integer.');\n }\n const multiplier = Math.pow(10, precision);\n return Math.round(value * multiplier) / multiplier;\n}\n","/**\n * Returns an array of numbers from `start` to `end`, incrementing by `step`.\n *\n * If `step` is not provided, it defaults to `1` for an\n * ascending range and `-1` for a descending range.\n *\n * @param {number} start - The starting number of the range.\n * @param {number} [end] - The end number of the range.\n * @param {number} [step] - The step value for the range.\n * @returns {number[]} An array of numbers from `start` to `end` with the specified `step`.\n *\n * @example\n * // Returns [0, 1, 2, 3]\n * range(4);\n *\n * @example\n * // Returns [0, 5, 10, 15]\n * range(0, 20, 5);\n *\n * @example\n * // Returns []\n * range(0, -4, -1);\n *\n * @example\n * // Throws an error: The step value must be a non-zero integer.\n * range(1, 4, 0);\n */\nexport function range(end: number): number[];\nexport function range(start: number, end: number): number[];\nexport function range(start: number, end: number, step: number): number[];\nexport function range(start: number, end?: number, step?: number): number[] {\n if (end == null) {\n end = start;\n start = 0;\n }\n\n if (step == null) {\n step = 1;\n }\n\n if (!Number.isInteger(step) || step === 0) {\n throw new Error(`The step value must be a non-zero integer.`);\n }\n\n const length = Math.max(Math.ceil((end - start) / step), 0);\n const result = new Array(length);\n\n for (let i = 0; i < length; i++) {\n result[i] = start + i * step;\n }\n\n return result;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACmBO,SAAS,MAAM,OAAe,QAAgB,QAAyB;AAC5E,MAAI,UAAU,MAAM;AAClB,WAAO,KAAK,IAAI,OAAO,MAAM;AAAA,EAC/B;AAEA,SAAO,KAAK,IAAI,KAAK,IAAI,OAAO,MAAM,GAAG,MAAM;AACjD;;;ACTO,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;;;ACdO,SAAS,IAAI,MAAiC;AACnD,MAAI,SAAS;AAEb,aAAW,OAAO,MAAM;AACtB,cAAU;AAAA,EACZ;AAEA,SAAO;AACT;;;ACNO,SAAS,KAAK,MAAiC;AACpD,SAAO,IAAI,IAAI,IAAI,KAAK;AAC1B;;;ACAO,SAAS,OAAU,OAAqB,UAA0C;AACvF,QAAM,OAAO,MAAM,IAAI,OAAK,SAAS,CAAC,CAAC;AAEvC,SAAO,KAAK,IAAI;AAClB;;;ACJO,SAAS,OAAO,SAAiB,SAA0B;AAChE,MAAI,WAAW,MAAM;AACnB,cAAU;AACV,cAAU;AAAA,EACZ;AAEA,MAAI,WAAW,SAAS;AACtB,UAAM,IAAI,MAAM,0EAA0E;AAAA,EAC5F;AAEA,SAAO,KAAK,OAAO,KAAK,UAAU,WAAW;AAC/C;;;ACVO,SAAS,UAAU,SAAiB,SAA0B;AACnE,SAAO,KAAK,MAAM,OAAO,SAAS,OAAQ,CAAC;AAC7C;;;ACHO,SAAS,MAAM,OAAe,YAAY,GAAW;AAC1D,MAAI,CAAC,OAAO,UAAU,SAAS,GAAG;AAChC,UAAM,IAAI,MAAM,+BAA+B;AAAA,EACjD;AACA,QAAM,aAAa,KAAK,IAAI,IAAI,SAAS;AACzC,SAAO,KAAK,MAAM,QAAQ,UAAU,IAAI;AAC1C;;;ACOO,SAAS,MAAM,OAAe,KAAc,MAAyB;AAC1E,MAAI,OAAO,MAAM;AACf,UAAM;AACN,YAAQ;AAAA,EACV;AAEA,MAAI,QAAQ,MAAM;AAChB,WAAO;AAAA,EACT;AAEA,MAAI,CAAC,OAAO,UAAU,IAAI,KAAK,SAAS,GAAG;AACzC,UAAM,IAAI,MAAM,4CAA4C;AAAA,EAC9D;AAEA,QAAM,SAAS,KAAK,IAAI,KAAK,MAAM,MAAM,SAAS,IAAI,GAAG,CAAC;AAC1D,QAAM,SAAS,IAAI,MAAM,MAAM;AAE/B,WAAS,IAAI,GAAG,IAAI,QAAQ,KAAK;AAC/B,WAAO,CAAC,IAAI,QAAQ,IAAI;AAAA,EAC1B;AAEA,SAAO;AACT;","names":[]}
@@ -1,4 +1,7 @@
1
- import "../chunk-TZE6EDCX.mjs";
1
+ import "../chunk-TLVQSNOE.mjs";
2
+ import {
3
+ meanBy
4
+ } from "../chunk-SDIMTYZW.mjs";
2
5
  import {
3
6
  range
4
7
  } from "../chunk-UNLX2F2Y.mjs";
@@ -9,8 +12,8 @@ import {
9
12
  clamp
10
13
  } from "../chunk-MLCL773E.mjs";
11
14
  import {
12
- meanBy
13
- } from "../chunk-SDIMTYZW.mjs";
15
+ inRange
16
+ } from "../chunk-BH6HLGBA.mjs";
14
17
  import {
15
18
  mean
16
19
  } from "../chunk-LT6E4Y4Z.mjs";
@@ -26,6 +29,7 @@ import {
26
29
  import "../chunk-2MM5EJJX.mjs";
27
30
  export {
28
31
  clamp,
32
+ inRange,
29
33
  mean,
30
34
  meanBy,
31
35
  random,
@@ -2,3 +2,4 @@ export { omit } from './omit.mjs';
2
2
  export { omitBy } from './omitBy.mjs';
3
3
  export { pick } from './pick.mjs';
4
4
  export { pickBy } from './pickBy.mjs';
5
+ export { invert } from './invert.mjs';
@@ -2,3 +2,4 @@ export { omit } from './omit.js';
2
2
  export { omitBy } from './omitBy.js';
3
3
  export { pick } from './pick.js';
4
4
  export { pickBy } from './pickBy.js';
5
+ export { invert } from './invert.js';
@@ -34,6 +34,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
34
34
  // src/object/index.ts
35
35
  var object_exports = {};
36
36
  __export(object_exports, {
37
+ invert: () => invert,
37
38
  omit: () => omit,
38
39
  omitBy: () => omitBy,
39
40
  pick: () => pick,
@@ -82,8 +83,19 @@ function pickBy(obj, shouldPick) {
82
83
  }
83
84
  return result;
84
85
  }
86
+
87
+ // src/object/invert.ts
88
+ function invert(obj) {
89
+ const result = {};
90
+ for (const key in obj) {
91
+ const value = obj[key];
92
+ result[value] = key;
93
+ }
94
+ return result;
95
+ }
85
96
  // Annotate the CommonJS export names for ESM import in node:
86
97
  0 && (module.exports = {
98
+ invert,
87
99
  omit,
88
100
  omitBy,
89
101
  pick,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/object/index.ts","../../src/object/omit.ts","../../src/object/omitBy.ts","../../src/object/pick.ts","../../src/object/pickBy.ts"],"sourcesContent":["export { omit } from './omit.ts';\nexport { omitBy } from './omitBy.ts';\nexport { pick } from './pick.ts';\nexport { pickBy } from './pickBy.ts';\n","/**\n * Creates a new object with specified keys omitted.\n *\n * This function takes an object and an array of keys, and returns a new object that\n * excludes the properties corresponding to the specified keys.\n *\n * @template T - The type of object.\n * @template K - The type of keys in object.\n * @param {T} obj - The object to omit keys from.\n * @param {K[]} keys - An array of keys to be omitted from the object.\n * @returns {Omit<T, K>} A new object with the specified keys omitted.\n *\n * @example\n * const obj = { a: 1, b: 2, c: 3 };\n * const result = omit(obj, ['b', 'c']);\n * // result will be { a: 1 }\n */\nexport function omit<T extends Record<string, any>, K extends keyof T>(obj: T, keys: K[]): Omit<T, K> {\n const result = { ...obj };\n\n for (const key of keys) {\n delete result[key];\n }\n\n return result as Omit<T, K>;\n}\n","/**\n * Creates a new object composed of the properties that do not satisfy the predicate function.\n *\n * This function takes an object and a predicate function, and returns a new object that\n * includes only the properties for which the predicate function returns false.\n *\n * @template T - The type of object.\n * @param {T} obj - The object to omit properties from.\n * @param {(value: T[string], key: keyof T) => boolean} shouldOmit - A predicate function that determines\n * whether a property should be omitted. It takes the property's key and value as arguments and returns `true`\n * if the property should be omitted, and `false` otherwise.\n * @returns {Partial<T>} A new object with the properties that do not satisfy the predicate function.\n *\n * @example\n * const obj = { a: 1, b: 'omit', c: 3 };\n * const shouldOmit = (key, value) => typeof value === 'string';\n * const result = omitBy(obj, shouldOmit);\n * // result will be { a: 1, c: 3 }\n */\nexport function omitBy<T extends Record<string, any>>(\n obj: T,\n shouldOmit: (value: T[keyof T], key: keyof T) => boolean\n): Partial<T> {\n const result: Partial<T> = {};\n\n for (const [key, value] of Object.entries(obj)) {\n if (shouldOmit(value, key)) {\n continue;\n }\n\n (result as any)[key] = value;\n }\n\n return result;\n}\n","/**\n * Creates a new object composed of the picked object properties.\n *\n * This function takes an object and an array of keys, and returns a new object that\n * includes only the properties corresponding to the specified keys.\n *\n * @template T - The type of object.\n * @template K - The type of keys in object.\n * @param {T} obj - The object to pick keys from.\n * @param {K[]} keys - An array of keys to be picked from the object.\n * @returns {Pick<T, K>} A new object with the specified keys picked.\n *\n * @example\n * const obj = { a: 1, b: 2, c: 3 };\n * const result = pick(obj, ['a', 'c']);\n * // result will be { a: 1, c: 3 }\n */\nexport function pick<T extends Record<string, any>, K extends keyof T>(obj: T, keys: K[]): Pick<T, K> {\n const result = {} as Pick<T, K>;\n\n for (const key of keys) {\n result[key] = obj[key];\n }\n\n return result;\n}\n","/**\n * Creates a new object composed of the properties that satisfy the predicate function.\n *\n * This function takes an object and a predicate function, and returns a new object that\n * includes only the properties for which the predicate function returns true.\n *\n * @template T - The type of object.\n * @param {T} obj - The object to pick properties from.\n * @param {(value: T[keyof T], key: keyof T) => boolean} shouldPick - A predicate function that determines\n * whether a property should be picked. It takes the property's key and value as arguments and returns `true`\n * if the property should be picked, and `false` otherwise.\n * @returns {Partial<T>} A new object with the properties that satisfy the predicate function.\n *\n * @example\n * const obj = { a: 1, b: 'pick', c: 3 };\n * const shouldPick = (value) => typeof value === 'string';\n * const result = pickBy(obj, shouldPick);\n * // result will be { b: 'pick' }\n */\nexport function pickBy<T extends Record<string, any>>(\n obj: T,\n shouldPick: (value: T[keyof T], key: keyof T) => boolean\n): Partial<T> {\n const result: Partial<T> = {};\n\n for (const [key, value] of Object.entries(obj)) {\n if (!shouldPick(value, key)) {\n continue;\n }\n\n (result as any)[key] = value;\n }\n\n return result;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACiBO,SAAS,KAAuD,KAAQ,MAAuB;AACpG,QAAM,SAAS,mBAAK;AAEpB,aAAW,OAAO,MAAM;AACtB,WAAO,OAAO,GAAG;AAAA,EACnB;AAEA,SAAO;AACT;;;ACNO,SAAS,OACd,KACA,YACY;AACZ,QAAM,SAAqB,CAAC;AAE5B,aAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,GAAG,GAAG;AAC9C,QAAI,WAAW,OAAO,GAAG,GAAG;AAC1B;AAAA,IACF;AAEA,IAAC,OAAe,GAAG,IAAI;AAAA,EACzB;AAEA,SAAO;AACT;;;ACjBO,SAAS,KAAuD,KAAQ,MAAuB;AACpG,QAAM,SAAS,CAAC;AAEhB,aAAW,OAAO,MAAM;AACtB,WAAO,GAAG,IAAI,IAAI,GAAG;AAAA,EACvB;AAEA,SAAO;AACT;;;ACNO,SAAS,OACd,KACA,YACY;AACZ,QAAM,SAAqB,CAAC;AAE5B,aAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,GAAG,GAAG;AAC9C,QAAI,CAAC,WAAW,OAAO,GAAG,GAAG;AAC3B;AAAA,IACF;AAEA,IAAC,OAAe,GAAG,IAAI;AAAA,EACzB;AAEA,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../../src/object/index.ts","../../src/object/omit.ts","../../src/object/omitBy.ts","../../src/object/pick.ts","../../src/object/pickBy.ts","../../src/object/invert.ts"],"sourcesContent":["export { omit } from './omit.ts';\nexport { omitBy } from './omitBy.ts';\nexport { pick } from './pick.ts';\nexport { pickBy } from './pickBy.ts';\nexport { invert } from './invert.ts';\n","/**\n * Creates a new object with specified keys omitted.\n *\n * This function takes an object and an array of keys, and returns a new object that\n * excludes the properties corresponding to the specified keys.\n *\n * @template T - The type of object.\n * @template K - The type of keys in object.\n * @param {T} obj - The object to omit keys from.\n * @param {K[]} keys - An array of keys to be omitted from the object.\n * @returns {Omit<T, K>} A new object with the specified keys omitted.\n *\n * @example\n * const obj = { a: 1, b: 2, c: 3 };\n * const result = omit(obj, ['b', 'c']);\n * // result will be { a: 1 }\n */\nexport function omit<T extends Record<string, any>, K extends keyof T>(obj: T, keys: K[]): Omit<T, K> {\n const result = { ...obj };\n\n for (const key of keys) {\n delete result[key];\n }\n\n return result as Omit<T, K>;\n}\n","/**\n * Creates a new object composed of the properties that do not satisfy the predicate function.\n *\n * This function takes an object and a predicate function, and returns a new object that\n * includes only the properties for which the predicate function returns false.\n *\n * @template T - The type of object.\n * @param {T} obj - The object to omit properties from.\n * @param {(value: T[string], key: keyof T) => boolean} shouldOmit - A predicate function that determines\n * whether a property should be omitted. It takes the property's key and value as arguments and returns `true`\n * if the property should be omitted, and `false` otherwise.\n * @returns {Partial<T>} A new object with the properties that do not satisfy the predicate function.\n *\n * @example\n * const obj = { a: 1, b: 'omit', c: 3 };\n * const shouldOmit = (key, value) => typeof value === 'string';\n * const result = omitBy(obj, shouldOmit);\n * // result will be { a: 1, c: 3 }\n */\nexport function omitBy<T extends Record<string, any>>(\n obj: T,\n shouldOmit: (value: T[keyof T], key: keyof T) => boolean\n): Partial<T> {\n const result: Partial<T> = {};\n\n for (const [key, value] of Object.entries(obj)) {\n if (shouldOmit(value, key)) {\n continue;\n }\n\n (result as any)[key] = value;\n }\n\n return result;\n}\n","/**\n * Creates a new object composed of the picked object properties.\n *\n * This function takes an object and an array of keys, and returns a new object that\n * includes only the properties corresponding to the specified keys.\n *\n * @template T - The type of object.\n * @template K - The type of keys in object.\n * @param {T} obj - The object to pick keys from.\n * @param {K[]} keys - An array of keys to be picked from the object.\n * @returns {Pick<T, K>} A new object with the specified keys picked.\n *\n * @example\n * const obj = { a: 1, b: 2, c: 3 };\n * const result = pick(obj, ['a', 'c']);\n * // result will be { a: 1, c: 3 }\n */\nexport function pick<T extends Record<string, any>, K extends keyof T>(obj: T, keys: K[]): Pick<T, K> {\n const result = {} as Pick<T, K>;\n\n for (const key of keys) {\n result[key] = obj[key];\n }\n\n return result;\n}\n","/**\n * Creates a new object composed of the properties that satisfy the predicate function.\n *\n * This function takes an object and a predicate function, and returns a new object that\n * includes only the properties for which the predicate function returns true.\n *\n * @template T - The type of object.\n * @param {T} obj - The object to pick properties from.\n * @param {(value: T[keyof T], key: keyof T) => boolean} shouldPick - A predicate function that determines\n * whether a property should be picked. It takes the property's key and value as arguments and returns `true`\n * if the property should be picked, and `false` otherwise.\n * @returns {Partial<T>} A new object with the properties that satisfy the predicate function.\n *\n * @example\n * const obj = { a: 1, b: 'pick', c: 3 };\n * const shouldPick = (value) => typeof value === 'string';\n * const result = pickBy(obj, shouldPick);\n * // result will be { b: 'pick' }\n */\nexport function pickBy<T extends Record<string, any>>(\n obj: T,\n shouldPick: (value: T[keyof T], key: keyof T) => boolean\n): Partial<T> {\n const result: Partial<T> = {};\n\n for (const [key, value] of Object.entries(obj)) {\n if (!shouldPick(value, key)) {\n continue;\n }\n\n (result as any)[key] = value;\n }\n\n return result;\n}\n","/**\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACiBO,SAAS,KAAuD,KAAQ,MAAuB;AACpG,QAAM,SAAS,mBAAK;AAEpB,aAAW,OAAO,MAAM;AACtB,WAAO,OAAO,GAAG;AAAA,EACnB;AAEA,SAAO;AACT;;;ACNO,SAAS,OACd,KACA,YACY;AACZ,QAAM,SAAqB,CAAC;AAE5B,aAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,GAAG,GAAG;AAC9C,QAAI,WAAW,OAAO,GAAG,GAAG;AAC1B;AAAA,IACF;AAEA,IAAC,OAAe,GAAG,IAAI;AAAA,EACzB;AAEA,SAAO;AACT;;;ACjBO,SAAS,KAAuD,KAAQ,MAAuB;AACpG,QAAM,SAAS,CAAC;AAEhB,aAAW,OAAO,MAAM;AACtB,WAAO,GAAG,IAAI,IAAI,GAAG;AAAA,EACvB;AAEA,SAAO;AACT;;;ACNO,SAAS,OACd,KACA,YACY;AACZ,QAAM,SAAqB,CAAC;AAE5B,aAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,GAAG,GAAG;AAC9C,QAAI,CAAC,WAAW,OAAO,GAAG,GAAG;AAC3B;AAAA,IACF;AAEA,IAAC,OAAe,GAAG,IAAI;AAAA,EACzB;AAEA,SAAO;AACT;;;ACbO,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":[]}
@@ -1,4 +1,4 @@
1
- import "../chunk-T5JCRGXA.mjs";
1
+ import "../chunk-PMHULJNL.mjs";
2
2
  import {
3
3
  omit
4
4
  } from "../chunk-QZITBKWX.mjs";
@@ -11,8 +11,12 @@ import {
11
11
  import {
12
12
  pickBy
13
13
  } from "../chunk-6CLH5YZ2.mjs";
14
+ import {
15
+ invert
16
+ } from "../chunk-FLTT2MGF.mjs";
14
17
  import "../chunk-2MM5EJJX.mjs";
15
18
  export {
19
+ invert,
16
20
  omit,
17
21
  omitBy,
18
22
  pick,
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Inverts the keys and values of an object. The keys of the input object become the values of the output object and vice versa.
3
+ *
4
+ * This function takes an object and creates a new object by inverting its keys and values. If the input object has duplicate values,
5
+ * 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
6
+ * of the input object's key-value pairs.
7
+ *
8
+ * @template K - Type of the keys in the input object (string, number, symbol)
9
+ * @template V - Type of the values in the input object (string, number, symbol)
10
+ * @param {Record<K, V>} obj - The input object whose keys and values are to be inverted
11
+ * @returns {{ [key in V]: K }} - A new object with keys and values inverted
12
+ *
13
+ * @example
14
+ * invert({ a: 1, b: 2, c: 3 }); // { 1: 'a', 2: 'b', 3: 'c' }
15
+ * invert({ 1: 'a', 2: 'b', 3: 'c' }); // { a: '1', b: '2', c: '3' }
16
+ * invert({ a: 1, 2: 'b', c: 3, 4: 'd' }); // { 1: 'a', b: '2', 3: 'c', d: '4' }
17
+ * invert({ a: Symbol('sym1'), b: Symbol('sym2') }); // { [Symbol('sym1')]: 'a', [Symbol('sym2')]: 'b' }
18
+ */
19
+ type PropertyKey = string | number | symbol;
20
+ declare function invert<K extends PropertyKey, V extends PropertyKey>(obj: Record<K, V>): {
21
+ [key in V]: K;
22
+ };
23
+
24
+ export { invert };
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Inverts the keys and values of an object. The keys of the input object become the values of the output object and vice versa.
3
+ *
4
+ * This function takes an object and creates a new object by inverting its keys and values. If the input object has duplicate values,
5
+ * 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
6
+ * of the input object's key-value pairs.
7
+ *
8
+ * @template K - Type of the keys in the input object (string, number, symbol)
9
+ * @template V - Type of the values in the input object (string, number, symbol)
10
+ * @param {Record<K, V>} obj - The input object whose keys and values are to be inverted
11
+ * @returns {{ [key in V]: K }} - A new object with keys and values inverted
12
+ *
13
+ * @example
14
+ * invert({ a: 1, b: 2, c: 3 }); // { 1: 'a', 2: 'b', 3: 'c' }
15
+ * invert({ 1: 'a', 2: 'b', 3: 'c' }); // { a: '1', b: '2', c: '3' }
16
+ * invert({ a: 1, 2: 'b', c: 3, 4: 'd' }); // { 1: 'a', b: '2', 3: 'c', d: '4' }
17
+ * invert({ a: Symbol('sym1'), b: Symbol('sym2') }); // { [Symbol('sym1')]: 'a', [Symbol('sym2')]: 'b' }
18
+ */
19
+ type PropertyKey = string | number | symbol;
20
+ declare function invert<K extends PropertyKey, V extends PropertyKey>(obj: Record<K, V>): {
21
+ [key in V]: K;
22
+ };
23
+
24
+ export { invert };
@@ -0,0 +1,38 @@
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/object/invert.ts
21
+ var invert_exports = {};
22
+ __export(invert_exports, {
23
+ invert: () => invert
24
+ });
25
+ module.exports = __toCommonJS(invert_exports);
26
+ function invert(obj) {
27
+ const result = {};
28
+ for (const key in obj) {
29
+ const value = obj[key];
30
+ result[value] = key;
31
+ }
32
+ return result;
33
+ }
34
+ // Annotate the CommonJS export names for ESM import in node:
35
+ 0 && (module.exports = {
36
+ invert
37
+ });
38
+ //# sourceMappingURL=invert.js.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":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;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,8 @@
1
+ import {
2
+ invert
3
+ } from "../chunk-FLTT2MGF.mjs";
4
+ import "../chunk-2MM5EJJX.mjs";
5
+ export {
6
+ invert
7
+ };
8
+ //# sourceMappingURL=invert.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -1,4 +1,7 @@
1
1
  import "../chunk-MAJSPFA6.mjs";
2
+ import {
3
+ isUndefined
4
+ } from "../chunk-VH2PV426.mjs";
2
5
  import {
3
6
  isNil
4
7
  } from "../chunk-OHQAR5AU.mjs";
@@ -8,9 +11,6 @@ import {
8
11
  import {
9
12
  isNull
10
13
  } from "../chunk-AIRSKN47.mjs";
11
- import {
12
- isUndefined
13
- } from "../chunk-VH2PV426.mjs";
14
14
  import "../chunk-2MM5EJJX.mjs";
15
15
  export {
16
16
  isNil,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "es-toolkit",
3
3
  "description": "A state-of-the-art, high-performance JavaScript utility library with a small bundle size and strong type annotations.",
4
- "version": "1.7.1",
4
+ "version": "1.8.0-dev.159+618f8ac0",
5
5
  "homepage": "https://es-toolkit.slash.page",
6
6
  "bugs": "https://github.com/toss/es-toolkit/issues",
7
7
  "repository": {
@@ -1 +0,0 @@
1
- //# sourceMappingURL=chunk-T5JCRGXA.mjs.map
@@ -1 +0,0 @@
1
- //# sourceMappingURL=chunk-TZE6EDCX.mjs.map
@@ -1 +0,0 @@
1
- //# sourceMappingURL=chunk-XJR5WV2Z.mjs.map