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
@@ -1,13 +1,25 @@
1
- import "../chunk-XJR5WV2Z.mjs";
1
+ import "../chunk-O5QHO3W7.mjs";
2
+ import {
3
+ xorWith
4
+ } from "../chunk-QRSJBBFY.mjs";
5
+ import {
6
+ zip
7
+ } from "../chunk-IDCUZVJL.mjs";
2
8
  import {
3
9
  zipObject
4
10
  } from "../chunk-6GWEY5EL.mjs";
5
11
  import {
6
12
  zipWith
7
13
  } from "../chunk-4KYXHZ4R.mjs";
14
+ import {
15
+ unionWith
16
+ } from "../chunk-2ZCITDMK.mjs";
8
17
  import {
9
18
  uniqBy
10
19
  } from "../chunk-OXAZEEGP.mjs";
20
+ import {
21
+ uniqWith
22
+ } from "../chunk-237HGSZS.mjs";
11
23
  import {
12
24
  unzipWith
13
25
  } from "../chunk-IFNXROZR.mjs";
@@ -21,11 +33,13 @@ import {
21
33
  xorBy
22
34
  } from "../chunk-Q47NGNXT.mjs";
23
35
  import {
24
- xorWith
25
- } from "../chunk-QRSJBBFY.mjs";
36
+ sampleSize
37
+ } from "../chunk-EHSKB6DF.mjs";
38
+ import "../chunk-GIWAOOFY.mjs";
39
+ import "../chunk-SYWMYQYJ.mjs";
26
40
  import {
27
- zip
28
- } from "../chunk-IDCUZVJL.mjs";
41
+ shuffle
42
+ } from "../chunk-G7UQ5PUR.mjs";
29
43
  import {
30
44
  take
31
45
  } from "../chunk-ME352XO7.mjs";
@@ -41,18 +55,15 @@ import {
41
55
  import {
42
56
  union
43
57
  } from "../chunk-R6QA7PLZ.mjs";
58
+ import {
59
+ uniq
60
+ } from "../chunk-DVK2N4KC.mjs";
44
61
  import {
45
62
  unionBy
46
63
  } from "../chunk-NFS7RWWE.mjs";
47
64
  import {
48
- unionWith
49
- } from "../chunk-2ZCITDMK.mjs";
50
- import {
51
- uniqWith
52
- } from "../chunk-237HGSZS.mjs";
53
- import {
54
- uniq
55
- } from "../chunk-DVK2N4KC.mjs";
65
+ intersectionBy
66
+ } from "../chunk-O6UXZR3U.mjs";
56
67
  import {
57
68
  intersectionWith
58
69
  } from "../chunk-XI7KRD2C.mjs";
