@ls-stack/utils 3.55.0 → 3.57.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.
@@ -29,9 +29,11 @@ __export(arrayUtils_exports, {
29
29
  findBeforeIndex: () => findBeforeIndex,
30
30
  getAscIndexOrder: () => getAscIndexOrder,
31
31
  hasDuplicates: () => hasDuplicates,
32
+ intersperse: () => intersperse,
32
33
  isInArray: () => isInArray,
33
34
  rejectArrayUndefinedValues: () => rejectArrayUndefinedValues,
34
35
  rejectDuplicates: () => rejectDuplicates,
36
+ repeat: () => repeat,
35
37
  sortBy: () => sortBy,
36
38
  truncateArray: () => truncateArray
37
39
  });
@@ -176,6 +178,26 @@ function arrayOps(array) {
176
178
  findAndMap: (predicate) => findAndMap(array, predicate)
177
179
  };
178
180
  }
181
+ function intersperse(array, separator) {
182
+ const result = [];
183
+ for (let i = 0; i < array.length; i++) {
184
+ result.push(array[i]);
185
+ if (i < array.length - 1) {
186
+ result.push(separator);
187
+ }
188
+ }
189
+ return result;
190
+ }
191
+ function repeat(value, count, separator) {
192
+ const result = [];
193
+ for (let i = 0; i < count; i++) {
194
+ result.push(value);
195
+ if (separator !== void 0 && i < count - 1) {
196
+ result.push(separator);
197
+ }
198
+ }
199
+ return result;
200
+ }
179
201
  // Annotate the CommonJS export names for ESM import in node:
