@8ms/helpers 2.3.27 → 2.3.28

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.
@@ -31,7 +31,7 @@ declare const merge: <T extends object>(target: T, ...sources: any[]) => T;
31
31
  //#region src/lodash/orderBy.d.ts
32
32
  type OrderDirection = "asc" | "desc";
33
33
  type Iteratee<T> = ((item: T) => unknown) | string;
34
- declare const orderBy: <T>(collection: T[], iteratees: Iteratee<T> | Iteratee<T>[], orders?: OrderDirection | OrderDirection[]) => T[];
34
+ declare const orderBy: <T>(collection: T[] | Record<string, T>, iteratees: Iteratee<T> | Iteratee<T>[], orders?: OrderDirection | OrderDirection[]) => T[];
35
35
  //#endregion
36
36
  //#region src/lodash/unescape.d.ts
37
37
  declare const unescape: (str: string) => string;
@@ -118,13 +118,14 @@ const merge = (target, ...sources) => {
118
118
  //#endregion
119
119
  //#region src/lodash/orderBy.ts
120
120
  const orderBy = (collection, iteratees, orders = "asc") => {
121
+ const arr = Array.isArray(collection) ? collection : Object.values(collection);
121
122
  const keys = Array.isArray(iteratees) ? iteratees : [iteratees];
122
123
  const dirs = Array.isArray(orders) ? orders : [orders];
123
124
  const getValue = (item, key) => {
124
125
  if (typeof key === "function") return key(item);
125
126
  return key.split(".").reduce((acc, part) => acc?.[part], item);
126
127
  };
127
- return [...collection].sort((a, b) => {
128
+ return [...arr].sort((a, b) => {
128
129
  for (let i = 0; i < keys.length; i++) {
129
130
  const dir = dirs[i] === "desc" ? -1 : 1;
130
131
  const aVal = getValue(a, keys[i]);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@8ms/helpers",
3
3
  "license": "UNLICENSED",
4
- "version": "2.3.27",
4
+ "version": "2.3.28",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/8millionstories-organisation/8ms-helpers-ts.git"