es-toolkit 1.7.1-dev.154 → 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.
@@ -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 @@
1
+ //# sourceMappingURL=chunk-OC7ZNKWX.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';
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';
package/dist/index.js CHANGED
@@ -69,6 +69,7 @@ __export(src_exports, {
69
69
  omit: () => omit,
70
70
  omitBy: () => omitBy,
71
71
  once: () => once,
72
+ orderBy: () => orderBy,
72
73
  partition: () => partition,
73
74
  pick: () => pick,
74
75
  pickBy: () => pickBy,
@@ -280,6 +281,31 @@ function minBy(items, getValue) {
280
281
  return minElement;
281
282
  }
282
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
+
283
309
  // src/array/partition.ts
284
310
  function partition(arr, isInTruthy) {
285
311
  const truthy = [];
@@ -769,6 +795,7 @@ function delay(ms, { signal } = {}) {
769
795
  omit,
770
796
  omitBy,
771
797
  once,
798
+ orderBy,
772
799
  partition,
773
800
  pick,
774
801
  pickBy,