180
202
  0 && (module.exports = {
181
203
  arrayOps,
@@ -187,9 +209,11 @@ function arrayOps(array) {
187
209
  findBeforeIndex,
188
210
  getAscIndexOrder,
189
211
  hasDuplicates,
212
+ intersperse,
190
213
  isInArray,
191
214
  rejectArrayUndefinedValues,
192
215
  rejectDuplicates,
216
+ repeat,
193
217
  sortBy,
194
218
  truncateArray
195
219
  });
@@ -82,25 +82,6 @@ declare function rejectArrayUndefinedValues<T extends unknown[]>(array: T): T;
82
82
  declare function hasDuplicates<T>(array: T[], getKey?: (item: T) => unknown): boolean;
83
83
  declare function rejectDuplicates<T>(array: T[], getKey?: (item: T) => unknown): T[];
84
84
  declare function truncateArray<T>(array: T[], maxLength: number, appendIfTruncated?: T | ((truncatedCount: number) => T)): T[];
85
- type ArrayOps<T> = {
86
- /**
87
- * Filter and map an array
88
- *
89
- * @example
90
- * const items = [1, 2, 3];
91
- *
92
- * const enhancedItems = arrayOps(items);
93
- *
94
- * enhancedItems.filterAndMap((item) => (item === 2 ? false : item));
95
- *
96
- * @param mapFilter - A function that takes an item and returns a value or
97
- * `false` to reject the item.
98
- */
99
- filterAndMap: <R>(mapFilter: (item: T, index: number) => false | R) => R[];
100
- sortBy: (sortByValue: SortByValueFn<T>, props: SortByProps) => T[];
101
- rejectDuplicates: (getKey: (item: T) => unknown) => T[];
102
- findAndMap: <R>(predicate: (value: T) => R | false) => R | undefined;
103
- };
104
85
  /**
105
86
  * Finds the first item in an array where the predicate returns a non-false
106
87
  * value and returns that mapped value.
@@ -127,6 +108,25 @@ type ArrayOps<T> = {
127
108
  * item matches
128
109
  */
129
110
  declare function findAndMap<T, R>(array: T[], predicate: (value: T) => R | false): R | undefined;
111
+ type ArrayOps<T> = {
112
+ /**
113
+ * Filter and map an array
114
+ *
115
+ * @example
116
+ * const items = [1, 2, 3];
117
+ *
118
+ * const enhancedItems = arrayOps(items);
119
+ *
120
+ * enhancedItems.filterAndMap((item) => (item === 2 ? false : item));
121
+ *
122
+ * @param mapFilter - A function that takes an item and returns a value or
123
+ * `false` to reject the item.
124
+ */
125
+ filterAndMap: <R>(mapFilter: (item: T, index: number) => false | R) => R[];
126
+ sortBy: (sortByValue: SortByValueFn<T>, props: SortByProps) => T[];
127
+ rejectDuplicates: (getKey: (item: T) => unknown) => T[];
128
+ findAndMap: <R>(predicate: (value: T) => R | false) => R | undefined;
129
+ };
130
130
  /**
131
131
  * Enhance an array with extra methods
132
132
  *
@@ -140,5 +140,30 @@ declare function findAndMap<T, R>(array: T[], predicate: (value: T) => R | false
140
140
  * @param array
141
141
  */
142
142
  declare function arrayOps<T>(array: T[]): ArrayOps<T>;
143
+ /**
144
+ * Inserts a separator value between each element in an array.
145
+ *
146
+ * @example
147
+ * intersperse([1, 2, 3], 0); // [1, 0, 2, 0, 3]
148
+ *
149
+ * @param array - The array to intersperse
150
+ * @param separator - The value to insert between elements
151
+ * @returns A new array with separator values inserted between elements
152
+ */
153
+ declare function intersperse<T, I>(array: T[], separator: I): (T | I)[];
154
+ /**
155
+ * Creates an array by repeating a value a specified number of times,
156
+ * optionally with a separator between each repetition.
157
+ *
158
+ * @example
159
+ * repeat('x', 3); // ['x', 'x', 'x']
160
+ * repeat('x', 3, '-'); // ['x', '-', 'x', '-', 'x']
161
+ *
162
+ * @param value - The value to repeat
163
+ * @param count - Number of times to repeat the value
164
+ * @param separator - Optional separator to insert between repetitions
165
+ * @returns A new array with the repeated values
166
+ */
167
+ declare function repeat<T>(value: T, count: number, separator?: T): T[];
143
168
 
144
- export { type FilterAndMapReturn, type SortByProps, type SortByValueFn, arrayOps, arrayWithPrev, arrayWithPrevAndIndex, filterAndMap, findAfterIndex, findAndMap, findBeforeIndex, getAscIndexOrder, hasDuplicates, isInArray, rejectArrayUndefinedValues, rejectDuplicates, sortBy, truncateArray };
169
+ export { type FilterAndMapReturn, type SortByProps, type SortByValueFn, arrayOps, arrayWithPrev, arrayWithPrevAndIndex, filterAndMap, findAfterIndex, findAndMap, findBeforeIndex, getAscIndexOrder, hasDuplicates, intersperse, isInArray, rejectArrayUndefinedValues, rejectDuplicates, repeat, sortBy, truncateArray };
@@ -82,25 +82,6 @@ declare function rejectArrayUndefinedValues<T extends unknown[]>(array: T): T;
82
82
  declare function hasDuplicates<T>(array: T[], getKey?: (item: T) => unknown): boolean;
83
83
  declare function rejectDuplicates<T>(array: T[], getKey?: (item: T) => unknown): T[];
84
84
  declare function truncateArray<T>(array: T[], maxLength: number, appendIfTruncated?: T | ((truncatedCount: number) => T)): T[];
85
- type ArrayOps<T> = {
86
- /**
87
- * Filter and map an array
88
- *
89
- * @example
90
- * const items = [1, 2, 3];
91
- *
92
- * const enhancedItems = arrayOps(items);
93
- *
94
- * enhancedItems.filterAndMap((item) => (item === 2 ? false : item));
95
- *
96
- * @param mapFilter - A function that takes an item and returns a value or
97
- * `false` to reject the item.
98
- */
99
- filterAndMap: <R>(mapFilter: (item: T, index: number) => false | R) => R[];
100
- sortBy: (sortByValue: SortByValueFn<T>, props: SortByProps) => T[];
101
- rejectDuplicates: (getKey: (item: T) => unknown) => T[];
102
- findAndMap: <R>(predicate: (value: T) => R | false) => R | undefined;
103
- };
104
85
  /**
105
86
  * Finds the first item in an array where the predicate returns a non-false
106
87
  * value and returns that mapped value.
@@ -127,6 +108,25 @@ type ArrayOps<T> = {
127
108
  * item matches
128
109
  */
129
110
  declare function findAndMap<T, R>(array: T[], predicate: (value: T) => R | false): R | undefined;
111
+ type ArrayOps<T> = {
112
+ /**
113
+ * Filter and map an array
114
+ *
115
+ * @example
116
+ * const items = [1, 2, 3];
117
+ *
118
+ * const enhancedItems = arrayOps(items);
119
+ *
120
+ * enhancedItems.filterAndMap((item) => (item === 2 ? false : item));
121
+ *
122
+ * @param mapFilter - A function that takes an item and returns a value or
123
+ * `false` to reject the item.
124
+ */
125
+ filterAndMap: <R>(mapFilter: (item: T, index: number) => false | R) => R[];
126
+ sortBy: (sortByValue: SortByValueFn<T>, props: SortByProps) => T[];
127
+ rejectDuplicates: (getKey: (item: T) => unknown) => T[];
128
+ findAndMap: <R>(predicate: (value: T) => R | false) => R | undefined;
129
+ };
130
130
  /**
131
131
  * Enhance an array with extra methods
132
132
  *
@@ -140,5 +140,30 @@ declare function findAndMap<T, R>(array: T[], predicate: (value: T) => R | false
140
140
  * @param array
141
141
  */
142
142
  declare function arrayOps<T>(array: T[]): ArrayOps<T>;
143
+ /**
144
+ * Inserts a separator value between each element in an array.
145
+ *
146
+ * @example
147
+ * intersperse([1, 2, 3], 0); // [1, 0, 2, 0, 3]
148
+ *
149
+ * @param array - The array to intersperse
150
+ * @param separator - The value to insert between elements
151
+ * @returns A new array with separator values inserted between elements
152
+ */
153
+ declare function intersperse<T, I>(array: T[], separator: I): (T | I)[];
154
+ /**
155
+ * Creates an array by repeating a value a specified number of times,
156
+ * optionally with a separator between each repetition.
157
+ *
158
+ * @example
159
+ * repeat('x', 3); // ['x', 'x', 'x']
160
+ * repeat('x', 3, '-'); // ['x', '-', 'x', '-', 'x']
161
+ *
162
+ * @param value - The value to repeat
163
+ * @param count - Number of times to repeat the value
164
+ * @param separator - Optional separator to insert between repetitions
165
+ * @returns A new array with the repeated values
166
+ */
167
+ declare function repeat<T>(value: T, count: number, separator?: T): T[];
143
168
 
144
- export { type FilterAndMapReturn, type SortByProps, type SortByValueFn, arrayOps, arrayWithPrev, arrayWithPrevAndIndex, filterAndMap, findAfterIndex, findAndMap, findBeforeIndex, getAscIndexOrder, hasDuplicates, isInArray, rejectArrayUndefinedValues, rejectDuplicates, sortBy, truncateArray };
169
+ export { type FilterAndMapReturn, type SortByProps, type SortByValueFn, arrayOps, arrayWithPrev, arrayWithPrevAndIndex, filterAndMap, findAfterIndex, findAndMap, findBeforeIndex, getAscIndexOrder, hasDuplicates, intersperse, isInArray, rejectArrayUndefinedValues, rejectDuplicates, repeat, sortBy, truncateArray };
@@ -8,12 +8,14 @@ import {
8
8
  findBeforeIndex,
9
9
  getAscIndexOrder,
10
10
  hasDuplicates,
11
+ intersperse,
11
12
  isInArray,
12
13
  rejectArrayUndefinedValues,
13
14
  rejectDuplicates,
15
+ repeat,
14
16
  sortBy,
15
17
  truncateArray
16
- } from "./chunk-27AL66CH.js";
18
+ } from "./chunk-BT3UMATU.js";
17
19
  import "./chunk-C2SVCIWE.js";
