@ls-stack/utils 3.27.0 → 3.27.2

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.
@@ -14,7 +14,7 @@
14
14
  function filterObjectOrArrayKeys(objOrArray, options): Record<string, any> | Record<string, any>[];
15
15
  ```
16
16
 
17
- Defined in: [packages/utils/src/filterObjectOrArrayKeys.ts:58](https://github.com/lucasols/utils/blob/main/packages/utils/src/filterObjectOrArrayKeys.ts#L58)
17
+ Defined in: [packages/utils/src/filterObjectOrArrayKeys.ts:60](https://github.com/lucasols/utils/blob/main/packages/utils/src/filterObjectOrArrayKeys.ts#L60)
18
18
 
19
19
  Filters the keys of an object based on the provided patterns.
20
20
 
@@ -6,6 +6,7 @@ import {
6
6
  } from "./chunk-JF2MDHOJ.js";
7
7
 
8
8
  // src/filterObjectOrArrayKeys.ts
9
+ var ID_PROP_REGEXP = /^(id_|key_|id-|key-)|(_id|_key|-id|-key)$/i;
9
10
  function filterObjectOrArrayKeys(objOrArray, {
10
11
  filterKeys,
11
12
  rejectKeys,
@@ -197,6 +198,8 @@ function filterObjectOrArrayKeys(objOrArray, {
197
198
  return 1.5 + value.length * -0.01;
198
199
  }
199
200
  }
201
+ if (key === "id" || key === "key") return 5;
202
+ if (ID_PROP_REGEXP.test(key)) return 4.5;
200
203
  if (typeof value === "boolean") return 4;
201
204
  if (typeof value === "number") return 3.5;
202
205
  if (typeof value === "string" && value.length < 20) return 3;
@@ -207,14 +210,15 @@ function filterObjectOrArrayKeys(objOrArray, {
207
210
  "desc"
208
211
  );
209
212
  }
210
- function sortKeysWithPatterns(keys, obj, currentPath) {
213
+ function sortKeysWithPatterns(keys_, obj, currentPath) {
211
214
  if (!sortKeys && sortPatternsParsed.length === 0) {
212
- return keys;
215
+ return keys_;
213
216
  }
214
- if (sortPatternsParsed.length === 0) {
215
- return sortKeys ? applySortKeys(keys, obj, sortKeys) : keys;
217
+ let keysToSort = keys_;
218
+ if (sortKeys) {
219
+ keysToSort = applySortKeys(keysToSort, obj, sortKeys);
216
220
  }
217
- const sortedKeys = [...keys].sort((a, b) => {
221
+ const sortedKeys = [...keysToSort].sort((a, b) => {
218
222
  const pathA = currentPath.concat({ type: "KEY", name: a });
219
223
  const pathB = currentPath.concat({ type: "KEY", name: b });
220
224
  const priorityA = getSortPriority(pathA);
@@ -64,6 +64,7 @@ function sortBy(arr, sortByValue, props = "asc") {
64
64
  }
65
65
 
66
66
  // src/filterObjectOrArrayKeys.ts
67
+ var ID_PROP_REGEXP = /^(id_|key_|id-|key-)|(_id|_key|-id|-key)$/i;
67
68
  function filterObjectOrArrayKeys(objOrArray, {
68
69
  filterKeys,
69
70
  rejectKeys,
@@ -255,6 +256,8 @@ function filterObjectOrArrayKeys(objOrArray, {
255
256
  return 1.5 + value.length * -0.01;
256
257
  }
257
258
  }
259
+ if (key === "id" || key === "key") return 5;
260
+ if (ID_PROP_REGEXP.test(key)) return 4.5;
258
261
  if (typeof value === "boolean") return 4;
259
262
  if (typeof value === "number") return 3.5;
260
263
  if (typeof value === "string" && value.length < 20) return 3;
@@ -265,14 +268,15 @@ function filterObjectOrArrayKeys(objOrArray, {
265
268
  "desc"
266
269
  );
267
270
  }
268
- function sortKeysWithPatterns(keys, obj, currentPath) {
271
+ function sortKeysWithPatterns(keys_, obj, currentPath) {
269
272
  if (!sortKeys && sortPatternsParsed.length === 0) {
270
- return keys;
273
+ return keys_;
271
274
  }
272
- if (sortPatternsParsed.length === 0) {
273
- return sortKeys ? applySortKeys(keys, obj, sortKeys) : keys;
275
+ let keysToSort = keys_;
276
+ if (sortKeys) {
277
+ keysToSort = applySortKeys(keysToSort, obj, sortKeys);
274
278
  }
275
- const sortedKeys = [...keys].sort((a, b) => {
279
+ const sortedKeys = [...keysToSort].sort((a, b) => {
276
280
  const pathA = currentPath.concat({ type: "KEY", name: a });
277
281
  const pathB = currentPath.concat({ type: "KEY", name: b });
278
282
  const priorityA = getSortPriority(pathA);
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  filterObjectOrArrayKeys
3
- } from "./chunk-MVN6FKX7.js";
3
+ } from "./chunk-J3ILVKZC.js";
4
4
  import "./chunk-SRVMMYSW.js";
5
5
  import "./chunk-C2SVCIWE.js";
6
6
  import "./chunk-JF2MDHOJ.js";
package/lib/testUtils.cjs CHANGED
@@ -156,6 +156,7 @@ function deepEqual(foo, bar, maxDepth = 20) {
156
156
  }
157
157
 
158
158
  // src/filterObjectOrArrayKeys.ts
159
+ var ID_PROP_REGEXP = /^(id_|key_|id-|key-)|(_id|_key|-id|-key)$/i;
159
160
  function filterObjectOrArrayKeys(objOrArray, {
160
161
  filterKeys,
161
162
  rejectKeys,
@@ -347,6 +348,8 @@ function filterObjectOrArrayKeys(objOrArray, {
347
348
  return 1.5 + value.length * -0.01;
348
349
  }
349
350
  }
351
+ if (key === "id" || key === "key") return 5;
352
+ if (ID_PROP_REGEXP.test(key)) return 4.5;
350
353
  if (typeof value === "boolean") return 4;
351
354
  if (typeof value === "number") return 3.5;
352
355
  if (typeof value === "string" && value.length < 20) return 3;
@@ -357,14 +360,15 @@ function filterObjectOrArrayKeys(objOrArray, {
357
360
  "desc"
358
361
  );
359
362
  }
360
- function sortKeysWithPatterns(keys, obj, currentPath) {
363
+ function sortKeysWithPatterns(keys_, obj, currentPath) {
361
364
  if (!sortKeys && sortPatternsParsed.length === 0) {
362
- return keys;
365
+ return keys_;
363
366
  }
364
- if (sortPatternsParsed.length === 0) {
365
- return sortKeys ? applySortKeys(keys, obj, sortKeys) : keys;
367
+ let keysToSort = keys_;
368
+ if (sortKeys) {
369
+ keysToSort = applySortKeys(keysToSort, obj, sortKeys);
366
370
  }
367
- const sortedKeys = [...keys].sort((a, b) => {
371
+ const sortedKeys = [...keysToSort].sort((a, b) => {
368
372
  const pathA = currentPath.concat({ type: "KEY", name: a });
369
373
  const pathB = currentPath.concat({ type: "KEY", name: b });
370
374
  const priorityA = getSortPriority(pathA);
package/lib/testUtils.js CHANGED
@@ -11,7 +11,7 @@ import {
11
11
  } from "./chunk-JQFUKJU5.js";
12
12
  import {
13
13
  filterObjectOrArrayKeys
14
- } from "./chunk-MVN6FKX7.js";
14
+ } from "./chunk-J3ILVKZC.js";
15
15
  import {
16
16
  defer
17
17
  } from "./chunk-DFXNVEH6.js";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ls-stack/utils",
3
3
  "description": "Universal TypeScript utilities for browser and Node.js",
4
- "version": "3.27.0",
4
+ "version": "3.27.2",
5
5
  "license": "MIT",
6
6
  "files": [
7
7
  "lib",