@@ -65,20 +76,15 @@ import {
65
76
  import {
66
77
  minBy
67
78
  } from "../chunk-IJD7FE2Z.mjs";
79
+ import {
80
+ orderBy
81
+ } from "../chunk-7B7W36UP.mjs";
68
82
  import {
69
83
  partition
70
84
  } from "../chunk-DN3NOZ3H.mjs";
71
85
  import {
72
86
  sample
73
87
  } from "../chunk-2KNLZB7V.mjs";
74
- import {
75
- sampleSize
76
- } from "../chunk-EHSKB6DF.mjs";
77
- import "../chunk-GIWAOOFY.mjs";
78
- import "../chunk-SYWMYQYJ.mjs";
79
- import {
80
- shuffle
81
- } from "../chunk-G7UQ5PUR.mjs";
82
88
  import {
83
89
  dropRightWhile
84
90
  } from "../chunk-JE6JKZU3.mjs";
@@ -94,12 +100,12 @@ import {
94
100
  import {
95
101
  groupBy
96
102
  } from "../chunk-E6E4RZLN.mjs";
103
+ import {
104
+ head
105
+ } from "../chunk-HM2JT2RX.mjs";
97
106
  import {
98
107
  intersection
99
108
  } from "../chunk-FVVSE2F2.mjs";
100
- import {
101
- intersectionBy
102
- } from "../chunk-O6UXZR3U.mjs";
103
109
  import {
104
110
  chunk
105
111
  } from "../chunk-E6C5EZQA.mjs";
@@ -139,12 +145,14 @@ export {
139
145
  fill,
140
146
  forEachRight,
141
147
  groupBy,
148
+ head,
142
149
  intersection,
143
150
  intersectionBy,
144
151
  intersectionWith,
145
152
  keyBy,
146
153
  maxBy,
147
154
  minBy,
155
+ orderBy,
148
156
  partition,
149
157
  sample,
150
158
  sampleSize,
@@ -0,0 +1,35 @@
1
+ type Order = 'asc' | 'desc';
2
+ /**
3
+ * Sorts an array of objects based on multiple properties and their corresponding order directions.
4
+ *
5
+ * This function takes an array of objects, an array of keys to sort by, and an array of order directions.
6
+ * It returns the sorted array, ordering by each key according to its corresponding direction
7
+ * ('asc' for ascending or 'desc' for descending). If values for a key are equal,
8
+ * it moves to the next key to determine the order.
9
+ *
10
+ * @template T - The type of elements in the array.
11
+ * @param {T[]} collection - The array of objects to be sorted.
12
+ * @param {Array<keyof T>} keys - An array of keys (properties) by which to sort.
13
+ * @param {Order[]} orders - An array of order directions ('asc' for ascending or 'desc' for descending).
14
+ * @returns {T[]} - The sorted array.
15
+ *
16
+ * @example
17
+ * // Sort an array of objects by 'user' in ascending order and 'age' in descending order.
18
+ * const users = [
19
+ * { user: 'fred', age: 48 },
20
+ * { user: 'barney', age: 34 },
21
+ * { user: 'fred', age: 40 },
22
+ * { user: 'barney', age: 36 },
23
+ * ];
24
+ * const result = orderBy(users, ['user', 'age'], ['asc', 'desc']);
25
+ * // result will be:
26
+ * // [
27
+ * // { user: 'barney', age: 36 },
28
+ * // { user: 'barney', age: 34 },
29
+ * // { user: 'fred', age: 48 },
30
+ * // { user: 'fred', age: 40 },
31
+ * // ]
32
+ */
33
+ declare function orderBy<T>(collection: T[], keys: Array<keyof T>, orders: Order[]): T[];
34
+
35
+ export { orderBy };
@@ -0,0 +1,35 @@
1
+ type Order = 'asc' | 'desc';
2
+ /**
3
+ * Sorts an array of objects based on multiple properties and their corresponding order directions.
4
+ *
5
+ * This function takes an array of objects, an array of keys to sort by, and an array of order directions.
6
+ * It returns the sorted array, ordering by each key according to its corresponding direction
7
+ * ('asc' for ascending or 'desc' for descending). If values for a key are equal,
8
+ * it moves to the next key to determine the order.
9
+ *
10
+ * @template T - The type of elements in the array.
11
+ * @param {T[]} collection - The array of objects to be sorted.
12
+ * @param {Array<keyof T>} keys - An array of keys (properties) by which to sort.
13
+ * @param {Order[]} orders - An array of order directions ('asc' for ascending or 'desc' for descending).
14
+ * @returns {T[]} - The sorted array.
15
+ *
16
+ * @example
17
+ * // Sort an array of objects by 'user' in ascending order and 'age' in descending order.
18
+ * const users = [
19
+ * { user: 'fred', age: 48 },
20
+ * { user: 'barney', age: 34 },
21
+ * { user: 'fred', age: 40 },
22
+ * { user: 'barney', age: 36 },
23
+ * ];
24
+ * const result = orderBy(users, ['user', 'age'], ['asc', 'desc']);
25
+ * // result will be:
26
+ * // [
27
+ * // { user: 'barney', age: 36 },
28
+ * // { user: 'barney', age: 34 },
29
+ * // { user: 'fred', age: 48 },
30
+ * // { user: 'fred', age: 40 },
31
+ * // ]
32
+ */
33
+ declare function orderBy<T>(collection: T[], keys: Array<keyof T>, orders: Order[]): T[];
34
+
35
+ export { orderBy };
@@ -0,0 +1,53 @@
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/orderBy.ts
21
+ var orderBy_exports = {};
22
+ __export(orderBy_exports, {
23
+ orderBy: () => orderBy
24
+ });
25
+ module.exports = __toCommonJS(orderBy_exports);
26
+ function orderBy(collection, keys, orders) {
27
+ const compareValues = (a, b, order) => {
28
+ if (a < b) {
29
+ return order === "asc" ? -1 : 1;
30
+ }
31
+ if (a > b) {
32
+ return order === "asc" ? 1 : -1;
33
+ }
34
+ return 0;
35
+ };
36
+ const effectiveOrders = keys.map((_, index) => orders[index] || orders[orders.length - 1]);
37
+ return collection.slice().sort((a, b) => {
38
+ for (let i = 0; i < keys.length; i++) {
39
+ const key = keys[i];
40
+ const order = effectiveOrders[i];
41
+ const result = compareValues(a[key], b[key], order);
42
+ if (result !== 0) {
43
+ return result;
44
+ }
45
+ }
46
+ return 0;
47
+ });
48
+ }
49
+ // Annotate the CommonJS export names for ESM import in node:
50
+ 0 && (module.exports = {
51
+ orderBy
52
+ });
53
+ //# sourceMappingURL=orderBy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/array/orderBy.ts"],"sourcesContent":["type Order = 'asc' | 'desc';\n\n/**\n * Sorts an array of objects based on multiple properties and their corresponding order directions.\n *\n * This function takes an array of objects, an array of keys to sort by, and an array of order directions.\n * It returns the sorted array, ordering by each key according to its corresponding direction\n * ('asc' for ascending or 'desc' for descending). If values for a key are equal,\n * it moves to the next key to determine the order.\n *\n * @template T - The type of elements in the array.\n * @param {T[]} collection - The array of objects to be sorted.\n * @param {Array<keyof T>} keys - An array of keys (properties) by which to sort.\n * @param {Order[]} orders - An array of order directions ('asc' for ascending or 'desc' for descending).\n * @returns {T[]} - The sorted array.\n *\n * @example\n * // Sort an array of objects by 'user' in ascending order and 'age' in descending order.\n * const users = [\n * { user: 'fred', age: 48 },\n * { user: 'barney', age: 34 },\n * { user: 'fred', age: 40 },\n * { user: 'barney', age: 36 },\n * ];\n * const result = orderBy(users, ['user', 'age'], ['asc', 'desc']);\n * // result will be:\n * // [\n * // { user: 'barney', age: 36 },\n * // { user: 'barney', age: 34 },\n * // { user: 'fred', age: 48 },\n * // { user: 'fred', age: 40 },\n * // ]\n */\nexport function orderBy<T>(collection: T[], keys: Array<keyof T>, orders: Order[]): T[] {\n const compareValues = (a: T[keyof T], b: T[keyof T], order: Order) => {\n if (a < b) {\n return order === 'asc' ? -1 : 1;\n }\n if (a > b) {\n return order === 'asc' ? 1 : -1;\n }\n return 0;\n };\n\n const effectiveOrders = keys.map((_, index) => orders[index] || orders[orders.length - 1]);\n\n return collection.slice().sort((a, b) => {\n for (let i = 0; i < keys.length; i++) {\n const key = keys[i];\n const order = effectiveOrders[i];\n const result = compareValues(a[key], b[key], order);\n if (result !== 0) {\n return result;\n }\n }\n return 0;\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAiCO,SAAS,QAAW,YAAiB,MAAsB,QAAsB;AACtF,QAAM,gBAAgB,CAAC,GAAe,GAAe,UAAiB;AACpE,QAAI,IAAI,GAAG;AACT,aAAO,UAAU,QAAQ,KAAK;AAAA,IAChC;AACA,QAAI,IAAI,GAAG;AACT,aAAO,UAAU,QAAQ,IAAI;AAAA,IAC/B;AACA,WAAO;AAAA,EACT;AAEA,QAAM,kBAAkB,KAAK,IAAI,CAAC,GAAG,UAAU,OAAO,KAAK,KAAK,OAAO,OAAO,SAAS,CAAC,CAAC;AAEzF,SAAO,WAAW,MAAM,EAAE,KAAK,CAAC,GAAG,MAAM;AACvC,aAAS,IAAI,GAAG,IAAI,KAAK,QAAQ,KAAK;AACpC,YAAM,MAAM,KAAK,CAAC;AAClB,YAAM,QAAQ,gBAAgB,CAAC;AAC/B,YAAM,SAAS,cAAc,EAAE,GAAG,GAAG,EAAE,GAAG,GAAG,KAAK;AAClD,UAAI,WAAW,GAAG;AAChB,eAAO;AAAA,MACT;AAAA,IACF;AACA,WAAO;AAAA,EACT,CAAC;AACH;","names":[]}
@@ -0,0 +1,8 @@
1
+ import {
2
+ orderBy
3
+ } from "../chunk-7B7W36UP.mjs";
4
+ import "../chunk-2MM5EJJX.mjs";
5
+ export {
6
+ orderBy
7
+ };
8
+ //# sourceMappingURL=orderBy.mjs.map
@@ -0,0 +1,29 @@
1
+ // src/array/orderBy.ts
2
+ function orderBy(collection, keys, orders) {
3
+ const compareValues = (a, b, order) => {
4
+ if (a < b) {
5
+ return order === "asc" ? -1 : 1;
6
+ }
7
+ if (a > b) {
8
+ return order === "asc" ? 1 : -1;
9
+ }
10
+ return 0;
11
+ };
12
+ const effectiveOrders = keys.map((_, index) => orders[index] || orders[orders.length - 1]);
13
+ return collection.slice().sort((a, b) => {
14
+ for (let i = 0; i < keys.length; i++) {
15
+ const key = keys[i];
16
+ const order = effectiveOrders[i];
17
+ const result = compareValues(a[key], b[key], order);
18
+ if (result !== 0) {
19
+ return result;
20
+ }
21
+ }
22
+ return 0;
23
+ });
24
+ }
25
+
26
+ export {
27
+ orderBy
28
+ };
29
+ //# sourceMappingURL=chunk-7B7W36UP.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/array/orderBy.ts"],"sourcesContent":["type Order = 'asc' | 'desc';\n\n/**\n * Sorts an array of objects based on multiple properties and their corresponding order directions.\n *\n * This function takes an array of objects, an array of keys to sort by, and an array of order directions.\n * It returns the sorted array, ordering by each key according to its corresponding direction\n * ('asc' for ascending or 'desc' for descending). If values for a key are equal,\n * it moves to the next key to determine the order.\n *\n * @template T - The type of elements in the array.\n * @param {T[]} collection - The array of objects to be sorted.\n * @param {Array<keyof T>} keys - An array of keys (properties) by which to sort.\n * @param {Order[]} orders - An array of order directions ('asc' for ascending or 'desc' for descending).\n * @returns {T[]} - The sorted array.\n *\n * @example\n * // Sort an array of objects by 'user' in ascending order and 'age' in descending order.\n * const users = [\n * { user: 'fred', age: 48 },\n * { user: 'barney', age: 34 },\n * { user: 'fred', age: 40 },\n * { user: 'barney', age: 36 },\n * ];\n * const result = orderBy(users, ['user', 'age'], ['asc', 'desc']);\n * // result will be:\n * // [\n * // { user: 'barney', age: 36 },\n * // { user: 'barney', age: 34 },\n * // { user: 'fred', age: 48 },\n * // { user: 'fred', age: 40 },\n * // ]\n */\nexport function orderBy<T>(collection: T[], keys: Array<keyof T>, orders: Order[]): T[] {\n const compareValues = (a: T[keyof T], b: T[keyof T], order: Order) => {\n if (a < b) {\n return order === 'asc' ? -1 : 1;\n }\n if (a > b) {\n return order === 'asc' ? 1 : -1;\n }\n return 0;\n };\n\n const effectiveOrders = keys.map((_, index) => orders[index] || orders[orders.length - 1]);\n\n return collection.slice().sort((a, b) => {\n for (let i = 0; i < keys.length; i++) {\n const key = keys[i];\n const order = effectiveOrders[i];\n const result = compareValues(a[key], b[key], order);\n if (result !== 0) {\n return result;\n }\n }\n return 0;\n });\n}\n"],"mappings":";AAiCO,SAAS,QAAW,YAAiB,MAAsB,QAAsB;AACtF,QAAM,gBAAgB,CAAC,GAAe,GAAe,UAAiB;AACpE,QAAI,IAAI,GAAG;AACT,aAAO,UAAU,QAAQ,KAAK;AAAA,IAChC;AACA,QAAI,IAAI,GAAG;AACT,aAAO,UAAU,QAAQ,IAAI;AAAA,IAC/B;AACA,WAAO;AAAA,EACT;AAEA,QAAM,kBAAkB,KAAK,IAAI,CAAC,GAAG,UAAU,OAAO,KAAK,KAAK,OAAO,OAAO,SAAS,CAAC,CAAC;AAEzF,SAAO,WAAW,MAAM,EAAE,KAAK,CAAC,GAAG,MAAM;AACvC,aAAS,IAAI,GAAG,IAAI,KAAK,QAAQ,KAAK;AACpC,YAAM,MAAM,KAAK,CAAC;AAClB,YAAM,QAAQ,gBAAgB,CAAC;AAC/B,YAAM,SAAS,cAAc,EAAE,GAAG,GAAG,EAAE,GAAG,GAAG,KAAK;AAClD,UAAI,WAAW,GAAG;AAChB,eAAO;AAAA,MACT;AAAA,IACF;AACA,WAAO;AAAA,EACT,CAAC;AACH;","names":[]}
@@ -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,9 @@
1
+ // src/array/head.ts
2
+ function head(arr) {
3
+ return arr[0];
4
+ }
5
+
6
+ export {
7
+ head
8
+ };
9
+ //# sourceMappingURL=chunk-HM2JT2RX.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/array/head.ts"],"sourcesContent":["/**\n * Returns the first element of an array.\n *\n * This function takes an array and returns the first element of the array.\n * If the array is empty, the function returns `undefined`.\n *\n * @param {T[]} arr - The array from which to get the first element.\n * @returns {T | undefined} The first element of the array, or `undefined` if the array is empty.\n *\n * @example\n * const arr = [1, 2, 3];\n * const firstElement = head(arr);\n * // firstElement will be 1\n *\n * const emptyArr: number[] = [];\n * const noElement = head(emptyArr);\n * // noElement will be undefined\n */\nexport function head<T>(arr: readonly [T, ...T[]]): T;\nexport function head<T>(arr: readonly T[]): T | undefined;\nexport function head<T>(arr: readonly T[]): T | undefined {\n return arr[0];\n}\n"],"mappings":";AAoBO,SAAS,KAAQ,KAAkC;AACxD,SAAO,IAAI,CAAC;AACd;","names":[]}
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=chunk-O5QHO3W7.mjs.map
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=chunk-PMHULJNL.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=chunk-TLVQSNOE.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
package/dist/index.d.mts CHANGED
@@ -17,6 +17,7 @@ export { intersectionWith } from './array/intersectionWith.mjs';
17
17
  export { keyBy } from './array/keyBy.mjs';
18
18
  export { maxBy } from './array/maxBy.mjs';
19
19
  export { minBy } from './array/minBy.mjs';
20
+ export { orderBy } from './array/orderBy.mjs';
20
21
  export { partition } from './array/partition.mjs';
21
22
  export { sample } from './array/sample.mjs';
22
23
  export { sampleSize } from './array/sampleSize.mjs';
@@ -39,12 +40,14 @@ export { zip } from './array/zip.mjs';
39
40
  export { zipObject } from './array/zipObject.mjs';
40
41
  export { zipWith } from './array/zipWith.mjs';
41
42
  export { without } from './array/without.mjs';
43
+ export { head } from './array/head.mjs';
42
44
  export { AbortError } from './error/AbortError.mjs';
43
45
  export { debounce } from './function/debounce.mjs';
44
46
  export { noop } from './function/noop.mjs';
45
47
  export { once } from './function/once.mjs';
46
48
  export { throttle } from './function/throttle.mjs';
47
49
  export { clamp } from './math/clamp.mjs';
50
+ export { inRange } from './math/inRange.mjs';
48
51
  export { mean } from './math/mean.mjs';
49
52
  export { meanBy } from './math/meanBy.mjs';
50
53
  export { random } from './math/random.mjs';
@@ -56,6 +59,7 @@ export { omit } from './object/omit.mjs';
56
59
  export { omitBy } from './object/omitBy.mjs';
57
60
  export { pick } from './object/pick.mjs';
58
61
  export { pickBy } from './object/pickBy.mjs';
62
+ export { invert } from './object/invert.mjs';
59
63
  export { isNil } from './predicate/isNil.mjs';
60
64
  export { isNotNil } from './predicate/isNotNil.mjs';
61
65
  export { isNull } from './predicate/isNull.mjs';
package/dist/index.d.ts CHANGED
@@ -17,6 +17,7 @@ export { intersectionWith } from './array/intersectionWith.js';
17
17
  export { keyBy } from './array/keyBy.js';
18
18
  export { maxBy } from './array/maxBy.js';
19
19
  export { minBy } from './array/minBy.js';
20
+ export { orderBy } from './array/orderBy.js';
20
21
  export { partition } from './array/partition.js';
21
22
  export { sample } from './array/sample.js';
22
23
  export { sampleSize } from './array/sampleSize.js';
@@ -39,12 +40,14 @@ export { zip } from './array/zip.js';
39
40
  export { zipObject } from './array/zipObject.js';
40
41
  export { zipWith } from './array/zipWith.js';
41
42
  export { without } from './array/without.js';
43
+ export { head } from './array/head.js';
42
44
  export { AbortError } from './error/AbortError.js';
43
45
  export { debounce } from './function/debounce.js';
44
46
  export { noop } from './function/noop.js';
45
47
  export { once } from './function/once.js';
46
48
  export { throttle } from './function/throttle.js';
47
49
  export { clamp } from './math/clamp.js';
50
+ export { inRange } from './math/inRange.js';
48
51
  export { mean } from './math/mean.js';
49
52
  export { meanBy } from './math/meanBy.js';
50
53
  export { random } from './math/random.js';
@@ -56,6 +59,7 @@ export { omit } from './object/omit.js';
56
59
  export { omitBy } from './object/omitBy.js';
57
60
  export { pick } from './object/pick.js';
58
61
  export { pickBy } from './object/pickBy.js';
62
+ export { invert } from './object/invert.js';
59
63
  export { isNil } from './predicate/isNil.js';
60
64
  export { isNotNil } from './predicate/isNotNil.js';
61
65
  export { isNull } from './predicate/isNull.js';
package/dist/index.js CHANGED
@@ -51,9 +51,12 @@ __export(src_exports, {
51
51
  fill: () => fill,
52
52
  forEachRight: () => forEachRight,
53
53
  groupBy: () => groupBy,
54
+ head: () => head,
55
+ inRange: () => inRange,
54
56
  intersection: () => intersection,
55
57
  intersectionBy: () => intersectionBy,
56
58
  intersectionWith: () => intersectionWith,
59
+ invert: () => invert,
57
60
  isNil: () => isNil,
58
61
  isNotNil: () => isNotNil,
59
62
  isNull: () => isNull,
@@ -67,6 +70,7 @@ __export(src_exports, {
67
70
  omit: () => omit,
68
71
  omitBy: () => omitBy,
69
72
  once: () => once,
73
+ orderBy: () => orderBy,
70
74
  partition: () => partition,
71
75
  pick: () => pick,
72
76
  pickBy: () => pickBy,
@@ -278,6 +282,31 @@ function minBy(items, getValue) {
278
282
  return minElement;
279
283
  }
280
284
 
285
+ // src/array/orderBy.ts
286
+ function orderBy(collection, keys, orders) {
287
+ const compareValues = (a, b, order) => {
288
+ if (a < b) {
289
+ return order === "asc" ? -1 : 1;
290
+ }
291
+ if (a > b) {
292
+ return order === "asc" ? 1 : -1;
293
+ }
294
+ return 0;
295
+ };
296
+ const effectiveOrders = keys.map((_, index) => orders[index] || orders[orders.length - 1]);
297
+ return collection.slice().sort((a, b) => {
298
+ for (let i = 0; i < keys.length; i++) {
299
+ const key = keys[i];
300
+ const order = effectiveOrders[i];
301
+ const result = compareValues(a[key], b[key], order);
302
+ if (result !== 0) {
303
+ return result;
304
+ }
305
+ }
306
+ return 0;
307
+ });
308
+ }
309
+
281
310
  // src/array/partition.ts
282
311
  function partition(arr, isInTruthy) {
283
312
  const truthy = [];
@@ -504,6 +533,11 @@ function without(array, ...values) {
504
533
  return array.filter((item) => !valuesSet.has(item));
505
534
  }
506
535
 
536
+ // src/array/head.ts
537
+ function head(arr) {
538
+ return arr[0];
539
+ }
540
+
507
541
  // src/error/AbortError.ts
508
542
  var AbortError = class extends Error {
509
543
  constructor(message = "The operation was aborted") {
@@ -580,6 +614,18 @@ function clamp(value, bound1, bound2) {
580
614
  return Math.min(Math.max(value, bound1), bound2);
581
615
  }
582
616
 
617
+ // src/math/inRange.ts
618
+ function inRange(value, minimum, maximum) {
619
+ if (maximum == null) {
620
+ maximum = minimum;
621
+ minimum = 0;
622
+ }
623
+ if (minimum >= maximum) {
624
+ throw new Error("The maximum value must be greater than the minimum value.");
625
+ }
626
+ return minimum <= value && value < maximum;
627
+ }
628
+
583
629
  // src/math/sum.ts
584
630
  function sum(nums) {
585
631
  let result = 0;
@@ -671,6 +717,16 @@ function pickBy(obj, shouldPick) {
671
717
  return result;
672
718
  }
673
719
 
720
+ // src/object/invert.ts
721
+ function invert(obj) {
722
+ const result = {};
723
+ for (const key in obj) {
724
+ const value = obj[key];
725
+ result[value] = key;
726
+ }
727
+ return result;
728
+ }
729
+
674
730
  // src/predicate/isNil.ts
675
731
  function isNil(x) {
676
732
  return x === null || x === void 0;
@@ -727,9 +783,12 @@ function delay(ms, { signal } = {}) {
727
783
  fill,
728
784
  forEachRight,
729
785
  groupBy,
786
+ head,
787
+ inRange,
730
788
  intersection,
731
789
  intersectionBy,
732
790
  intersectionWith,
791
+ invert,
733
792
  isNil,
734
793
  isNotNil,
735
794
  isNull,
@@ -743,6 +802,7 @@ function delay(ms, { signal } = {}) {
743
802
  omit,
744
803
  omitBy,
745
804
  once,
805
+ orderBy,
746
806
  partition,
747
807
  pick,
748
808
  pickBy,