18
20
  import "./chunk-JF2MDHOJ.js";
19
21
  export {
@@ -26,9 +28,11 @@ export {
26
28
  findBeforeIndex,
27
29
  getAscIndexOrder,
28
30
  hasDuplicates,
31
+ intersperse,
29
32
  isInArray,
30
33
  rejectArrayUndefinedValues,
31
34
  rejectDuplicates,
35
+ repeat,
32
36
  sortBy,
33
37
  truncateArray
34
38
  };
@@ -133,6 +133,26 @@ function arrayOps(array) {
133
133
  findAndMap: (predicate) => findAndMap(array, predicate)
134
134
  };
135
135
  }
136
+ function intersperse(array, separator) {
137
+ const result = [];
138
+ for (let i = 0; i < array.length; i++) {
139
+ result.push(array[i]);
140
+ if (i < array.length - 1) {
141
+ result.push(separator);
142
+ }
143
+ }
144
+ return result;
145
+ }
146
+ function repeat(value, count, separator) {
147
+ const result = [];
148
+ for (let i = 0; i < count; i++) {
149
+ result.push(value);
150
+ if (separator !== void 0 && i < count - 1) {
151
+ result.push(separator);
152
+ }
153
+ }
154
+ return result;
155
+ }
136
156
 
137
157
  export {
138
158
  filterAndMap,
@@ -148,5 +168,7 @@ export {
148
168
  rejectDuplicates,
149
169
  truncateArray,
150
170
  findAndMap,
151
- arrayOps
171
+ arrayOps,
172
+ intersperse,
173
+ repeat
152
174
  };
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  sortBy
3
- } from "./chunk-27AL66CH.js";
3
+ } from "./chunk-BT3UMATU.js";
4
4
  import {
5
5
  isPlainObject
6
6
  } from "./chunk-JF2MDHOJ.js";
