@ls-stack/utils 3.56.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.
- package/dist/arrayUtils.cjs +24 -0
- package/dist/arrayUtils.d.cts +45 -20
- package/dist/arrayUtils.d.ts +45 -20
- package/dist/arrayUtils.js +5 -1
- package/dist/{chunk-27AL66CH.js → chunk-BT3UMATU.js} +23 -1
- package/dist/{chunk-6CG6JZKB.js → chunk-LBBC55GE.js} +1 -1
- package/dist/{chunk-Y76LZUOB.js → chunk-WNFRB7P6.js} +1 -1
- package/dist/concurrentCalls.js +4 -4
- package/dist/filterObjectOrArrayKeys.js +2 -2
- package/dist/iteratorUtils.cjs +73 -0
- package/dist/iteratorUtils.d.cts +10 -0
- package/dist/iteratorUtils.d.ts +10 -0
- package/dist/iteratorUtils.js +44 -0
- package/dist/objUtils.js +2 -2
- package/dist/serializeXML.js +1 -1
- package/dist/testUtils.js +3 -3
- package/package.json +5 -1
package/dist/arrayUtils.cjs
CHANGED
|
@@ -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
|
});
|
package/dist/arrayUtils.d.cts
CHANGED
|
@@ -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 };
|
package/dist/arrayUtils.d.ts
CHANGED
|
@@ -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 };
|
package/dist/arrayUtils.js
CHANGED
|
@@ -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-
|
|
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
|
};
|
package/dist/concurrentCalls.js
CHANGED
|
@@ -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-
|
|
12
|
+
} from "./chunk-BT3UMATU.js";
|
|
13
13
|
import {
|
|
14
14
|
invariant
|
|
15
15
|
} from "./chunk-C2SVCIWE.js";
|
|
@@ -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-
|
|
12
|
+
} from "./chunk-WNFRB7P6.js";
|
|
13
13
|
import "./chunk-GMJTLFM6.js";
|
|
14
|
-
import "./chunk-
|
|
14
|
+
import "./chunk-BT3UMATU.js";
|
|
15
15
|
import "./chunk-C2SVCIWE.js";
|
|
16
16
|
import "./chunk-JF2MDHOJ.js";
|
|
17
17
|
export {
|
package/dist/serializeXML.js
CHANGED
package/dist/testUtils.js
CHANGED
|
@@ -4,11 +4,11 @@ import {
|
|
|
4
4
|
import {
|
|
5
5
|
omit,
|
|
6
6
|
pick
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-WNFRB7P6.js";
|
|
8
8
|
import "./chunk-GMJTLFM6.js";
|
|
9
9
|
import {
|
|
10
10
|
filterObjectOrArrayKeys
|
|
11
|
-
} from "./chunk-
|
|
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-
|
|
29
|
+
} from "./chunk-BT3UMATU.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.
|
|
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"
|