es-toolkit 1.7.1-dev.153 → 1.7.1-dev.155

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.d.mts +1 -0
  2. package/dist/array/index.d.ts +1 -0
  3. package/dist/array/index.js +27 -0
  4. package/dist/array/index.js.map +1 -1
  5. package/dist/array/index.mjs +51 -47
  6. package/dist/array/orderBy.d.mts +35 -0
  7. package/dist/array/orderBy.d.ts +35 -0
  8. package/dist/array/orderBy.js +53 -0
  9. package/dist/array/orderBy.js.map +1 -0
  10. package/dist/array/orderBy.mjs +8 -0
  11. package/dist/chunk-7B7W36UP.mjs +29 -0
  12. package/dist/chunk-7B7W36UP.mjs.map +1 -0
  13. package/dist/chunk-FLTT2MGF.mjs +14 -0
  14. package/dist/chunk-FLTT2MGF.mjs.map +1 -0
  15. package/dist/chunk-OC7ZNKWX.mjs +1 -0
  16. package/dist/chunk-PMHULJNL.mjs +1 -0
  17. package/dist/chunk-PMHULJNL.mjs.map +1 -0
  18. package/dist/function/index.mjs +3 -3
  19. package/dist/index.d.mts +2 -0
  20. package/dist/index.d.ts +2 -0
  21. package/dist/index.js +39 -0
  22. package/dist/index.js.map +1 -1
  23. package/dist/index.mjs +81 -73
  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-XJR5WV2Z.mjs +0 -1
  38. /package/dist/{chunk-T5JCRGXA.mjs.map → array/orderBy.mjs.map} +0 -0
  39. /package/dist/{chunk-XJR5WV2Z.mjs.map → chunk-OC7ZNKWX.mjs.map} +0 -0
@@ -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,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-OC7ZNKWX.mjs.map
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=chunk-PMHULJNL.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -1,7 +1,4 @@
1
1
  import "../chunk-N6EM6ETS.mjs";
2
- import {
3
- debounce
4
- } from "../chunk-3IP4JVLL.mjs";
5
2
  import {
6
3
  noop
7
4
  } from "../chunk-LKXCOLNY.mjs";
@@ -11,6 +8,9 @@ import {
11
8
  import {
12
9
  throttle
13
10
  } from "../chunk-QOJGMVVR.mjs";
11
+ import {
12
+ debounce
13
+ } from "../chunk-3IP4JVLL.mjs";
14
14
  import "../chunk-2MM5EJJX.mjs";
15
15
  export {
16
16
  debounce,
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';
@@ -57,6 +58,7 @@ export { omit } from './object/omit.mjs';
57
58
  export { omitBy } from './object/omitBy.mjs';
58
59
  export { pick } from './object/pick.mjs';
59
60
  export { pickBy } from './object/pickBy.mjs';
61
+ export { invert } from './object/invert.mjs';
60
62
  export { isNil } from './predicate/isNil.mjs';
61
63
  export { isNotNil } from './predicate/isNotNil.mjs';
62
64
  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';
@@ -57,6 +58,7 @@ export { omit } from './object/omit.js';
57
58
  export { omitBy } from './object/omitBy.js';
58
59
  export { pick } from './object/pick.js';
59
60
  export { pickBy } from './object/pickBy.js';
61
+ export { invert } from './object/invert.js';
60
62
  export { isNil } from './predicate/isNil.js';
61
63
  export { isNotNil } from './predicate/isNotNil.js';
62
64
  export { isNull } from './predicate/isNull.js';
package/dist/index.js CHANGED
@@ -55,6 +55,7 @@ __export(src_exports, {
55
55
  intersection: () => intersection,
56
56
  intersectionBy: () => intersectionBy,
57
57
  intersectionWith: () => intersectionWith,
58
+ invert: () => invert,
58
59
  isNil: () => isNil,
59
60
  isNotNil: () => isNotNil,
60
61
  isNull: () => isNull,
@@ -68,6 +69,7 @@ __export(src_exports, {
68
69
  omit: () => omit,
69
70
  omitBy: () => omitBy,
70
71
  once: () => once,
72
+ orderBy: () => orderBy,
71
73
  partition: () => partition,
72
74
  pick: () => pick,
73
75
  pickBy: () => pickBy,
@@ -279,6 +281,31 @@ function minBy(items, getValue) {
279
281
  return minElement;
280
282
  }
281
283
 
284
+ // src/array/orderBy.ts
285
+ function orderBy(collection, keys, orders) {
286
+ const compareValues = (a, b, order) => {
287
+ if (a < b) {
288
+ return order === "asc" ? -1 : 1;
289
+ }
290
+ if (a > b) {
291
+ return order === "asc" ? 1 : -1;
292
+ }
293
+ return 0;
294
+ };
295
+ const effectiveOrders = keys.map((_, index) => orders[index] || orders[orders.length - 1]);
296
+ return collection.slice().sort((a, b) => {
297
+ for (let i = 0; i < keys.length; i++) {
298
+ const key = keys[i];
299
+ const order = effectiveOrders[i];
300
+ const result = compareValues(a[key], b[key], order);
301
+ if (result !== 0) {
302
+ return result;
303
+ }
304
+ }
305
+ return 0;
306
+ });
307
+ }
308
+
282
309
  // src/array/partition.ts
283
310
  function partition(arr, isInTruthy) {
284
311
  const truthy = [];
@@ -684,6 +711,16 @@ function pickBy(obj, shouldPick) {
684
711
  return result;
685
712
  }
686
713
 
714
+ // src/object/invert.ts
715
+ function invert(obj) {
716
+ const result = {};
717
+ for (const key in obj) {
718
+ const value = obj[key];
719
+ result[value] = key;
720
+ }
721
+ return result;
722
+ }
723
+
687
724
  // src/predicate/isNil.ts
688
725
  function isNil(x) {
689
726
  return x === null || x === void 0;
@@ -744,6 +781,7 @@ function delay(ms, { signal } = {}) {
744
781
  intersection,
745
782
  intersectionBy,
746
783
  intersectionWith,
784
+ invert,
747
785
  isNil,
748
786
  isNotNil,
749
787
  isNull,
@@ -757,6 +795,7 @@ function delay(ms, { signal } = {}) {
757
795
  omit,
758
796
  omitBy,
759
797
  once,
798
+ orderBy,
760
799
  partition,
761
800
  pick,
762
801
  pickBy,