@@ -3,7 +3,7 @@ import {
3
3
  } from "./chunk-GMJTLFM6.js";
4
4
  import {
5
5
  sortBy
6
- } from "./chunk-27AL66CH.js";
6
+ } from "./chunk-BT3UMATU.js";
7
7
 
8
8
  // src/objUtils.ts
9
9
  import { Result } from "t-result";
@@ -1,15 +1,15 @@
1
- import {
2
- safeJsonStringify
3
- } from "./chunk-VAAMRG4K.js";
4
1
  import {
5
2
  truncateString
6
3
  } from "./chunk-BM4PYVOX.js";
4
+ import {
5
+ safeJsonStringify
6
+ } from "./chunk-VAAMRG4K.js";
7
7
  import {
8
8
  sleep
9
9
  } from "./chunk-5DZT3Z5Z.js";
10
10
  import {
11
11
  truncateArray
12
- } from "./chunk-27AL66CH.js";
12
+ } from "./chunk-BT3UMATU.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-6CG6JZKB.js";
4
- import "./chunk-27AL66CH.js";
3
+ } from "./chunk-LBBC55GE.js";
4
+ import "./chunk-BT3UMATU.js";
5
5
  import "./chunk-C2SVCIWE.js";
6
6
  import "./chunk-JF2MDHOJ.js";
