@ls-stack/utils 3.58.0 → 3.59.0

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,6 +31,7 @@ __export(arrayUtils_exports, {
31
31
  hasDuplicates: () => hasDuplicates,
32
32
  intersperse: () => intersperse,
33
33
  isInArray: () => isInArray,
34
+ looseIsInArray: () => looseIsInArray,
34
35
  rejectArrayUndefinedValues: () => rejectArrayUndefinedValues,
35
36
  rejectDuplicates: () => rejectDuplicates,
36
37
  repeat: () => repeat,
@@ -105,6 +106,9 @@ function isInArray(value, oneOf) {
105
106
  }
106
107
  return false;
107
108
  }
109
+ function looseIsInArray(value, array) {
110
+ return array.includes(value);
111
+ }
108
112
  function findAfterIndex(array, index, predicate) {
109
113
  for (let i = index + 1; i < array.length; i++) {
110
114
  if (predicate(array[i])) {
@@ -211,6 +215,7 @@ function repeat(value, count, separator) {
211
215
  hasDuplicates,
212
216
  intersperse,
213
217
  isInArray,
218
+ looseIsInArray,
214
219
  rejectArrayUndefinedValues,
215
220
  rejectDuplicates,
216
221
  repeat,
@@ -76,6 +76,7 @@ declare function arrayWithPrevAndIndex<T>(array: T[]): {
76
76
  index: number;
77
77
  }[];
78
78
  declare function isInArray<T, const U extends T>(value: T, oneOf: readonly U[]): value is U;
79
+ declare function looseIsInArray(value: unknown, array: readonly unknown[]): boolean;
79
80
  declare function findAfterIndex<T>(array: T[], index: number, predicate: (item: T) => boolean): T | undefined;
80
81
  declare function findBeforeIndex<T>(array: T[], index: number, predicate: (item: T) => boolean): T | undefined;
81
82
  declare function rejectArrayUndefinedValues<T extends unknown[]>(array: T): T;
@@ -152,8 +153,8 @@ declare function arrayOps<T>(array: T[]): ArrayOps<T>;
152
153
  */
153
154
  declare function intersperse<T, I>(array: T[], separator: I): (T | I)[];
154
155
  /**
155
- * Creates an array by repeating a value a specified number of times,
156
- * optionally with a separator between each repetition.
156
+ * Creates an array by repeating a value a specified number of times, optionally
157
+ * with a separator between each repetition.
157
158
  *
158
159
  * @example
159
160
  * repeat('x', 3); // ['x', 'x', 'x']
@@ -166,4 +167,4 @@ declare function intersperse<T, I>(array: T[], separator: I): (T | I)[];
166
167
  */
167
168
  declare function repeat<T>(value: T, count: number, separator?: T): T[];
168
169
 
169
- export { type FilterAndMapReturn, type SortByProps, type SortByValueFn, arrayOps, arrayWithPrev, arrayWithPrevAndIndex, filterAndMap, findAfterIndex, findAndMap, findBeforeIndex, getAscIndexOrder, hasDuplicates, intersperse, isInArray, rejectArrayUndefinedValues, rejectDuplicates, repeat, sortBy, truncateArray };
170
+ export { type FilterAndMapReturn, type SortByProps, type SortByValueFn, arrayOps, arrayWithPrev, arrayWithPrevAndIndex, filterAndMap, findAfterIndex, findAndMap, findBeforeIndex, getAscIndexOrder, hasDuplicates, intersperse, isInArray, looseIsInArray, rejectArrayUndefinedValues, rejectDuplicates, repeat, sortBy, truncateArray };
@@ -76,6 +76,7 @@ declare function arrayWithPrevAndIndex<T>(array: T[]): {
76
76
  index: number;
77
77
  }[];
78
78
  declare function isInArray<T, const U extends T>(value: T, oneOf: readonly U[]): value is U;
79
+ declare function looseIsInArray(value: unknown, array: readonly unknown[]): boolean;
79
80
  declare function findAfterIndex<T>(array: T[], index: number, predicate: (item: T) => boolean): T | undefined;
80
81
  declare function findBeforeIndex<T>(array: T[], index: number, predicate: (item: T) => boolean): T | undefined;
81
82
  declare function rejectArrayUndefinedValues<T extends unknown[]>(array: T): T;
@@ -152,8 +153,8 @@ declare function arrayOps<T>(array: T[]): ArrayOps<T>;
152
153
  */
153
154
  declare function intersperse<T, I>(array: T[], separator: I): (T | I)[];
154
155
  /**
155
- * Creates an array by repeating a value a specified number of times,
156
- * optionally with a separator between each repetition.
156
+ * Creates an array by repeating a value a specified number of times, optionally
157
+ * with a separator between each repetition.
157
158
  *
158
159
  * @example
159
160
  * repeat('x', 3); // ['x', 'x', 'x']
@@ -166,4 +167,4 @@ declare function intersperse<T, I>(array: T[], separator: I): (T | I)[];
166
167
  */
167
168
  declare function repeat<T>(value: T, count: number, separator?: T): T[];
168
169
 
169
- export { type FilterAndMapReturn, type SortByProps, type SortByValueFn, arrayOps, arrayWithPrev, arrayWithPrevAndIndex, filterAndMap, findAfterIndex, findAndMap, findBeforeIndex, getAscIndexOrder, hasDuplicates, intersperse, isInArray, rejectArrayUndefinedValues, rejectDuplicates, repeat, sortBy, truncateArray };
170
+ export { type FilterAndMapReturn, type SortByProps, type SortByValueFn, arrayOps, arrayWithPrev, arrayWithPrevAndIndex, filterAndMap, findAfterIndex, findAndMap, findBeforeIndex, getAscIndexOrder, hasDuplicates, intersperse, isInArray, looseIsInArray, rejectArrayUndefinedValues, rejectDuplicates, repeat, sortBy, truncateArray };
@@ -10,12 +10,13 @@ import {
10
10
  hasDuplicates,
11
11
  intersperse,
12
12
  isInArray,
13
+ looseIsInArray,
13
14
  rejectArrayUndefinedValues,
14
15
  rejectDuplicates,
15
16
  repeat,
16
17
  sortBy,
17
18
  truncateArray
18
- } from "./chunk-BT3UMATU.js";
19
+ } from "./chunk-GVIDV772.js";
19
20
  import "./chunk-C2SVCIWE.js";
20
21
  import "./chunk-JF2MDHOJ.js";
21
22
  export {
@@ -30,6 +31,7 @@ export {
30
31
  hasDuplicates,
31
32
  intersperse,
32
33
  isInArray,
34
+ looseIsInArray,
33
35
  rejectArrayUndefinedValues,
34
36
  rejectDuplicates,
35
37
  repeat,
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  sortBy
3
- } from "./chunk-BT3UMATU.js";
3
+ } from "./chunk-GVIDV772.js";
4
4
  import {
5
5
  isPlainObject
6
6
  } from "./chunk-JF2MDHOJ.js";
@@ -60,6 +60,9 @@ function isInArray(value, oneOf) {
60
60
  }
61
61
  return false;
62
62
  }
63
+ function looseIsInArray(value, array) {
64
+ return array.includes(value);
65
+ }
63
66
  function findAfterIndex(array, index, predicate) {
64
67
  for (let i = index + 1; i < array.length; i++) {
65
68
  if (predicate(array[i])) {
@@ -161,6 +164,7 @@ export {
161
164
  arrayWithPrev,
162
165
  arrayWithPrevAndIndex,
163
166
  isInArray,
167
+ looseIsInArray,
164
168
  findAfterIndex,
165
169
  findBeforeIndex,
166
170
  rejectArrayUndefinedValues,
@@ -3,7 +3,7 @@ import {
3
3
  } from "./chunk-GMJTLFM6.js";
4
4
  import {
5
5
  sortBy
6
- } from "./chunk-BT3UMATU.js";
6
+ } from "./chunk-GVIDV772.js";
7
7
 
8
8
  // src/objUtils.ts
9
9
  import { Result } from "t-result";
@@ -17,14 +17,16 @@ function pick(obj, keys) {
17
17
  }
18
18
  return result;
19
19
  }
20
- function mapArrayToObject(array, mapper) {
20
+ function mapArrToObj(array, mapper) {
21
21
  return Object.fromEntries(array.map(mapper));
22
22
  }
23
- function mapObjectToObject(obj, mapper) {
23
+ var mapArrayToObject = mapArrToObj;
24
+ function mapObjToObj(obj, mapper) {
24
25
  return Object.fromEntries(
25
26
  objectTypedEntries(obj).map(([key, value]) => mapper(key, value))
26
27
  );
27
28
  }
29
+ var mapObjectToObject = mapObjToObj;
28
30
  function omit(obj, keys) {
29
31
  const result = {};
30
32
  for (const key of Object.keys(obj)) {
@@ -136,16 +138,41 @@ function parsePath(path) {
136
138
  function isNumericString(str) {
137
139
  return /^\d+$/.test(str);
138
140
  }
141
+ function getObjPropertyOrInsert(obj, prop, insertValue) {
142
+ if (obj[prop] === void 0) {
143
+ obj[prop] = insertValue();
144
+ }
145
+ return obj[prop];
146
+ }
147
+ function addPrefixToObjKeys(obj, prefix) {
148
+ const newObj = {};
149
+ for (const [key, value] of Object.entries(obj)) {
150
+ newObj[`${prefix}${key}`] = value;
151
+ }
152
+ return newObj;
153
+ }
154
+ function addSuffixToObjKeys(obj, suffix) {
155
+ const newObj = {};
156
+ for (const [key, value] of Object.entries(obj)) {
157
+ newObj[`${key}${suffix}`] = value;
158
+ }
159
+ return newObj;
160
+ }
139
161
 
140
162
  export {
141
163
  objectTypedEntries,
142
164
  pick,
165
+ mapArrToObj,
143
166
  mapArrayToObject,
167
+ mapObjToObj,
144
168
  mapObjectToObject,
145
169
  omit,
146
170
  looseGetObjectProperty,
147
171
  rejectObjUndefinedValues,
148
172
  filterObjectKeys,
149
173
  sortObjectKeys,
150
- getValueFromPath
174
+ getValueFromPath,
175
+ getObjPropertyOrInsert,
176
+ addPrefixToObjKeys,
177
+ addSuffixToObjKeys
151
178
  };
@@ -9,7 +9,7 @@ import {
9
9
  } from "./chunk-5DZT3Z5Z.js";
10
10
  import {
11
11
  truncateArray
12
- } from "./chunk-BT3UMATU.js";
12
+ } from "./chunk-GVIDV772.js";
13
13
  import {
14
14
  invariant
15
15
  } from "./chunk-C2SVCIWE.js";
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  filterObjectOrArrayKeys
3
- } from "./chunk-LBBC55GE.js";
4
- import "./chunk-BT3UMATU.js";
3
+ } from "./chunk-2LO5FYP5.js";
4
+ import "./chunk-GVIDV772.js";
5
5
  import "./chunk-C2SVCIWE.js";
6
6
  import "./chunk-JF2MDHOJ.js";
7
7
  export {
package/dist/objUtils.cjs CHANGED
@@ -20,10 +20,15 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/objUtils.ts
21
21
  var objUtils_exports = {};
22
22
  __export(objUtils_exports, {
23
+ addPrefixToObjKeys: () => addPrefixToObjKeys,
24
+ addSuffixToObjKeys: () => addSuffixToObjKeys,
23
25
  filterObjectKeys: () => filterObjectKeys,
26
+ getObjPropertyOrInsert: () => getObjPropertyOrInsert,
24
27
  getValueFromPath: () => getValueFromPath,
25
28
  looseGetObjectProperty: () => looseGetObjectProperty,
29
+ mapArrToObj: () => mapArrToObj,
26
30
  mapArrayToObject: () => mapArrayToObject,
31
+ mapObjToObj: () => mapObjToObj,
27
32
  mapObjectToObject: () => mapObjectToObject,
28
33
  objectTypedEntries: () => objectTypedEntries,
29
34
  omit: () => omit,
@@ -76,14 +81,16 @@ function pick(obj, keys) {
76
81
  }
77
82
  return result;
78
83
  }
79
- function mapArrayToObject(array, mapper) {
84
+ function mapArrToObj(array, mapper) {
80
85
  return Object.fromEntries(array.map(mapper));
81
86
  }
82
- function mapObjectToObject(obj, mapper) {
87
+ var mapArrayToObject = mapArrToObj;
88
+ function mapObjToObj(obj, mapper) {
83
89
  return Object.fromEntries(
84
90
  objectTypedEntries(obj).map(([key, value]) => mapper(key, value))
85
91
  );
86
92
  }
93
+ var mapObjectToObject = mapObjToObj;
87
94
  function omit(obj, keys) {
88
95
  const result = {};
89
96
  for (const key of Object.keys(obj)) {
@@ -195,12 +202,37 @@ function parsePath(path) {
195
202
  function isNumericString(str) {
196
203
  return /^\d+$/.test(str);
197
204
  }
205
+ function getObjPropertyOrInsert(obj, prop, insertValue) {
206
+ if (obj[prop] === void 0) {
207
+ obj[prop] = insertValue();
208
+ }
209
+ return obj[prop];
210
+ }
211
+ function addPrefixToObjKeys(obj, prefix) {
212
+ const newObj = {};
213
+ for (const [key, value] of Object.entries(obj)) {
214
+ newObj[`${prefix}${key}`] = value;
215
+ }
216
+ return newObj;
217
+ }
218
+ function addSuffixToObjKeys(obj, suffix) {
219
+ const newObj = {};
220
+ for (const [key, value] of Object.entries(obj)) {
221
+ newObj[`${key}${suffix}`] = value;
222
+ }
223
+ return newObj;
224
+ }
198
225
  // Annotate the CommonJS export names for ESM import in node:
199
226
  0 && (module.exports = {
227
+ addPrefixToObjKeys,
228
+ addSuffixToObjKeys,
200
229
  filterObjectKeys,
230
+ getObjPropertyOrInsert,
201
231
  getValueFromPath,
202
232
  looseGetObjectProperty,
233
+ mapArrToObj,
203
234
  mapArrayToObject,
235
+ mapObjToObj,
204
236
  mapObjectToObject,
205
237
  objectTypedEntries,
206
238
  omit,
@@ -8,13 +8,24 @@ import { MakeUndefinedKeysOptional } from './typeUtils.cjs';
8
8
  */
9
9
  declare function objectTypedEntries<T extends Record<string, unknown>>(obj: T): [Extract<keyof T, string>, T[keyof T]][];
10
10
  declare function pick<T extends Record<string, unknown>, K extends keyof T>(obj: T, keys: K[]): Pick<T, K>;
11
- declare function mapArrayToObject<T, K extends string, O>(array: T[], mapper: (item: T, index: number) => [K, O]): Record<K, O>;
12
- declare function mapObjectToObject<I extends Record<string | number | symbol, unknown>, K extends string | number | symbol, O>(obj: I, mapper: (key: keyof I, value: I[keyof I]) => [K, O]): Record<K, O>;
11
+ declare function mapArrToObj<T, K extends string, O>(array: T[], mapper: (item: T, index: number) => [K, O]): Record<K, O>;
12
+ /** @deprecated Use mapArrToObj instead */
13
+ declare const mapArrayToObject: typeof mapArrToObj;
14
+ declare function mapObjToObj<I extends Record<string | number | symbol, unknown>, K extends string | number | symbol, O>(obj: I, mapper: (key: keyof I, value: I[keyof I]) => [K, O]): Record<K, O>;
15
+ /** @deprecated Use mapObjToObj instead */
16
+ declare const mapObjectToObject: typeof mapObjToObj;
13
17
  declare function omit<T extends Record<string, unknown>, K extends keyof T>(obj: T, keys: K[]): Omit<T, K>;
14
18
  declare function looseGetObjectProperty<T extends Record<string, unknown>>(obj: T, key: string): T[keyof T] | undefined;
15
19
  declare function rejectObjUndefinedValues<T extends Record<string, unknown>>(obj: T): MakeUndefinedKeysOptional<T>;
16
20
  declare function filterObjectKeys<T extends Record<string, unknown>>(obj: T, predicate: (key: keyof T, value: T[keyof T]) => boolean): Partial<T>;
17
21
  declare function sortObjectKeys<T extends Record<string, unknown>>(obj: T, sortByFn: SortByValueFn<[key: keyof T, value: T[keyof T]]>, options?: SortByProps): T;
18
22
  declare function getValueFromPath(obj: Record<string, unknown>, path: string): Result<unknown, Error>;
23
+ declare function getObjPropertyOrInsert<T extends Record<string, any>, K extends keyof T>(obj: T, prop: K, insertValue: () => Exclude<T[K], undefined>): Exclude<T[K], undefined>;
24
+ declare function addPrefixToObjKeys<T extends Record<string, unknown>, P extends string>(obj: T, prefix: P): {
25
+ [K in keyof T & string as `${P}${K}`]: T[K];
26
+ };
27
+ declare function addSuffixToObjKeys<T extends Record<string, unknown>, S extends string>(obj: T, suffix: S): {
28
+ [K in keyof T & string as `${K}${S}`]: T[K];
29
+ };
19
30
 
20
- export { filterObjectKeys, getValueFromPath, looseGetObjectProperty, mapArrayToObject, mapObjectToObject, objectTypedEntries, omit, pick, rejectObjUndefinedValues, sortObjectKeys };
31
+ export { addPrefixToObjKeys, addSuffixToObjKeys, filterObjectKeys, getObjPropertyOrInsert, getValueFromPath, looseGetObjectProperty, mapArrToObj, mapArrayToObject, mapObjToObj, mapObjectToObject, objectTypedEntries, omit, pick, rejectObjUndefinedValues, sortObjectKeys };
@@ -8,13 +8,24 @@ import { MakeUndefinedKeysOptional } from './typeUtils.js';
8
8
  */
9
9
  declare function objectTypedEntries<T extends Record<string, unknown>>(obj: T): [Extract<keyof T, string>, T[keyof T]][];
10
10
  declare function pick<T extends Record<string, unknown>, K extends keyof T>(obj: T, keys: K[]): Pick<T, K>;
11
- declare function mapArrayToObject<T, K extends string, O>(array: T[], mapper: (item: T, index: number) => [K, O]): Record<K, O>;
12
- declare function mapObjectToObject<I extends Record<string | number | symbol, unknown>, K extends string | number | symbol, O>(obj: I, mapper: (key: keyof I, value: I[keyof I]) => [K, O]): Record<K, O>;
11
+ declare function mapArrToObj<T, K extends string, O>(array: T[], mapper: (item: T, index: number) => [K, O]): Record<K, O>;
12
+ /** @deprecated Use mapArrToObj instead */
13
+ declare const mapArrayToObject: typeof mapArrToObj;
14
+ declare function mapObjToObj<I extends Record<string | number | symbol, unknown>, K extends string | number | symbol, O>(obj: I, mapper: (key: keyof I, value: I[keyof I]) => [K, O]): Record<K, O>;
15
+ /** @deprecated Use mapObjToObj instead */
16
+ declare const mapObjectToObject: typeof mapObjToObj;
13
17
  declare function omit<T extends Record<string, unknown>, K extends keyof T>(obj: T, keys: K[]): Omit<T, K>;
14
18
  declare function looseGetObjectProperty<T extends Record<string, unknown>>(obj: T, key: string): T[keyof T] | undefined;
15
19
  declare function rejectObjUndefinedValues<T extends Record<string, unknown>>(obj: T): MakeUndefinedKeysOptional<T>;
16
20
  declare function filterObjectKeys<T extends Record<string, unknown>>(obj: T, predicate: (key: keyof T, value: T[keyof T]) => boolean): Partial<T>;
17
21
  declare function sortObjectKeys<T extends Record<string, unknown>>(obj: T, sortByFn: SortByValueFn<[key: keyof T, value: T[keyof T]]>, options?: SortByProps): T;
18
22
  declare function getValueFromPath(obj: Record<string, unknown>, path: string): Result<unknown, Error>;
23
+ declare function getObjPropertyOrInsert<T extends Record<string, any>, K extends keyof T>(obj: T, prop: K, insertValue: () => Exclude<T[K], undefined>): Exclude<T[K], undefined>;
24
+ declare function addPrefixToObjKeys<T extends Record<string, unknown>, P extends string>(obj: T, prefix: P): {
25
+ [K in keyof T & string as `${P}${K}`]: T[K];
26
+ };
27
+ declare function addSuffixToObjKeys<T extends Record<string, unknown>, S extends string>(obj: T, suffix: S): {
28
+ [K in keyof T & string as `${K}${S}`]: T[K];
29
+ };
19
30
 
20
- export { filterObjectKeys, getValueFromPath, looseGetObjectProperty, mapArrayToObject, mapObjectToObject, objectTypedEntries, omit, pick, rejectObjUndefinedValues, sortObjectKeys };
31
+ export { addPrefixToObjKeys, addSuffixToObjKeys, filterObjectKeys, getObjPropertyOrInsert, getValueFromPath, looseGetObjectProperty, mapArrToObj, mapArrayToObject, mapObjToObj, mapObjectToObject, objectTypedEntries, omit, pick, rejectObjUndefinedValues, sortObjectKeys };
package/dist/objUtils.js CHANGED
@@ -1,24 +1,34 @@
1
1
  import {
2
+ addPrefixToObjKeys,
3
+ addSuffixToObjKeys,
2
4
  filterObjectKeys,
5
+ getObjPropertyOrInsert,
3
6
  getValueFromPath,
4
7
  looseGetObjectProperty,
8
+ mapArrToObj,
5
9
  mapArrayToObject,
10
+ mapObjToObj,
6
11
  mapObjectToObject,
7
12
  objectTypedEntries,
8
13
  omit,
9
14
  pick,
10
15
  rejectObjUndefinedValues,
11
16
  sortObjectKeys
12
- } from "./chunk-WNFRB7P6.js";
17
+ } from "./chunk-SGRS4OEE.js";
13
18
  import "./chunk-GMJTLFM6.js";
14
- import "./chunk-BT3UMATU.js";
19
+ import "./chunk-GVIDV772.js";
15
20
  import "./chunk-C2SVCIWE.js";
16
21
  import "./chunk-JF2MDHOJ.js";
17
22
  export {
23
+ addPrefixToObjKeys,
24
+ addSuffixToObjKeys,
18
25
  filterObjectKeys,
26
+ getObjPropertyOrInsert,
19
27
  getValueFromPath,
20
28
  looseGetObjectProperty,
29
+ mapArrToObj,
21
30
  mapArrayToObject,
31
+ mapObjToObj,
22
32
  mapObjectToObject,
23
33
  objectTypedEntries,
24
34
  omit,
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  filterAndMap
3
- } from "./chunk-BT3UMATU.js";
3
+ } from "./chunk-GVIDV772.js";
4
4
  import "./chunk-C2SVCIWE.js";
5
5
  import {
6
6
  isTruthy
package/dist/testUtils.js CHANGED
@@ -4,11 +4,11 @@ import {
4
4
  import {
5
5
  omit,
6
6
  pick
7
- } from "./chunk-WNFRB7P6.js";
7
+ } from "./chunk-SGRS4OEE.js";
8
8
  import "./chunk-GMJTLFM6.js";
9
9
  import {
10
10
  filterObjectOrArrayKeys
11
- } from "./chunk-LBBC55GE.js";
11
+ } from "./chunk-2LO5FYP5.js";
12
12
  import "./chunk-IATIXMCE.js";
13
13
  import {
14
14
  deepEqual
@@ -26,7 +26,7 @@ import "./chunk-BM4PYVOX.js";
26
26
  import {
27
27
  arrayWithPrevAndIndex,
28
28
  filterAndMap
29
- } from "./chunk-BT3UMATU.js";
29
+ } from "./chunk-GVIDV772.js";
30
30
  import {
31
31
  isObject
32
32
  } from "./chunk-C2SVCIWE.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.58.0",
4
+ "version": "3.59.0",
5
5
  "license": "MIT",
6
6
  "files": [
7
7
  "dist",