7
7
  export {
@@ -0,0 +1,73 @@
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/iteratorUtils.ts
21
+ var iteratorUtils_exports = {};
22
+ __export(iteratorUtils_exports, {
23
+ enumerate: () => enumerate,
24
+ range: () => range,
25
+ rangeArray: () => rangeArray,
26
+ withIsLast: () => withIsLast,
27
+ withPrevious: () => withPrevious
28
+ });
29
+ module.exports = __toCommonJS(iteratorUtils_exports);
30
+ function* enumerate(iter, start = 0) {
31
+ let index = start;
32
+ for (const item of iter) {
33
+ yield [index, item];
34
+ index++;
35
+ }
36
+ }
37
+ function* withIsLast(array) {
38
+ let index = 0;
39
+ for (const item of array) {
40
+ const isLast = index === array.length - 1;
41
+ yield [isLast, item, index];
42
+ index++;
43
+ }
44
+ }
45
+ function* withPrevious(iter) {
46
+ let prev = void 0;
47
+ for (const current of iter) {
48
+ yield { prev, current };
49
+ prev = current;
50
+ }
51
+ }
52
+ function* range(start, end, step = 1) {
53
+ if (start > end) {
54
+ for (let i = start; i >= end; i -= step) {
55
+ yield i;
56
+ }
57
+ } else {
58
+ for (let i = start; i <= end; i += step) {
59
+ yield i;
60
+ }
61
+ }
62
+ }
63
+ function rangeArray(start, end, step = 1) {
64
+ return [...range(start, end, step)];
65
+ }
66
+ // Annotate the CommonJS export names for ESM import in node:
67
+ 0 && (module.exports = {
68
+ enumerate,
69
+ range,
70
+ rangeArray,
71
+ withIsLast,
72
+ withPrevious
73
+ });
@@ -0,0 +1,10 @@
1
+ declare function enumerate<T>(iter: Iterable<T>, start?: number): Generator<[number, T]>;
2
+ declare function withIsLast<T>(array: T[]): Generator<[isLast: boolean, item: T, index: number]>;
3
+ declare function withPrevious<T>(iter: Iterable<T>): Generator<{
4
+ prev: T | undefined;
5
+ current: T;
6
+ }>;
7
+ declare function range(start: number, end: number, step?: number): Generator<number>;
8
+ declare function rangeArray(start: number, end: number, step?: number): number[];
9
+
10
+ export { enumerate, range, rangeArray, withIsLast, withPrevious };
@@ -0,0 +1,10 @@
1
+ declare function enumerate<T>(iter: Iterable<T>, start?: number): Generator<[number, T]>;
2
+ declare function withIsLast<T>(array: T[]): Generator<[isLast: boolean, item: T, index: number]>;
3
+ declare function withPrevious<T>(iter: Iterable<T>): Generator<{
4
+ prev: T | undefined;
5
+ current: T;
6
+ }>;
7
+ declare function range(start: number, end: number, step?: number): Generator<number>;
8
+ declare function rangeArray(start: number, end: number, step?: number): number[];
9
+
10
+ export { enumerate, range, rangeArray, withIsLast, withPrevious };
@@ -0,0 +1,44 @@
1
+ // src/iteratorUtils.ts
2
+ function* enumerate(iter, start = 0) {
3
+ let index = start;
4
+ for (const item of iter) {
5
+ yield [index, item];
6
+ index++;
7
+ }
8
+ }
9
+ function* withIsLast(array) {
10
+ let index = 0;
11
+ for (const item of array) {
12
+ const isLast = index === array.length - 1;
13
+ yield [isLast, item, index];
14
+ index++;
15
+ }
16
+ }
17
+ function* withPrevious(iter) {
18
+ let prev = void 0;
19
+ for (const current of iter) {
20
+ yield { prev, current };
21
+ prev = current;
22
+ }
23
+ }
24
+ function* range(start, end, step = 1) {
25
+ if (start > end) {
26
+ for (let i = start; i >= end; i -= step) {
27
+ yield i;
28
+ }
29
+ } else {
30
+ for (let i = start; i <= end; i += step) {
31
+ yield i;
32
+ }
33
+ }
34
+ }
35
+ function rangeArray(start, end, step = 1) {
36
+ return [...range(start, end, step)];
37
+ }
38
+ export {
39
+ enumerate,
40
+ range,
41
+ rangeArray,
42
+ withIsLast,
43
+ withPrevious
44
+ };
package/dist/objUtils.js CHANGED
@@ -9,9 +9,9 @@ import {
9
9
  pick,
10
10
  rejectObjUndefinedValues,
11
11
  sortObjectKeys
12
- } from "./chunk-Y76LZUOB.js";
12
+ } from "./chunk-WNFRB7P6.js";
13
13
  import "./chunk-GMJTLFM6.js";
14
- import "./chunk-27AL66CH.js";
14
+ import "./chunk-BT3UMATU.js";
15
15
  import "./chunk-C2SVCIWE.js";
16
16
  import "./chunk-JF2MDHOJ.js";
17
17
  export {
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  filterAndMap
3
- } from "./chunk-27AL66CH.js";
3
+ } from "./chunk-BT3UMATU.js";
4
4
  import "./chunk-C2SVCIWE.js";
5
5
  import {
6
6
  isTruthy
@@ -13,23 +13,41 @@ declare function concatStrings(...args: (Arg | Arg[])[]): string;
13
13
  /** @deprecated Use {@link concatStrings} instead */
14
14
  declare const joinStrings: typeof concatStrings;
15
15
  declare function formatNum(num: number, maxDecimalsOrOptions?: number | Intl.NumberFormatOptions): string;
16
+ /** Check if a string is `snake_case` */
16
17
  declare function isSnakeCase(str: string): boolean;
18
+ /** Check if a string is `kebab-case` */
17
19
  declare function isKebabCase(str: string): boolean;
20
+ /** Check if a string is `PascalCase` */
18
21
  declare function isPascalCase(str: string): boolean;
22
+ /** Check if a string is `camelCase` */
19
23
  declare function isCamelCase(str: string): boolean;
24
+ /** Check if a string is `Title Case` */
20
25
  declare function isTitleCase(str: string): boolean;
26
+ /** Check if a string is `Sentence Case` */
21
27
  declare function isSentenceCase(str: string): boolean;
28
+ /** Check if a string is `CONSTANT_CASE` */
22
29
  declare function isConstantCase(str: string): boolean;
30
+ /** Check if a string is `dot.case` */
23
31
  declare function isDotCase(str: string): boolean;
32
+ /** Check if a string is `path/case` */
24
33
  declare function isPathCase(str: string): boolean;
34
+ /** Convert a string to `kebab-case` */
25
35
  declare function convertToKebabCase(str: string): string;
36
+ /** Convert a string to `snake_case` */
26
37
  declare function convertToSnakeCase(str: string): string;
38
+ /** Convert a string to `PascalCase` */
27
39
  declare function convertToPascalCase(str: string): string;
40
+ /** Convert a string to `camelCase` */
28
41
  declare function convertToCamelCase(str: string): string;
42
+ /** Convert a string to `Sentence Case` */
29
43
  declare function convertToSentenceCase(str: string): string;
44
+ /** Convert a string to `Title Case` */
30
45
  declare function convertToTitleCase(str: string): string;
46
+ /** Convert a string to `CONSTANT_CASE` */
31
47
  declare function convertToConstantCase(str: string): string;
48
+ /** Convert a string to `dot.case` */
32
49
  declare function convertToDotCase(str: string): string;
50
+ /** Convert a string to `path/case` */
33
51
  declare function convertToPathCase(str: string): string;
34
52
  declare function truncateString(str: string, length: number, ellipsis?: string): string;
35
53
  declare function removeANSIColors(str: string): string;
@@ -13,23 +13,41 @@ declare function concatStrings(...args: (Arg | Arg[])[]): string;
13
13
  /** @deprecated Use {@link concatStrings} instead */
14
14
  declare const joinStrings: typeof concatStrings;
15
15
  declare function formatNum(num: number, maxDecimalsOrOptions?: number | Intl.NumberFormatOptions): string;
16
+ /** Check if a string is `snake_case` */
16
17
  declare function isSnakeCase(str: string): boolean;
18
+ /** Check if a string is `kebab-case` */
17
19
  declare function isKebabCase(str: string): boolean;
20
+ /** Check if a string is `PascalCase` */
18
21
  declare function isPascalCase(str: string): boolean;
22
+ /** Check if a string is `camelCase` */
19
23
  declare function isCamelCase(str: string): boolean;
24
+ /** Check if a string is `Title Case` */
20
25
  declare function isTitleCase(str: string): boolean;
26
+ /** Check if a string is `Sentence Case` */
21
27
  declare function isSentenceCase(str: string): boolean;
28
+ /** Check if a string is `CONSTANT_CASE` */
22
29
  declare function isConstantCase(str: string): boolean;
30
+ /** Check if a string is `dot.case` */
23
31
  declare function isDotCase(str: string): boolean;
32
+ /** Check if a string is `path/case` */
24
33
  declare function isPathCase(str: string): boolean;
34
+ /** Convert a string to `kebab-case` */
25
35
  declare function convertToKebabCase(str: string): string;
36
+ /** Convert a string to `snake_case` */
26
37
  declare function convertToSnakeCase(str: string): string;
38
+ /** Convert a string to `PascalCase` */
27
39
  declare function convertToPascalCase(str: string): string;
40
+ /** Convert a string to `camelCase` */
28
41
  declare function convertToCamelCase(str: string): string;
42
+ /** Convert a string to `Sentence Case` */
29
43
  declare function convertToSentenceCase(str: string): string;
44
+ /** Convert a string to `Title Case` */
30
45
  declare function convertToTitleCase(str: string): string;
46
+ /** Convert a string to `CONSTANT_CASE` */
31
47
  declare function convertToConstantCase(str: string): string;
48
+ /** Convert a string to `dot.case` */
32
49
  declare function convertToDotCase(str: string): string;
50
+ /** Convert a string to `path/case` */
33
51
  declare function convertToPathCase(str: string): string;
34
52
  declare function truncateString(str: string, length: number, ellipsis?: string): string;
35
53
  declare function removeANSIColors(str: string): string;
package/dist/testUtils.js CHANGED
@@ -4,11 +4,11 @@ import {
4
4
  import {
5
5
  omit,
6
6
  pick
7
- } from "./chunk-Y76LZUOB.js";
7
+ } from "./chunk-WNFRB7P6.js";
8
8
  import "./chunk-GMJTLFM6.js";
9
9
  import {
10
10
  filterObjectOrArrayKeys
11
- } from "./chunk-6CG6JZKB.js";
11
+ } from "./chunk-LBBC55GE.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-27AL66CH.js";
29
+ } from "./chunk-BT3UMATU.js";
30
30
  import {
31
31
  isObject
32
32
  } from "./chunk-C2SVCIWE.js";
package/dist/timers.cjs CHANGED
@@ -125,9 +125,11 @@ async function waitFor(condition, { polling, timeout }) {
125
125
  cleanup();
126
126
  resolve(result);
127
127
  }
128
- function checkCondition() {
128
+ async function checkCondition() {
129
129
  try {
130
- if (condition()) {
130
+ const result = condition();
131
+ const conditionMet = result instanceof Promise ? await result : result;
132
+ if (conditionMet) {
131
133
  resolveWith(import_t_result.Result.ok(void 0));
132
134
  return true;
133
135
  }
@@ -137,30 +139,49 @@ async function waitFor(condition, { polling, timeout }) {
137
139
  return true;
138
140
  }
139
141
  }
140
- if (checkCondition()) {
141
- return promise;
142
- }
143
- timeoutId = setTimeout(() => {
144
- resolveWith(import_t_result.Result.err(new Error(`Timeout of ${timeout}ms exceeded while waiting for condition`)));
145
- }, timeout);
146
- if (polling === "raf") {
147
- let rafCheck2 = function() {
148
- if (isResolved) return;
149
- if (!checkCondition()) {
150
- rafId = requestAnimationFrame(rafCheck2);
142
+ checkCondition().then((resolved) => {
143
+ if (resolved) {
144
+ return;
145
+ }
146
+ timeoutId = setTimeout(() => {
147
+ resolveWith(
148
+ import_t_result.Result.err(
149
+ new Error(
150
+ `Timeout of ${timeout}ms exceeded while waiting for condition`
151
+ )
152
+ )
153
+ );
154
+ }, timeout);
155
+ if (polling === "raf") {
156
+ let rafCheck2 = function() {
157
+ if (isResolved) return;
158
+ checkCondition().then((conditionResolved) => {
159
+ if (!conditionResolved && !isResolved) {
160
+ rafId = requestAnimationFrame(rafCheck2);
161
+ }
162
+ }).catch(() => {
163
+ });
164
+ };
165
+ var rafCheck = rafCheck2;
166
+ if (typeof requestAnimationFrame === "undefined") {
167
+ resolveWith(
168
+ import_t_result.Result.err(
169
+ new Error(
170
+ "requestAnimationFrame is not available in this environment"
171
+ )
172
+ )
173
+ );
174
+ return;
151
175
  }
152
- };
153
- var rafCheck = rafCheck2;
154
- if (typeof requestAnimationFrame === "undefined") {
155
- resolveWith(import_t_result.Result.err(new Error("requestAnimationFrame is not available in this environment")));
156
- return promise;
176
+ rafId = requestAnimationFrame(rafCheck2);
177
+ } else {
178
+ intervalId = setInterval(() => {
179
+ checkCondition().catch(() => {
180
+ });
181
+ }, polling);
157
182
  }
158
- rafId = requestAnimationFrame(rafCheck2);
159
- } else {
160
- intervalId = setInterval(() => {
161
- checkCondition();
162
- }, polling);
163
- }
183
+ }).catch(() => {
184
+ });
164
185
  return promise;
165
186
  }
166
187
  // Annotate the CommonJS export names for ESM import in node:
package/dist/timers.d.cts CHANGED
@@ -113,7 +113,7 @@ declare function createWaitUntil<T extends NonNullable<unknown>>({ condition, ma
113
113
  callback: (value: T) => void;
114
114
  checkIntervalMs?: number;
115
115
  }): CleanupTimer;
116
- declare function waitFor(condition: () => boolean, { polling, timeout }: {
116
+ declare function waitFor(condition: () => boolean | Promise<boolean>, { polling, timeout }: {
117
117
  polling: number | 'raf';
118
118
  timeout: number;
119
119
  }): Promise<Result<void, Error>>;
package/dist/timers.d.ts CHANGED
@@ -113,7 +113,7 @@ declare function createWaitUntil<T extends NonNullable<unknown>>({ condition, ma
113
113
  callback: (value: T) => void;
114
114
  checkIntervalMs?: number;
115
115
  }): CleanupTimer;
116
- declare function waitFor(condition: () => boolean, { polling, timeout }: {
116
+ declare function waitFor(condition: () => boolean | Promise<boolean>, { polling, timeout }: {
117
117
  polling: number | 'raf';
118
118
  timeout: number;
119
119
  }): Promise<Result<void, Error>>;
package/dist/timers.js CHANGED
@@ -88,9 +88,11 @@ async function waitFor(condition, { polling, timeout }) {
88
88
  cleanup();
89
89
  resolve(result);
90
90
  }
91
- function checkCondition() {
91
+ async function checkCondition() {
92
92
  try {
93
- if (condition()) {
93
+ const result = condition();
94
+ const conditionMet = result instanceof Promise ? await result : result;
95
+ if (conditionMet) {
94
96
  resolveWith(Result.ok(void 0));
95
97
  return true;
96
98
  }
@@ -100,30 +102,49 @@ async function waitFor(condition, { polling, timeout }) {
100
102
  return true;
101
103
  }
102
104
  }
103
- if (checkCondition()) {
104
- return promise;
105
- }
106
- timeoutId = setTimeout(() => {
107
- resolveWith(Result.err(new Error(`Timeout of ${timeout}ms exceeded while waiting for condition`)));
108
- }, timeout);
109
- if (polling === "raf") {
110
- let rafCheck2 = function() {
111
- if (isResolved) return;
112
- if (!checkCondition()) {
113
- rafId = requestAnimationFrame(rafCheck2);
105
+ checkCondition().then((resolved) => {
106
+ if (resolved) {
107
+ return;
108
+ }
109
+ timeoutId = setTimeout(() => {
110
+ resolveWith(
111
+ Result.err(
112
+ new Error(
113
+ `Timeout of ${timeout}ms exceeded while waiting for condition`
114
+ )
115
+ )
116
+ );
117
+ }, timeout);
118
+ if (polling === "raf") {
119
+ let rafCheck2 = function() {
120
+ if (isResolved) return;
121
+ checkCondition().then((conditionResolved) => {
122
+ if (!conditionResolved && !isResolved) {
123
+ rafId = requestAnimationFrame(rafCheck2);
124
+ }
125
+ }).catch(() => {
126
+ });
127
+ };
128
+ var rafCheck = rafCheck2;
129
+ if (typeof requestAnimationFrame === "undefined") {
130
+ resolveWith(
131
+ Result.err(
132
+ new Error(
133
+ "requestAnimationFrame is not available in this environment"
134
+ )
135
+ )
136
+ );
137
+ return;
114
138
  }
115
- };
116
- var rafCheck = rafCheck2;
117
- if (typeof requestAnimationFrame === "undefined") {
118
- resolveWith(Result.err(new Error("requestAnimationFrame is not available in this environment")));
119
- return promise;
139
+ rafId = requestAnimationFrame(rafCheck2);
140
+ } else {
141
+ intervalId = setInterval(() => {
142
+ checkCondition().catch(() => {
143
+ });
144
+ }, polling);
120
145
  }
121
- rafId = requestAnimationFrame(rafCheck2);
122
- } else {
123
- intervalId = setInterval(() => {
124
- checkCondition();
125
- }, polling);
126
- }
146
+ }).catch(() => {
147
+ });
127
148
  return promise;
128
149
  }
129
150
  export {
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.55.0",
4
+ "version": "3.57.0",
5
5
  "license": "MIT",
6
6
  "files": [
7
7
  "dist",
@@ -112,6 +112,10 @@
112
112
  "import": "./dist/interpolate.js",
113
113
  "require": "./dist/interpolate.cjs"
114
114
  },
115
+ "./iteratorUtils": {
116
+ "import": "./dist/iteratorUtils.js",
117
+ "require": "./dist/iteratorUtils.cjs"
118
+ },
115
119
  "./keepPrevIfUnchanged": {
116
120
  "import": "./dist/keepPrevIfUnchanged.js",
117
121
  "require": "./dist/keepPrevIfUnchanged.cjs"