@oscarpalmer/atoms 0.145.0 → 0.147.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/array/from.js +18 -0
- package/dist/array/misc.js +20 -0
- package/dist/atoms.full.js +213 -201
- package/dist/index.js +9 -8
- package/dist/random.js +2 -2
- package/package.json +6 -74
- package/src/array/from.ts +89 -0
- package/src/array/misc.ts +20 -0
- package/src/array/toggle.ts +2 -2
- package/src/array/update.ts +2 -2
- package/src/index.ts +1 -19
- package/src/math.ts +1 -1
- package/src/promise.ts +3 -3
- package/src/random.ts +1 -1
- package/types/array/from.d.ts +41 -0
- package/types/array/misc.d.ts +19 -0
- package/types/array/toggle.d.ts +2 -2
- package/types/array/update.d.ts +2 -2
- package/types/index.d.ts +1 -19
- package/types/math.d.ts +1 -1
- package/types/promise.d.ts +3 -3
- package/types/random.d.ts +1 -1
- package/dist/array/range.js +0 -6
- package/src/array/range.ts +0 -35
- package/types/array/range.d.ts +0 -20
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
function range(first, second, third) {
|
|
2
|
+
const start = typeof second === "number" ? first : 0;
|
|
3
|
+
const end = typeof second === "number" ? second : first;
|
|
4
|
+
const step = typeof third === "number" ? third : 1;
|
|
5
|
+
const values = [];
|
|
6
|
+
if (step === 0) return values;
|
|
7
|
+
if (step > 0) for (let i = start; i < end; i += step) values.push(i);
|
|
8
|
+
else for (let i = start; i > end; i += step) values.push(i);
|
|
9
|
+
return values;
|
|
10
|
+
}
|
|
11
|
+
function times(length, value) {
|
|
12
|
+
if (typeof length !== "number" || length <= 0) return [];
|
|
13
|
+
const isFunction = typeof value === "function";
|
|
14
|
+
const values = [];
|
|
15
|
+
for (let index = 0; index < length; index += 1) values.push(isFunction ? value(index) : value ?? index);
|
|
16
|
+
return values;
|
|
17
|
+
}
|
|
18
|
+
export { range, times };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { exists } from "./exists.js";
|
|
2
|
+
import { filter } from "./filter.js";
|
|
3
|
+
import { find } from "./find.js";
|
|
4
|
+
import { flatten } from "./flatten.js";
|
|
5
|
+
import { range, times } from "./from.js";
|
|
6
|
+
import { getArray } from "./get.js";
|
|
7
|
+
import { indexOf } from "./index-of.js";
|
|
8
|
+
import { chunk } from "../internal/array/chunk.js";
|
|
9
|
+
import { insert } from "./insert.js";
|
|
10
|
+
import { compact } from "../internal/array/compact.js";
|
|
11
|
+
import { shuffle } from "../internal/array/shuffle.js";
|
|
12
|
+
import { partition } from "./partition.js";
|
|
13
|
+
import { push } from "./push.js";
|
|
14
|
+
import { select } from "./select.js";
|
|
15
|
+
import { sort } from "./sort.js";
|
|
16
|
+
import { splice } from "./splice.js";
|
|
17
|
+
import { toSet } from "./to-set.js";
|
|
18
|
+
import { toggle } from "./toggle.js";
|
|
19
|
+
import { update } from "./update.js";
|
|
20
|
+
export { chunk, compact, exists, filter, find, flatten, getArray, indexOf, insert, partition, push, range, select, shuffle, sort, splice, times, toSet, toggle, update };
|
package/dist/atoms.full.js
CHANGED
|
@@ -37,6 +37,168 @@ function getArrayCallbacks(bool, key, value) {
|
|
|
37
37
|
value: getArrayCallback(value)
|
|
38
38
|
};
|
|
39
39
|
}
|
|
40
|
+
function groupValues(array, key, value, arrays) {
|
|
41
|
+
if (!Array.isArray(array) || array.length === 0) return {};
|
|
42
|
+
const { length } = array;
|
|
43
|
+
const callbacks = getArrayCallbacks(void 0, key, value);
|
|
44
|
+
const record = {};
|
|
45
|
+
for (let index = 0; index < length; index += 1) {
|
|
46
|
+
const item = array[index];
|
|
47
|
+
const keyed = callbacks?.keyed?.(item, index, array) ?? index;
|
|
48
|
+
const valued = callbacks?.value?.(item, index, array) ?? item;
|
|
49
|
+
if (arrays) {
|
|
50
|
+
const existing = record[keyed];
|
|
51
|
+
if (existing == null) record[keyed] = [valued];
|
|
52
|
+
else existing.push(valued);
|
|
53
|
+
} else record[keyed] = valued;
|
|
54
|
+
}
|
|
55
|
+
return record;
|
|
56
|
+
}
|
|
57
|
+
function groupBy(array, first, second) {
|
|
58
|
+
return groupValues(array, first, second, false);
|
|
59
|
+
}
|
|
60
|
+
groupBy.arrays = groupArraysBy;
|
|
61
|
+
function groupArraysBy(array, first, second) {
|
|
62
|
+
return groupValues(array, first, second, true);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Chunk an array into smaller arrays
|
|
66
|
+
* @param array Array to chunk
|
|
67
|
+
* @param size Size of each chunk _(minimum is `1`, maximum is `5000`; defaults to `5000`)_
|
|
68
|
+
* @returns Array of arrays
|
|
69
|
+
*/
|
|
70
|
+
function chunk(array, size) {
|
|
71
|
+
if (!Array.isArray(array)) return [];
|
|
72
|
+
if (array.length === 0) return [];
|
|
73
|
+
const { length } = array;
|
|
74
|
+
const actualSize = typeof size === "number" && size > 0 && size <= MAX_SIZE ? size : MAX_SIZE;
|
|
75
|
+
if (length <= actualSize) return [array];
|
|
76
|
+
const chunks = [];
|
|
77
|
+
let index = 0;
|
|
78
|
+
while (index < length) {
|
|
79
|
+
chunks.push(array.slice(index, index + actualSize));
|
|
80
|
+
index += actualSize;
|
|
81
|
+
}
|
|
82
|
+
return chunks;
|
|
83
|
+
}
|
|
84
|
+
const MAX_SIZE = 5e3;
|
|
85
|
+
function compact(array, strict) {
|
|
86
|
+
if (!Array.isArray(array)) return [];
|
|
87
|
+
if (strict === true) return array.filter(Boolean);
|
|
88
|
+
const { length } = array;
|
|
89
|
+
const compacted = [];
|
|
90
|
+
for (let index = 0; index < length; index += 1) {
|
|
91
|
+
const item = array[index];
|
|
92
|
+
if (item != null) compacted.push(item);
|
|
93
|
+
}
|
|
94
|
+
return compacted;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Is the value an array or a record?
|
|
98
|
+
* @param value Value to check
|
|
99
|
+
* @returns `true` if the value is an array or a record, otherwise `false`
|
|
100
|
+
*/
|
|
101
|
+
function isArrayOrPlainObject(value) {
|
|
102
|
+
return Array.isArray(value) || isPlainObject(value);
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Is the value a constructor function?
|
|
106
|
+
* @param value Value to check
|
|
107
|
+
* @returns `true` if the value is a constructor function, otherwise `false`
|
|
108
|
+
*/
|
|
109
|
+
function isConstructor(value) {
|
|
110
|
+
return typeof value === "function" && value.prototype?.constructor === value;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Is the value a key?
|
|
114
|
+
* @param value Value to check
|
|
115
|
+
* @returns `true` if the value is a `Key` _(`number` or `string`)_, otherwise `false`
|
|
116
|
+
*/
|
|
117
|
+
function isKey(value) {
|
|
118
|
+
return typeof value === "number" || typeof value === "string";
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Is the value a number?
|
|
122
|
+
* @param value Value to check
|
|
123
|
+
* @returns `true` if the value is a `number`, otherwise `false`
|
|
124
|
+
*/
|
|
125
|
+
function isNumber(value) {
|
|
126
|
+
return typeof value === "number" && !Number.isNaN(value);
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Is the value a plain object?
|
|
130
|
+
* @param value Value to check
|
|
131
|
+
* @returns `true` if the value is a plain object, otherwise `false`
|
|
132
|
+
*/
|
|
133
|
+
function isPlainObject(value) {
|
|
134
|
+
if (value === null || typeof value !== "object") return false;
|
|
135
|
+
if (Symbol.toStringTag in value || Symbol.iterator in value) return false;
|
|
136
|
+
const prototype = Object.getPrototypeOf(value);
|
|
137
|
+
return prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Is the value a typed array?
|
|
141
|
+
* @param value Value to check
|
|
142
|
+
* @returns `true` if the value is a typed array, otherwise `false`
|
|
143
|
+
*/
|
|
144
|
+
function isTypedArray(value) {
|
|
145
|
+
TYPED_ARRAYS ??= new Set([
|
|
146
|
+
Int8Array,
|
|
147
|
+
Uint8Array,
|
|
148
|
+
Uint8ClampedArray,
|
|
149
|
+
Int16Array,
|
|
150
|
+
Uint16Array,
|
|
151
|
+
Int32Array,
|
|
152
|
+
Uint32Array,
|
|
153
|
+
Float32Array,
|
|
154
|
+
Float64Array,
|
|
155
|
+
BigInt64Array,
|
|
156
|
+
BigUint64Array
|
|
157
|
+
]);
|
|
158
|
+
return TYPED_ARRAYS.has(value?.constructor);
|
|
159
|
+
}
|
|
160
|
+
let TYPED_ARRAYS;
|
|
161
|
+
function _getRandomFloat(inclusive, minimum, maximum) {
|
|
162
|
+
let maxFloat = isNumber(maximum) && maximum <= Number.MAX_SAFE_INTEGER ? maximum : Number.MAX_SAFE_INTEGER;
|
|
163
|
+
let minFloat = isNumber(minimum) && minimum >= Number.MIN_SAFE_INTEGER ? minimum : Number.MIN_SAFE_INTEGER;
|
|
164
|
+
if (minFloat === maxFloat) return minFloat;
|
|
165
|
+
if (minFloat > maxFloat) [minFloat, maxFloat] = [maxFloat, minFloat];
|
|
166
|
+
return Math.random() * (maxFloat + (inclusive ? 1 : 0) - minFloat) + minFloat;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Get a random floating-point number
|
|
170
|
+
* @param minimum Minimum value
|
|
171
|
+
* @param maximum Maximum value
|
|
172
|
+
* @returns Random floating-point number
|
|
173
|
+
*/
|
|
174
|
+
function getRandomFloat(minimum, maximum) {
|
|
175
|
+
return _getRandomFloat(false, minimum, maximum);
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Get a random integer
|
|
179
|
+
* @param minimum Minimum value
|
|
180
|
+
* @param maximum Maximum value
|
|
181
|
+
* @returns Random integer
|
|
182
|
+
*/
|
|
183
|
+
function getRandomInteger(minimum, maximum) {
|
|
184
|
+
return Math.floor(_getRandomFloat(true, minimum, maximum));
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Shuffle items in array
|
|
188
|
+
* @param array Original array
|
|
189
|
+
* @returns Shuffled array
|
|
190
|
+
*/
|
|
191
|
+
function shuffle(array) {
|
|
192
|
+
if (!Array.isArray(array)) return [];
|
|
193
|
+
const shuffled = [...array];
|
|
194
|
+
if (shuffled.length < 2) return shuffled;
|
|
195
|
+
let index = Number(shuffled.length);
|
|
196
|
+
while (--index >= 0) {
|
|
197
|
+
const random = getRandomInteger(0, index);
|
|
198
|
+
[shuffled[index], shuffled[random]] = [shuffled[random], shuffled[index]];
|
|
199
|
+
}
|
|
200
|
+
return shuffled;
|
|
201
|
+
}
|
|
40
202
|
function findValue(type, array, parameters) {
|
|
41
203
|
const findIndex = type === "index";
|
|
42
204
|
if (!Array.isArray(array) || array.length === 0) return findIndex ? -1 : void 0;
|
|
@@ -122,71 +284,23 @@ function find(array, ...parameters) {
|
|
|
122
284
|
function flatten(array) {
|
|
123
285
|
return Array.isArray(array) ? array.flat(Number.POSITIVE_INFINITY) : [];
|
|
124
286
|
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
* Is the value a constructor function?
|
|
135
|
-
* @param value Value to check
|
|
136
|
-
* @returns `true` if the value is a constructor function, otherwise `false`
|
|
137
|
-
*/
|
|
138
|
-
function isConstructor(value) {
|
|
139
|
-
return typeof value === "function" && value.prototype?.constructor === value;
|
|
140
|
-
}
|
|
141
|
-
/**
|
|
142
|
-
* Is the value a key?
|
|
143
|
-
* @param value Value to check
|
|
144
|
-
* @returns `true` if the value is a `Key` _(`number` or `string`)_, otherwise `false`
|
|
145
|
-
*/
|
|
146
|
-
function isKey(value) {
|
|
147
|
-
return typeof value === "number" || typeof value === "string";
|
|
148
|
-
}
|
|
149
|
-
/**
|
|
150
|
-
* Is the value a number?
|
|
151
|
-
* @param value Value to check
|
|
152
|
-
* @returns `true` if the value is a `number`, otherwise `false`
|
|
153
|
-
*/
|
|
154
|
-
function isNumber(value) {
|
|
155
|
-
return typeof value === "number" && !Number.isNaN(value);
|
|
156
|
-
}
|
|
157
|
-
/**
|
|
158
|
-
* Is the value a plain object?
|
|
159
|
-
* @param value Value to check
|
|
160
|
-
* @returns `true` if the value is a plain object, otherwise `false`
|
|
161
|
-
*/
|
|
162
|
-
function isPlainObject(value) {
|
|
163
|
-
if (value === null || typeof value !== "object") return false;
|
|
164
|
-
if (Symbol.toStringTag in value || Symbol.iterator in value) return false;
|
|
165
|
-
const prototype = Object.getPrototypeOf(value);
|
|
166
|
-
return prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null;
|
|
287
|
+
function range(first, second, third) {
|
|
288
|
+
const start = typeof second === "number" ? first : 0;
|
|
289
|
+
const end = typeof second === "number" ? second : first;
|
|
290
|
+
const step = typeof third === "number" ? third : 1;
|
|
291
|
+
const values = [];
|
|
292
|
+
if (step === 0) return values;
|
|
293
|
+
if (step > 0) for (let i = start; i < end; i += step) values.push(i);
|
|
294
|
+
else for (let i = start; i > end; i += step) values.push(i);
|
|
295
|
+
return values;
|
|
167
296
|
}
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
TYPED_ARRAYS ??= new Set([
|
|
175
|
-
Int8Array,
|
|
176
|
-
Uint8Array,
|
|
177
|
-
Uint8ClampedArray,
|
|
178
|
-
Int16Array,
|
|
179
|
-
Uint16Array,
|
|
180
|
-
Int32Array,
|
|
181
|
-
Uint32Array,
|
|
182
|
-
Float32Array,
|
|
183
|
-
Float64Array,
|
|
184
|
-
BigInt64Array,
|
|
185
|
-
BigUint64Array
|
|
186
|
-
]);
|
|
187
|
-
return TYPED_ARRAYS.has(value?.constructor);
|
|
297
|
+
function times(length, value) {
|
|
298
|
+
if (typeof length !== "number" || length <= 0) return [];
|
|
299
|
+
const isFunction = typeof value === "function";
|
|
300
|
+
const values = [];
|
|
301
|
+
for (let index = 0; index < length; index += 1) values.push(isFunction ? value(index) : value ?? index);
|
|
302
|
+
return values;
|
|
188
303
|
}
|
|
189
|
-
let TYPED_ARRAYS;
|
|
190
304
|
function getArray(value, indiced) {
|
|
191
305
|
if (Array.isArray(value)) return value;
|
|
192
306
|
if (value instanceof Map || value instanceof Set) return [...value.values()];
|
|
@@ -201,54 +315,9 @@ function getArray(value, indiced) {
|
|
|
201
315
|
}
|
|
202
316
|
return array;
|
|
203
317
|
}
|
|
204
|
-
function groupValues(array, key, value, arrays) {
|
|
205
|
-
if (!Array.isArray(array) || array.length === 0) return {};
|
|
206
|
-
const { length } = array;
|
|
207
|
-
const callbacks = getArrayCallbacks(void 0, key, value);
|
|
208
|
-
const record = {};
|
|
209
|
-
for (let index = 0; index < length; index += 1) {
|
|
210
|
-
const item = array[index];
|
|
211
|
-
const keyed = callbacks?.keyed?.(item, index, array) ?? index;
|
|
212
|
-
const valued = callbacks?.value?.(item, index, array) ?? item;
|
|
213
|
-
if (arrays) {
|
|
214
|
-
const existing = record[keyed];
|
|
215
|
-
if (existing == null) record[keyed] = [valued];
|
|
216
|
-
else existing.push(valued);
|
|
217
|
-
} else record[keyed] = valued;
|
|
218
|
-
}
|
|
219
|
-
return record;
|
|
220
|
-
}
|
|
221
|
-
function groupBy(array, first, second) {
|
|
222
|
-
return groupValues(array, first, second, false);
|
|
223
|
-
}
|
|
224
|
-
groupBy.arrays = groupArraysBy;
|
|
225
|
-
function groupArraysBy(array, first, second) {
|
|
226
|
-
return groupValues(array, first, second, true);
|
|
227
|
-
}
|
|
228
318
|
function indexOf(array, ...parameters) {
|
|
229
319
|
return findValue("index", array, parameters);
|
|
230
320
|
}
|
|
231
|
-
/**
|
|
232
|
-
* Chunk an array into smaller arrays
|
|
233
|
-
* @param array Array to chunk
|
|
234
|
-
* @param size Size of each chunk _(minimum is `1`, maximum is `5000`; defaults to `5000`)_
|
|
235
|
-
* @returns Array of arrays
|
|
236
|
-
*/
|
|
237
|
-
function chunk(array, size) {
|
|
238
|
-
if (!Array.isArray(array)) return [];
|
|
239
|
-
if (array.length === 0) return [];
|
|
240
|
-
const { length } = array;
|
|
241
|
-
const actualSize = typeof size === "number" && size > 0 && size <= MAX_SIZE ? size : MAX_SIZE;
|
|
242
|
-
if (length <= actualSize) return [array];
|
|
243
|
-
const chunks = [];
|
|
244
|
-
let index = 0;
|
|
245
|
-
while (index < length) {
|
|
246
|
-
chunks.push(array.slice(index, index + actualSize));
|
|
247
|
-
index += actualSize;
|
|
248
|
-
}
|
|
249
|
-
return chunks;
|
|
250
|
-
}
|
|
251
|
-
const MAX_SIZE = 5e3;
|
|
252
321
|
function insertChunkedValues(type, array, items, start, deleteCount) {
|
|
253
322
|
const actualDeleteCount = deleteCount < 0 ? 0 : deleteCount;
|
|
254
323
|
const actualStart = Math.min(Math.max(0, start), array.length);
|
|
@@ -286,11 +355,6 @@ function partition(array, ...parameters) {
|
|
|
286
355
|
function push(array, pushed) {
|
|
287
356
|
return insertValues("push", array, pushed, array.length, 0);
|
|
288
357
|
}
|
|
289
|
-
function range(length, value) {
|
|
290
|
-
if (typeof length !== "number" || length <= 0) return [];
|
|
291
|
-
const isFunction = typeof value === "function";
|
|
292
|
-
return Array.from({ length }, (_, index) => isFunction ? value(index) : value ?? index);
|
|
293
|
-
}
|
|
294
358
|
function select(array, ...parameters) {
|
|
295
359
|
return findValues("all", array, parameters, parameters.pop()).matched;
|
|
296
360
|
}
|
|
@@ -338,17 +402,6 @@ const aggregators = {
|
|
|
338
402
|
min: (current, value, notNumber) => notNumber || value < current ? value : current,
|
|
339
403
|
sum: calculateSum
|
|
340
404
|
};
|
|
341
|
-
function compact(array, strict) {
|
|
342
|
-
if (!Array.isArray(array)) return [];
|
|
343
|
-
if (strict === true) return array.filter(Boolean);
|
|
344
|
-
const { length } = array;
|
|
345
|
-
const compacted = [];
|
|
346
|
-
for (let index = 0; index < length; index += 1) {
|
|
347
|
-
const item = array[index];
|
|
348
|
-
if (item != null) compacted.push(item);
|
|
349
|
-
}
|
|
350
|
-
return compacted;
|
|
351
|
-
}
|
|
352
405
|
/**
|
|
353
406
|
* Get the string value from any value
|
|
354
407
|
* @param value Original value
|
|
@@ -578,37 +631,6 @@ function sort(array, first, second) {
|
|
|
578
631
|
function splice(array, start, deleteCountOrItems, items) {
|
|
579
632
|
return insertValues("splice", array, typeof deleteCountOrItems === "number" ? items : deleteCountOrItems, start, typeof deleteCountOrItems === "number" ? deleteCountOrItems : 0);
|
|
580
633
|
}
|
|
581
|
-
function getMapValues(array, first, second, arrays) {
|
|
582
|
-
if (!Array.isArray(array)) return /* @__PURE__ */ new Map();
|
|
583
|
-
const { length } = array;
|
|
584
|
-
const callbacks = getArrayCallbacks(void 0, first, second);
|
|
585
|
-
const map = /* @__PURE__ */ new Map();
|
|
586
|
-
for (let index = 0; index < length; index += 1) {
|
|
587
|
-
const item = array[index];
|
|
588
|
-
const key = callbacks?.keyed?.(item, index, array) ?? index;
|
|
589
|
-
const value = callbacks?.value?.(item, index, array) ?? item;
|
|
590
|
-
if (arrays) {
|
|
591
|
-
const existing = map.get(key);
|
|
592
|
-
if (existing == null) map.set(key, [value]);
|
|
593
|
-
else existing.push(value);
|
|
594
|
-
} else map.set(key, value);
|
|
595
|
-
}
|
|
596
|
-
return map;
|
|
597
|
-
}
|
|
598
|
-
function toMap(array, first, second) {
|
|
599
|
-
return getMapValues(array, first, second, false);
|
|
600
|
-
}
|
|
601
|
-
toMap.arrays = toMapArrays;
|
|
602
|
-
function toMapArrays(array, first, second) {
|
|
603
|
-
return getMapValues(array, first, second, true);
|
|
604
|
-
}
|
|
605
|
-
function toRecord(array, first, second) {
|
|
606
|
-
return groupValues(array, first, second, false);
|
|
607
|
-
}
|
|
608
|
-
toRecord.arrays = toRecordArrays;
|
|
609
|
-
function toRecordArrays(array, first, second) {
|
|
610
|
-
return groupValues(array, first, second, true);
|
|
611
|
-
}
|
|
612
634
|
function toSet(array, value) {
|
|
613
635
|
if (!Array.isArray(array)) return /* @__PURE__ */ new Set();
|
|
614
636
|
const callbacks = getArrayCallbacks(void 0, void 0, value);
|
|
@@ -641,13 +663,44 @@ function updateInArray(array, items, key, replace) {
|
|
|
641
663
|
function toggle(array, values, key) {
|
|
642
664
|
return updateInArray(array, values, key, false);
|
|
643
665
|
}
|
|
666
|
+
function update(array, values, key) {
|
|
667
|
+
return updateInArray(array, values, key, true);
|
|
668
|
+
}
|
|
669
|
+
function getMapValues(array, first, second, arrays) {
|
|
670
|
+
if (!Array.isArray(array)) return /* @__PURE__ */ new Map();
|
|
671
|
+
const { length } = array;
|
|
672
|
+
const callbacks = getArrayCallbacks(void 0, first, second);
|
|
673
|
+
const map = /* @__PURE__ */ new Map();
|
|
674
|
+
for (let index = 0; index < length; index += 1) {
|
|
675
|
+
const item = array[index];
|
|
676
|
+
const key = callbacks?.keyed?.(item, index, array) ?? index;
|
|
677
|
+
const value = callbacks?.value?.(item, index, array) ?? item;
|
|
678
|
+
if (arrays) {
|
|
679
|
+
const existing = map.get(key);
|
|
680
|
+
if (existing == null) map.set(key, [value]);
|
|
681
|
+
else existing.push(value);
|
|
682
|
+
} else map.set(key, value);
|
|
683
|
+
}
|
|
684
|
+
return map;
|
|
685
|
+
}
|
|
686
|
+
function toMap(array, first, second) {
|
|
687
|
+
return getMapValues(array, first, second, false);
|
|
688
|
+
}
|
|
689
|
+
toMap.arrays = toMapArrays;
|
|
690
|
+
function toMapArrays(array, first, second) {
|
|
691
|
+
return getMapValues(array, first, second, true);
|
|
692
|
+
}
|
|
693
|
+
function toRecord(array, first, second) {
|
|
694
|
+
return groupValues(array, first, second, false);
|
|
695
|
+
}
|
|
696
|
+
toRecord.arrays = toRecordArrays;
|
|
697
|
+
function toRecordArrays(array, first, second) {
|
|
698
|
+
return groupValues(array, first, second, true);
|
|
699
|
+
}
|
|
644
700
|
function unique(array, key) {
|
|
645
701
|
if (!Array.isArray(array)) return [];
|
|
646
702
|
return array.length > 1 ? findValues("unique", array, [key, void 0]).matched : array;
|
|
647
703
|
}
|
|
648
|
-
function update(array, values, key) {
|
|
649
|
-
return updateInArray(array, values, key, true);
|
|
650
|
-
}
|
|
651
704
|
function getLimiter(callback, throttler, time) {
|
|
652
705
|
const interval = typeof time === "number" && time >= frame_rate_default ? time : frame_rate_default;
|
|
653
706
|
function step(now, parameters) {
|
|
@@ -959,47 +1012,6 @@ const MESSAGE_FLOW = "Flow expected to receive an array of functions";
|
|
|
959
1012
|
const MESSAGE_PIPE = "Pipe expected to receive an array of functions";
|
|
960
1013
|
const assertFlowFunctions = assert.condition((value) => Array.isArray(value) && value.every((item) => typeof item === "function"), MESSAGE_FLOW, TypeError);
|
|
961
1014
|
const assertPipeFunctions = assert.condition((value) => Array.isArray(value) && value.every((item) => typeof item === "function"), MESSAGE_PIPE, TypeError);
|
|
962
|
-
function _getRandomFloat(inclusive, minimum, maximum) {
|
|
963
|
-
let maxFloat = isNumber(maximum) && maximum <= Number.MAX_SAFE_INTEGER ? maximum : Number.MAX_SAFE_INTEGER;
|
|
964
|
-
let minFloat = isNumber(minimum) && minimum >= Number.MIN_SAFE_INTEGER ? minimum : Number.MIN_SAFE_INTEGER;
|
|
965
|
-
if (minFloat === maxFloat) return minFloat;
|
|
966
|
-
if (minFloat > maxFloat) [minFloat, maxFloat] = [maxFloat, minFloat];
|
|
967
|
-
return Math.random() * (maxFloat + (inclusive ? 1 : 0) - minFloat) + minFloat;
|
|
968
|
-
}
|
|
969
|
-
/**
|
|
970
|
-
* Get a random floating-point number
|
|
971
|
-
* @param minimum Minimum value
|
|
972
|
-
* @param maximum Maximum value
|
|
973
|
-
* @returns Random floating-point number
|
|
974
|
-
*/
|
|
975
|
-
function getRandomFloat(minimum, maximum) {
|
|
976
|
-
return _getRandomFloat(false, minimum, maximum);
|
|
977
|
-
}
|
|
978
|
-
/**
|
|
979
|
-
* Get a random integer
|
|
980
|
-
* @param minimum Minimum value
|
|
981
|
-
* @param maximum Maximum value
|
|
982
|
-
* @returns Random integer
|
|
983
|
-
*/
|
|
984
|
-
function getRandomInteger(minimum, maximum) {
|
|
985
|
-
return Math.floor(_getRandomFloat(true, minimum, maximum));
|
|
986
|
-
}
|
|
987
|
-
/**
|
|
988
|
-
* Shuffle items in array
|
|
989
|
-
* @param array Original array
|
|
990
|
-
* @returns Shuffled array
|
|
991
|
-
*/
|
|
992
|
-
function shuffle(array) {
|
|
993
|
-
if (!Array.isArray(array)) return [];
|
|
994
|
-
const shuffled = [...array];
|
|
995
|
-
if (shuffled.length < 2) return shuffled;
|
|
996
|
-
let index = Number(shuffled.length);
|
|
997
|
-
while (--index >= 0) {
|
|
998
|
-
const random = getRandomInteger(0, index);
|
|
999
|
-
[shuffled[index], shuffled[random]] = [shuffled[random], shuffled[index]];
|
|
1000
|
-
}
|
|
1001
|
-
return shuffled;
|
|
1002
|
-
}
|
|
1003
1015
|
/**
|
|
1004
1016
|
* A function that does nothing, which can be useful, I guess…
|
|
1005
1017
|
*/
|
|
@@ -3431,7 +3443,7 @@ const MESSAGE_MAXIMUM = "Queue has reached its maximum size";
|
|
|
3431
3443
|
const MESSAGE_REMOVE = "Item removed from queue";
|
|
3432
3444
|
/**
|
|
3433
3445
|
* Get a random boolean
|
|
3434
|
-
* @
|
|
3446
|
+
* @returns Random boolean
|
|
3435
3447
|
*/
|
|
3436
3448
|
function getRandomBoolean() {
|
|
3437
3449
|
return Math.random() > BOOLEAN_MODIFIER;
|
|
@@ -3601,4 +3613,4 @@ var SizedSet = class extends Set {
|
|
|
3601
3613
|
}
|
|
3602
3614
|
}
|
|
3603
3615
|
};
|
|
3604
|
-
export { CancelablePromise, frame_rate_default as FRAME_RATE_MS, PromiseTimeoutError, QueueError, SizedMap, SizedSet, attempt, attemptPromise, average, beacon, between, camelCase, cancelable, capitalize, ceil, chunk, clamp, clone, compact, compare, count, debounce, delay, diff, endsWith, equal, error, exists, filter, find, flatten, floor, flow, fromQuery, getArray, getColor, getForegroundColor, getHexColor, getHexaColor, getHslColor, getHslaColor, getNormalizedHex, getNumber, getRandomBoolean, getRandomCharacters, getRandomColor, getRandomFloat, getRandomHex, getRandomInteger, getRandomItem, getRandomItems, getRgbColor, getRgbaColor, getString, getUuid, getValue, groupBy, hexToHsl, hexToHsla, hexToRgb, hexToRgba, hslToHex, hslToRgb, hslToRgba, ignoreKey, includes, indexOf, insert, isArrayOrPlainObject, isColor, isConstructor, isEmpty, isError, isFulfilled, isHexColor, isHslColor, isHslLike, isHslaColor, isInstanceOf, isKey, isNonNullable, isNullable, isNullableOrEmpty, isNullableOrWhitespace, isNumber, isNumerical, isObject, isOk, isPlainObject, isPrimitive, isRejected, isResult, isRgbColor, isRgbLike, isRgbaColor, isTypedArray, join, kebabCase, logger, lowerCase, max, median, memoize, merge, min, noop, ok, omit, parse, partition, pascalCase, pick, pipe, promises, push, queue, range, rgbToHex, rgbToHsl, rgbToHsla, round, select, setValue, shuffle, smush, snakeCase, sort, splice, startsWith, sum, template, throttle, timed, titleCase, toMap, toQuery, toRecord, toSet, toggle, trim, truncate, tryDecode, tryEncode, unique, unsmush, unwrap, update, upperCase, words };
|
|
3616
|
+
export { CancelablePromise, frame_rate_default as FRAME_RATE_MS, PromiseTimeoutError, QueueError, SizedMap, SizedSet, attempt, attemptPromise, average, beacon, between, camelCase, cancelable, capitalize, ceil, chunk, clamp, clone, compact, compare, count, debounce, delay, diff, endsWith, equal, error, exists, filter, find, flatten, floor, flow, fromQuery, getArray, getColor, getForegroundColor, getHexColor, getHexaColor, getHslColor, getHslaColor, getNormalizedHex, getNumber, getRandomBoolean, getRandomCharacters, getRandomColor, getRandomFloat, getRandomHex, getRandomInteger, getRandomItem, getRandomItems, getRgbColor, getRgbaColor, getString, getUuid, getValue, groupBy, hexToHsl, hexToHsla, hexToRgb, hexToRgba, hslToHex, hslToRgb, hslToRgba, ignoreKey, includes, indexOf, insert, isArrayOrPlainObject, isColor, isConstructor, isEmpty, isError, isFulfilled, isHexColor, isHslColor, isHslLike, isHslaColor, isInstanceOf, isKey, isNonNullable, isNullable, isNullableOrEmpty, isNullableOrWhitespace, isNumber, isNumerical, isObject, isOk, isPlainObject, isPrimitive, isRejected, isResult, isRgbColor, isRgbLike, isRgbaColor, isTypedArray, join, kebabCase, logger, lowerCase, max, median, memoize, merge, min, noop, ok, omit, parse, partition, pascalCase, pick, pipe, promises, push, queue, range, rgbToHex, rgbToHsl, rgbToHsla, round, select, setValue, shuffle, smush, snakeCase, sort, splice, startsWith, sum, template, throttle, timed, times, titleCase, toMap, toQuery, toRecord, toSet, toggle, trim, truncate, tryDecode, tryEncode, unique, unsmush, unwrap, update, upperCase, words };
|
package/dist/index.js
CHANGED
|
@@ -2,28 +2,31 @@ import { exists } from "./array/exists.js";
|
|
|
2
2
|
import { filter } from "./array/filter.js";
|
|
3
3
|
import { find } from "./array/find.js";
|
|
4
4
|
import { flatten } from "./array/flatten.js";
|
|
5
|
+
import { range, times } from "./array/from.js";
|
|
5
6
|
import { isArrayOrPlainObject, isConstructor, isKey, isNumber, isPlainObject, isTypedArray } from "./internal/is.js";
|
|
6
7
|
import { getArray } from "./array/get.js";
|
|
7
8
|
import { groupBy } from "./array/group-by.js";
|
|
8
9
|
import { indexOf } from "./array/index-of.js";
|
|
9
10
|
import { chunk } from "./internal/array/chunk.js";
|
|
10
11
|
import { insert } from "./array/insert.js";
|
|
12
|
+
import { compact } from "./internal/array/compact.js";
|
|
13
|
+
import { getRandomFloat, getRandomInteger } from "./internal/random.js";
|
|
14
|
+
import { shuffle } from "./internal/array/shuffle.js";
|
|
11
15
|
import { partition } from "./array/partition.js";
|
|
12
16
|
import { push } from "./array/push.js";
|
|
13
|
-
import { range } from "./array/range.js";
|
|
14
17
|
import { select } from "./array/select.js";
|
|
15
18
|
import { max } from "./internal/math/aggregate.js";
|
|
16
|
-
import { compact } from "./internal/array/compact.js";
|
|
17
19
|
import { getString, ignoreKey, join, tryDecode, tryEncode, words } from "./internal/string.js";
|
|
18
20
|
import { compare } from "./internal/value/compare.js";
|
|
19
21
|
import { sort } from "./array/sort.js";
|
|
20
22
|
import { splice } from "./array/splice.js";
|
|
21
|
-
import { toMap } from "./array/to-map.js";
|
|
22
|
-
import { toRecord } from "./array/to-record.js";
|
|
23
23
|
import { toSet } from "./array/to-set.js";
|
|
24
24
|
import { toggle } from "./array/toggle.js";
|
|
25
|
-
import { unique } from "./array/unique.js";
|
|
26
25
|
import { update } from "./array/update.js";
|
|
26
|
+
import "./array/misc.js";
|
|
27
|
+
import { toMap } from "./array/to-map.js";
|
|
28
|
+
import { toRecord } from "./array/to-record.js";
|
|
29
|
+
import { unique } from "./array/unique.js";
|
|
27
30
|
import { noop } from "./internal/function/misc.js";
|
|
28
31
|
import { beacon } from "./beacon.js";
|
|
29
32
|
import { between, clamp, getNumber } from "./internal/number.js";
|
|
@@ -39,8 +42,6 @@ import { SizedMap } from "./sized/map.js";
|
|
|
39
42
|
import { memoize } from "./function/memoize.js";
|
|
40
43
|
import { throttle } from "./function/throttle.js";
|
|
41
44
|
import { flow, pipe } from "./function/work.js";
|
|
42
|
-
import { getRandomFloat, getRandomInteger } from "./internal/random.js";
|
|
43
|
-
import { shuffle } from "./internal/array/shuffle.js";
|
|
44
45
|
import { equal } from "./internal/value/equal.js";
|
|
45
46
|
import { getValue } from "./internal/value/get.js";
|
|
46
47
|
import { setValue } from "./internal/value/set.js";
|
|
@@ -64,4 +65,4 @@ import { QueueError, queue } from "./queue.js";
|
|
|
64
65
|
import { getRandomBoolean, getRandomCharacters, getRandomColor, getRandomHex, getRandomItem, getRandomItems } from "./random.js";
|
|
65
66
|
import { attempt, error, isError, isOk, isResult, ok, unwrap } from "./result.js";
|
|
66
67
|
import { SizedSet } from "./sized/set.js";
|
|
67
|
-
export { CancelablePromise, frame_rate_default as FRAME_RATE_MS, PromiseTimeoutError, QueueError, SizedMap, SizedSet, attempt, attemptPromise, average, beacon, between, camelCase, cancelable, capitalize, ceil, chunk, clamp, clone, compact, compare, count, debounce, delay, diff, endsWith, equal, error, exists, filter, find, flatten, floor, flow, fromQuery, getArray, getColor, getForegroundColor, getHexColor, getHexaColor, getHslColor, getHslaColor, getNormalizedHex, getNumber, getRandomBoolean, getRandomCharacters, getRandomColor, getRandomFloat, getRandomHex, getRandomInteger, getRandomItem, getRandomItems, getRgbColor, getRgbaColor, getString, getUuid, getValue, groupBy, hexToHsl, hexToHsla, hexToRgb, hexToRgba, hslToHex, hslToRgb, hslToRgba, ignoreKey, includes, indexOf, insert, isArrayOrPlainObject, isColor, isConstructor, isEmpty, isError, isFulfilled, isHexColor, isHslColor, isHslLike, isHslaColor, isInstanceOf, isKey, isNonNullable, isNullable, isNullableOrEmpty, isNullableOrWhitespace, isNumber, isNumerical, isObject, isOk, isPlainObject, isPrimitive, isRejected, isResult, isRgbColor, isRgbLike, isRgbaColor, isTypedArray, join, kebabCase, logger, lowerCase, max, median, memoize, merge, min, noop, ok, omit, parse, partition, pascalCase, pick, pipe, promises, push, queue, range, rgbToHex, rgbToHsl, rgbToHsla, round, select, setValue, shuffle, smush, snakeCase, sort, splice, startsWith, sum, template, throttle, timed, titleCase, toMap, toQuery, toRecord, toSet, toggle, trim, truncate, tryDecode, tryEncode, unique, unsmush, unwrap, update, upperCase, words };
|
|
68
|
+
export { CancelablePromise, frame_rate_default as FRAME_RATE_MS, PromiseTimeoutError, QueueError, SizedMap, SizedSet, attempt, attemptPromise, average, beacon, between, camelCase, cancelable, capitalize, ceil, chunk, clamp, clone, compact, compare, count, debounce, delay, diff, endsWith, equal, error, exists, filter, find, flatten, floor, flow, fromQuery, getArray, getColor, getForegroundColor, getHexColor, getHexaColor, getHslColor, getHslaColor, getNormalizedHex, getNumber, getRandomBoolean, getRandomCharacters, getRandomColor, getRandomFloat, getRandomHex, getRandomInteger, getRandomItem, getRandomItems, getRgbColor, getRgbaColor, getString, getUuid, getValue, groupBy, hexToHsl, hexToHsla, hexToRgb, hexToRgba, hslToHex, hslToRgb, hslToRgba, ignoreKey, includes, indexOf, insert, isArrayOrPlainObject, isColor, isConstructor, isEmpty, isError, isFulfilled, isHexColor, isHslColor, isHslLike, isHslaColor, isInstanceOf, isKey, isNonNullable, isNullable, isNullableOrEmpty, isNullableOrWhitespace, isNumber, isNumerical, isObject, isOk, isPlainObject, isPrimitive, isRejected, isResult, isRgbColor, isRgbLike, isRgbaColor, isTypedArray, join, kebabCase, logger, lowerCase, max, median, memoize, merge, min, noop, ok, omit, parse, partition, pascalCase, pick, pipe, promises, push, queue, range, rgbToHex, rgbToHsl, rgbToHsla, round, select, setValue, shuffle, smush, snakeCase, sort, splice, startsWith, sum, template, throttle, timed, times, titleCase, toMap, toQuery, toRecord, toSet, toggle, trim, truncate, tryDecode, tryEncode, unique, unsmush, unwrap, update, upperCase, words };
|
package/dist/random.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { join } from "./internal/string.js";
|
|
2
1
|
import { getRandomFloat, getRandomInteger } from "./internal/random.js";
|
|
3
2
|
import { shuffle } from "./internal/array/shuffle.js";
|
|
3
|
+
import { join } from "./internal/string.js";
|
|
4
4
|
/**
|
|
5
5
|
* Get a random boolean
|
|
6
|
-
* @
|
|
6
|
+
* @returns Random boolean
|
|
7
7
|
*/
|
|
8
8
|
function getRandomBoolean() {
|
|
9
9
|
return Math.random() > BOOLEAN_MODIFIER;
|
package/package.json
CHANGED
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
"@types/node": "^25.3",
|
|
9
9
|
"@vitest/coverage-istanbul": "^4",
|
|
10
10
|
"jsdom": "^28.1",
|
|
11
|
-
"oxfmt": "^0.
|
|
12
|
-
"oxlint": "^1.
|
|
11
|
+
"oxfmt": "^0.36",
|
|
12
|
+
"oxlint": "^1.51",
|
|
13
13
|
"rolldown": "1.0.0-rc.6",
|
|
14
14
|
"tslib": "^2.8",
|
|
15
15
|
"typescript": "^5.9",
|
|
@@ -22,69 +22,13 @@
|
|
|
22
22
|
"types": "./types/index.d.ts",
|
|
23
23
|
"default": "./dist/index.js"
|
|
24
24
|
},
|
|
25
|
-
"./array/chunk": {
|
|
26
|
-
"types": "./types/internal/array/chunk.d.ts",
|
|
27
|
-
"default": "./dist/internal/array/chunk.js"
|
|
28
|
-
},
|
|
29
|
-
"./array/compact": {
|
|
30
|
-
"types": "./types/internal/array/compact.d.ts",
|
|
31
|
-
"default": "./dist/internal/array/compact.js"
|
|
32
|
-
},
|
|
33
|
-
"./array/exists": {
|
|
34
|
-
"types": "./types/array/exists.d.ts",
|
|
35
|
-
"default": "./dist/array/exists.js"
|
|
36
|
-
},
|
|
37
|
-
"./array/filter": {
|
|
38
|
-
"types": "./types/array/filter.d.ts",
|
|
39
|
-
"default": "./dist/array/filter.js"
|
|
40
|
-
},
|
|
41
|
-
"./array/find": {
|
|
42
|
-
"types": "./types/array/find.d.ts",
|
|
43
|
-
"default": "./dist/array/find.js"
|
|
44
|
-
},
|
|
45
|
-
"./array/flatten": {
|
|
46
|
-
"types": "./types/array/flatten.d.ts",
|
|
47
|
-
"default": "./dist/array/flatten.js"
|
|
48
|
-
},
|
|
49
|
-
"./array/get": {
|
|
50
|
-
"types": "./types/array/get.d.ts",
|
|
51
|
-
"default": "./dist/array/get.js"
|
|
52
|
-
},
|
|
53
25
|
"./array/group-by": {
|
|
54
26
|
"types": "./types/array/group-by.d.ts",
|
|
55
27
|
"default": "./dist/array/group-by.js"
|
|
56
28
|
},
|
|
57
|
-
"./array/
|
|
58
|
-
"types": "./types/array/
|
|
59
|
-
"default": "./dist/array/
|
|
60
|
-
},
|
|
61
|
-
"./array/insert": {
|
|
62
|
-
"types": "./types/array/insert.d.ts",
|
|
63
|
-
"default": "./dist/array/insert.js"
|
|
64
|
-
},
|
|
65
|
-
"./array/partition": {
|
|
66
|
-
"types": "./types/array/partition.d.ts",
|
|
67
|
-
"default": "./dist/array/partition.js"
|
|
68
|
-
},
|
|
69
|
-
"./array/push": {
|
|
70
|
-
"types": "./types/array/push.d.ts",
|
|
71
|
-
"default": "./dist/array/push.js"
|
|
72
|
-
},
|
|
73
|
-
"./array/range": {
|
|
74
|
-
"types": "./types/array/range.d.ts",
|
|
75
|
-
"default": "./dist/array/range.js"
|
|
76
|
-
},
|
|
77
|
-
"./array/select": {
|
|
78
|
-
"types": "./types/array/select.d.ts",
|
|
79
|
-
"default": "./dist/array/select.js"
|
|
80
|
-
},
|
|
81
|
-
"./array/sort": {
|
|
82
|
-
"types": "./types/array/sort.d.ts",
|
|
83
|
-
"default": "./dist/array/sort.js"
|
|
84
|
-
},
|
|
85
|
-
"./array/splice": {
|
|
86
|
-
"types": "./types/array/splice.d.ts",
|
|
87
|
-
"default": "./dist/array/splice.js"
|
|
29
|
+
"./array/misc": {
|
|
30
|
+
"types": "./types/array/misc.d.ts",
|
|
31
|
+
"default": "./dist/array/misc.js"
|
|
88
32
|
},
|
|
89
33
|
"./array/to-map": {
|
|
90
34
|
"types": "./types/array/to-map.d.ts",
|
|
@@ -94,22 +38,10 @@
|
|
|
94
38
|
"types": "./types/array/to-record.d.ts",
|
|
95
39
|
"default": "./dist/array/to-record.js"
|
|
96
40
|
},
|
|
97
|
-
"./array/to-set": {
|
|
98
|
-
"types": "./types/array/to-set.d.ts",
|
|
99
|
-
"default": "./dist/array/to-set.js"
|
|
100
|
-
},
|
|
101
|
-
"./array/toggle": {
|
|
102
|
-
"types": "./types/array/toggle.d.ts",
|
|
103
|
-
"default": "./dist/array/toggle.js"
|
|
104
|
-
},
|
|
105
41
|
"./array/unique": {
|
|
106
42
|
"types": "./types/array/unique.d.ts",
|
|
107
43
|
"default": "./dist/array/unique.js"
|
|
108
44
|
},
|
|
109
|
-
"./array/update": {
|
|
110
|
-
"types": "./types/array/update.d.ts",
|
|
111
|
-
"default": "./dist/array/update.js"
|
|
112
|
-
},
|
|
113
45
|
"./beacon": {
|
|
114
46
|
"types": "./types/beacon.d.ts",
|
|
115
47
|
"default": "./dist/beacon.js"
|
|
@@ -260,5 +192,5 @@
|
|
|
260
192
|
},
|
|
261
193
|
"type": "module",
|
|
262
194
|
"types": "./types/index.d.ts",
|
|
263
|
-
"version": "0.
|
|
195
|
+
"version": "0.147.0"
|
|
264
196
|
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get an array with a specified length, filled with indices
|
|
3
|
+
* @param length Length of the array
|
|
4
|
+
* @returns Array of indices
|
|
5
|
+
*/
|
|
6
|
+
export function range(length: number): number[];
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Get an array of numbers in a specified range
|
|
10
|
+
* @param start Starting number _(inclusive)_
|
|
11
|
+
* @param end Ending number _(exclusive)_
|
|
12
|
+
* @returns Array of numbers in range
|
|
13
|
+
*/
|
|
14
|
+
export function range(start: number, end: number): number[];
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Get an array of numbers in a specified range with a specified step
|
|
18
|
+
* @param start Starting number _(inclusive)_
|
|
19
|
+
* @param end Ending number _(exclusive)_
|
|
20
|
+
* @param step Step between numbers
|
|
21
|
+
* @returns Array of numbers in range
|
|
22
|
+
*/
|
|
23
|
+
export function range(start: number, end: number, step: number): number[];
|
|
24
|
+
|
|
25
|
+
export function range(first: number, second?: number, third?: number): number[] {
|
|
26
|
+
const start = typeof second === 'number' ? first : 0;
|
|
27
|
+
const end = typeof second === 'number' ? second : first;
|
|
28
|
+
const step = typeof third === 'number' ? third : 1;
|
|
29
|
+
|
|
30
|
+
const values: number[] = [];
|
|
31
|
+
|
|
32
|
+
if (step === 0) {
|
|
33
|
+
return values;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (step > 0) {
|
|
37
|
+
for (let i = start; i < end; i += step) {
|
|
38
|
+
values.push(i);
|
|
39
|
+
}
|
|
40
|
+
} else {
|
|
41
|
+
for (let i = start; i > end; i += step) {
|
|
42
|
+
values.push(i);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return values;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Get an array with a specified length, filled with indices
|
|
51
|
+
* @param length Length of the array
|
|
52
|
+
* @returns Array of indices
|
|
53
|
+
*/
|
|
54
|
+
export function times(length: number): number[];
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Get an array with a specified length, filled by values from a callback
|
|
58
|
+
* @param length Length of the array
|
|
59
|
+
* @param callback Callback function to generate values
|
|
60
|
+
* @returns Array of values generated by the callback
|
|
61
|
+
*/
|
|
62
|
+
export function times<Callback extends (index: number) => unknown>(
|
|
63
|
+
length: number,
|
|
64
|
+
callback: Callback,
|
|
65
|
+
): ReturnType<Callback>[];
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Get an array with a specified length, filled with a specified value
|
|
69
|
+
* @param length Length of the array
|
|
70
|
+
* @param value Value to fill the array with
|
|
71
|
+
* @returns Array filled with the specified value
|
|
72
|
+
*/
|
|
73
|
+
export function times<Value>(length: number, value: Value): Value[];
|
|
74
|
+
|
|
75
|
+
export function times(length: number, value?: unknown): unknown[] {
|
|
76
|
+
if (typeof length !== 'number' || length <= 0) {
|
|
77
|
+
return [];
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const isFunction = typeof value === 'function';
|
|
81
|
+
|
|
82
|
+
const values: unknown[] = [];
|
|
83
|
+
|
|
84
|
+
for (let index = 0; index < length; index += 1) {
|
|
85
|
+
values.push(isFunction ? (value as (index: number) => unknown)(index) : (value ?? index));
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return values;
|
|
89
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export * from '../internal/array/chunk';
|
|
2
|
+
export * from '../internal/array/compact';
|
|
3
|
+
export * from '../internal/array/shuffle';
|
|
4
|
+
|
|
5
|
+
export * from './exists';
|
|
6
|
+
export * from './filter';
|
|
7
|
+
export * from './find';
|
|
8
|
+
export * from './flatten';
|
|
9
|
+
export * from './from';
|
|
10
|
+
export * from './get';
|
|
11
|
+
export * from './index-of';
|
|
12
|
+
export * from './insert';
|
|
13
|
+
export * from './partition';
|
|
14
|
+
export * from './push';
|
|
15
|
+
export * from './select';
|
|
16
|
+
export * from './sort';
|
|
17
|
+
export * from './splice';
|
|
18
|
+
export * from './to-set';
|
|
19
|
+
export * from './toggle';
|
|
20
|
+
export * from './update';
|
package/src/array/toggle.ts
CHANGED
|
@@ -6,7 +6,7 @@ import type {PlainObject} from '../models';
|
|
|
6
6
|
* @param destination Array to toggle within
|
|
7
7
|
* @param toggled Toggled items
|
|
8
8
|
* @param callback Callback to find existing item
|
|
9
|
-
* @
|
|
9
|
+
* @returns Original array
|
|
10
10
|
*/
|
|
11
11
|
export function toggle<Item>(
|
|
12
12
|
destination: Item[],
|
|
@@ -19,7 +19,7 @@ export function toggle<Item>(
|
|
|
19
19
|
* @param destination Array to toggle within
|
|
20
20
|
* @param toggled Toggled items
|
|
21
21
|
* @param key Key to find existing item
|
|
22
|
-
* @
|
|
22
|
+
* @returns Original array
|
|
23
23
|
*/
|
|
24
24
|
export function toggle<Item extends PlainObject, Key extends keyof Item>(
|
|
25
25
|
destination: Item[],
|
package/src/array/update.ts
CHANGED
|
@@ -6,7 +6,7 @@ import type {PlainObject} from '../models';
|
|
|
6
6
|
* @param destination Array to update within
|
|
7
7
|
* @param updated Updated items
|
|
8
8
|
* @param callback Callback to find existing item
|
|
9
|
-
* @
|
|
9
|
+
* @returns Original array
|
|
10
10
|
*/
|
|
11
11
|
export function update<Item>(
|
|
12
12
|
destination: Item[],
|
|
@@ -19,7 +19,7 @@ export function update<Item>(
|
|
|
19
19
|
* @param destination Array to update within
|
|
20
20
|
* @param updated Updated items
|
|
21
21
|
* @param key Key to find existing item
|
|
22
|
-
* @
|
|
22
|
+
* @returns Original array
|
|
23
23
|
*/
|
|
24
24
|
export function update<Item extends PlainObject, Key extends keyof Item>(
|
|
25
25
|
destination: Item[],
|
package/src/index.ts
CHANGED
|
@@ -1,34 +1,16 @@
|
|
|
1
1
|
import FRAME_RATE_MS from './internal/frame-rate';
|
|
2
2
|
|
|
3
|
-
export * from './array/exists';
|
|
4
|
-
export * from './array/filter';
|
|
5
|
-
export * from './array/find';
|
|
6
|
-
export * from './array/flatten';
|
|
7
|
-
export * from './array/get';
|
|
8
3
|
export * from './array/group-by';
|
|
9
|
-
export * from './array/
|
|
10
|
-
export * from './array/insert';
|
|
11
|
-
export * from './array/partition';
|
|
12
|
-
export * from './array/push';
|
|
13
|
-
export * from './array/range';
|
|
14
|
-
export * from './array/select';
|
|
15
|
-
export * from './array/sort';
|
|
16
|
-
export * from './array/splice';
|
|
4
|
+
export * from './array/misc';
|
|
17
5
|
export * from './array/to-map';
|
|
18
6
|
export * from './array/to-record';
|
|
19
|
-
export * from './array/to-set';
|
|
20
|
-
export * from './array/toggle';
|
|
21
7
|
export * from './array/unique';
|
|
22
|
-
export * from './array/update';
|
|
23
8
|
|
|
24
9
|
export * from './function/debounce';
|
|
25
10
|
export * from './function/memoize';
|
|
26
11
|
export * from './function/throttle';
|
|
27
12
|
export * from './function/work';
|
|
28
13
|
|
|
29
|
-
export * from './internal/array/chunk';
|
|
30
|
-
export * from './internal/array/compact';
|
|
31
|
-
export * from './internal/array/shuffle';
|
|
32
14
|
export * from './internal/function/misc';
|
|
33
15
|
export * from './internal/string';
|
|
34
16
|
export * from './internal/value/compare';
|
package/src/math.ts
CHANGED
|
@@ -78,7 +78,7 @@ export function count<Item extends PlainObject, Key extends keyof Item>(
|
|
|
78
78
|
/**
|
|
79
79
|
* Count the number of items in an array
|
|
80
80
|
* @param values Array to count for
|
|
81
|
-
* @
|
|
81
|
+
* @returns Number of items, or `NaN` if no count can be calculated
|
|
82
82
|
*/
|
|
83
83
|
export function count(values: unknown[]): number;
|
|
84
84
|
|
package/src/promise.ts
CHANGED
|
@@ -375,7 +375,7 @@ function isType(value: unknown, type: string): boolean {
|
|
|
375
375
|
* Depending on the strategy, the function will either reject on the first error encountered or return an array of rejected and resolved results
|
|
376
376
|
* @param items List of promises
|
|
377
377
|
* @param options Options for handling the promises
|
|
378
|
-
* @
|
|
378
|
+
* @returns List of results
|
|
379
379
|
*/
|
|
380
380
|
export async function promises<Items extends unknown[], Options extends PromisesOptions>(
|
|
381
381
|
items: Promises<Items>,
|
|
@@ -388,7 +388,7 @@ export async function promises<Items extends unknown[], Options extends Promises
|
|
|
388
388
|
* If any promise in the list is rejected, the whole function will reject
|
|
389
389
|
* @param items List of promises
|
|
390
390
|
* @param strategy Strategy for handling the promises; rejects on the first error encountered
|
|
391
|
-
* @
|
|
391
|
+
* @returns List of results
|
|
392
392
|
*/
|
|
393
393
|
export async function promises<Items extends unknown[]>(
|
|
394
394
|
items: Promises<Items>,
|
|
@@ -399,7 +399,7 @@ export async function promises<Items extends unknown[]>(
|
|
|
399
399
|
* Handle a list of promises, returning their results in an ordered array of rejected and resolved results
|
|
400
400
|
* @param items List of promises
|
|
401
401
|
* @param signal AbortSignal for aborting the operation _(when aborted, the promise will reject with the reason of the signal)_
|
|
402
|
-
* @
|
|
402
|
+
* @returns List of results
|
|
403
403
|
*/
|
|
404
404
|
export async function promises<Items extends unknown[]>(
|
|
405
405
|
items: Promises<Items>,
|
package/src/random.ts
CHANGED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get an array with a specified length, filled with indices
|
|
3
|
+
* @param length Length of the array
|
|
4
|
+
* @returns Array of indices
|
|
5
|
+
*/
|
|
6
|
+
export declare function range(length: number): number[];
|
|
7
|
+
/**
|
|
8
|
+
* Get an array of numbers in a specified range
|
|
9
|
+
* @param start Starting number _(inclusive)_
|
|
10
|
+
* @param end Ending number _(exclusive)_
|
|
11
|
+
* @returns Array of numbers in range
|
|
12
|
+
*/
|
|
13
|
+
export declare function range(start: number, end: number): number[];
|
|
14
|
+
/**
|
|
15
|
+
* Get an array of numbers in a specified range with a specified step
|
|
16
|
+
* @param start Starting number _(inclusive)_
|
|
17
|
+
* @param end Ending number _(exclusive)_
|
|
18
|
+
* @param step Step between numbers
|
|
19
|
+
* @returns Array of numbers in range
|
|
20
|
+
*/
|
|
21
|
+
export declare function range(start: number, end: number, step: number): number[];
|
|
22
|
+
/**
|
|
23
|
+
* Get an array with a specified length, filled with indices
|
|
24
|
+
* @param length Length of the array
|
|
25
|
+
* @returns Array of indices
|
|
26
|
+
*/
|
|
27
|
+
export declare function times(length: number): number[];
|
|
28
|
+
/**
|
|
29
|
+
* Get an array with a specified length, filled by values from a callback
|
|
30
|
+
* @param length Length of the array
|
|
31
|
+
* @param callback Callback function to generate values
|
|
32
|
+
* @returns Array of values generated by the callback
|
|
33
|
+
*/
|
|
34
|
+
export declare function times<Callback extends (index: number) => unknown>(length: number, callback: Callback): ReturnType<Callback>[];
|
|
35
|
+
/**
|
|
36
|
+
* Get an array with a specified length, filled with a specified value
|
|
37
|
+
* @param length Length of the array
|
|
38
|
+
* @param value Value to fill the array with
|
|
39
|
+
* @returns Array filled with the specified value
|
|
40
|
+
*/
|
|
41
|
+
export declare function times<Value>(length: number, value: Value): Value[];
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export * from '../internal/array/chunk';
|
|
2
|
+
export * from '../internal/array/compact';
|
|
3
|
+
export * from '../internal/array/shuffle';
|
|
4
|
+
export * from './exists';
|
|
5
|
+
export * from './filter';
|
|
6
|
+
export * from './find';
|
|
7
|
+
export * from './flatten';
|
|
8
|
+
export * from './from';
|
|
9
|
+
export * from './get';
|
|
10
|
+
export * from './index-of';
|
|
11
|
+
export * from './insert';
|
|
12
|
+
export * from './partition';
|
|
13
|
+
export * from './push';
|
|
14
|
+
export * from './select';
|
|
15
|
+
export * from './sort';
|
|
16
|
+
export * from './splice';
|
|
17
|
+
export * from './to-set';
|
|
18
|
+
export * from './toggle';
|
|
19
|
+
export * from './update';
|
package/types/array/toggle.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import type { PlainObject } from '../models';
|
|
|
4
4
|
* @param destination Array to toggle within
|
|
5
5
|
* @param toggled Toggled items
|
|
6
6
|
* @param callback Callback to find existing item
|
|
7
|
-
* @
|
|
7
|
+
* @returns Original array
|
|
8
8
|
*/
|
|
9
9
|
export declare function toggle<Item>(destination: Item[], toggled: Item[], callback: (item: Item, index: number, array: Item[]) => unknown): Item[];
|
|
10
10
|
/**
|
|
@@ -12,7 +12,7 @@ export declare function toggle<Item>(destination: Item[], toggled: Item[], callb
|
|
|
12
12
|
* @param destination Array to toggle within
|
|
13
13
|
* @param toggled Toggled items
|
|
14
14
|
* @param key Key to find existing item
|
|
15
|
-
* @
|
|
15
|
+
* @returns Original array
|
|
16
16
|
*/
|
|
17
17
|
export declare function toggle<Item extends PlainObject, Key extends keyof Item>(destination: Item[], toggled: Item[], key: Key): Item[];
|
|
18
18
|
/**
|
package/types/array/update.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import type { PlainObject } from '../models';
|
|
|
4
4
|
* @param destination Array to update within
|
|
5
5
|
* @param updated Updated items
|
|
6
6
|
* @param callback Callback to find existing item
|
|
7
|
-
* @
|
|
7
|
+
* @returns Original array
|
|
8
8
|
*/
|
|
9
9
|
export declare function update<Item>(destination: Item[], updated: Item[], callback: (item: Item, index: number, array: Item[]) => unknown): Item[];
|
|
10
10
|
/**
|
|
@@ -12,7 +12,7 @@ export declare function update<Item>(destination: Item[], updated: Item[], callb
|
|
|
12
12
|
* @param destination Array to update within
|
|
13
13
|
* @param updated Updated items
|
|
14
14
|
* @param key Key to find existing item
|
|
15
|
-
* @
|
|
15
|
+
* @returns Original array
|
|
16
16
|
*/
|
|
17
17
|
export declare function update<Item extends PlainObject, Key extends keyof Item>(destination: Item[], updated: Item[], key: Key): Item[];
|
|
18
18
|
/**
|
package/types/index.d.ts
CHANGED
|
@@ -1,31 +1,13 @@
|
|
|
1
1
|
import FRAME_RATE_MS from './internal/frame-rate';
|
|
2
|
-
export * from './array/exists';
|
|
3
|
-
export * from './array/filter';
|
|
4
|
-
export * from './array/find';
|
|
5
|
-
export * from './array/flatten';
|
|
6
|
-
export * from './array/get';
|
|
7
2
|
export * from './array/group-by';
|
|
8
|
-
export * from './array/
|
|
9
|
-
export * from './array/insert';
|
|
10
|
-
export * from './array/partition';
|
|
11
|
-
export * from './array/push';
|
|
12
|
-
export * from './array/range';
|
|
13
|
-
export * from './array/select';
|
|
14
|
-
export * from './array/sort';
|
|
15
|
-
export * from './array/splice';
|
|
3
|
+
export * from './array/misc';
|
|
16
4
|
export * from './array/to-map';
|
|
17
5
|
export * from './array/to-record';
|
|
18
|
-
export * from './array/to-set';
|
|
19
|
-
export * from './array/toggle';
|
|
20
6
|
export * from './array/unique';
|
|
21
|
-
export * from './array/update';
|
|
22
7
|
export * from './function/debounce';
|
|
23
8
|
export * from './function/memoize';
|
|
24
9
|
export * from './function/throttle';
|
|
25
10
|
export * from './function/work';
|
|
26
|
-
export * from './internal/array/chunk';
|
|
27
|
-
export * from './internal/array/compact';
|
|
28
|
-
export * from './internal/array/shuffle';
|
|
29
11
|
export * from './internal/function/misc';
|
|
30
12
|
export * from './internal/string';
|
|
31
13
|
export * from './internal/value/compare';
|
package/types/math.d.ts
CHANGED
|
@@ -45,7 +45,7 @@ export declare function count<Item extends PlainObject, Key extends keyof Item>(
|
|
|
45
45
|
/**
|
|
46
46
|
* Count the number of items in an array
|
|
47
47
|
* @param values Array to count for
|
|
48
|
-
* @
|
|
48
|
+
* @returns Number of items, or `NaN` if no count can be calculated
|
|
49
49
|
*/
|
|
50
50
|
export declare function count(values: unknown[]): number;
|
|
51
51
|
/**
|
package/types/promise.d.ts
CHANGED
|
@@ -101,7 +101,7 @@ export declare function isRejected(value: unknown): value is RejectedPromiseResu
|
|
|
101
101
|
* Depending on the strategy, the function will either reject on the first error encountered or return an array of rejected and resolved results
|
|
102
102
|
* @param items List of promises
|
|
103
103
|
* @param options Options for handling the promises
|
|
104
|
-
* @
|
|
104
|
+
* @returns List of results
|
|
105
105
|
*/
|
|
106
106
|
export declare function promises<Items extends unknown[], Options extends PromisesOptions>(items: Promises<Items>, options?: Options): Promise<Options['strategy'] extends 'first' ? Items : PromisesResult<Items>>;
|
|
107
107
|
/**
|
|
@@ -110,14 +110,14 @@ export declare function promises<Items extends unknown[], Options extends Promis
|
|
|
110
110
|
* If any promise in the list is rejected, the whole function will reject
|
|
111
111
|
* @param items List of promises
|
|
112
112
|
* @param strategy Strategy for handling the promises; rejects on the first error encountered
|
|
113
|
-
* @
|
|
113
|
+
* @returns List of results
|
|
114
114
|
*/
|
|
115
115
|
export declare function promises<Items extends unknown[]>(items: Promises<Items>, strategy: 'first'): Promise<Items>;
|
|
116
116
|
/**
|
|
117
117
|
* Handle a list of promises, returning their results in an ordered array of rejected and resolved results
|
|
118
118
|
* @param items List of promises
|
|
119
119
|
* @param signal AbortSignal for aborting the operation _(when aborted, the promise will reject with the reason of the signal)_
|
|
120
|
-
* @
|
|
120
|
+
* @returns List of results
|
|
121
121
|
*/
|
|
122
122
|
export declare function promises<Items extends unknown[]>(items: Promises<Items>, signal?: AbortSignal): Promise<PromisesResult<Items>>;
|
|
123
123
|
/**
|
package/types/random.d.ts
CHANGED
package/dist/array/range.js
DELETED
package/src/array/range.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Get an array with a specified length, filled with indices
|
|
3
|
-
* @param length Length of the array
|
|
4
|
-
* @return Arry of indices
|
|
5
|
-
*/
|
|
6
|
-
export function range(length: number): number[];
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Get an array with a specified length, filled by values from a callback
|
|
10
|
-
* @param length Length of the array
|
|
11
|
-
* @param callback Callback function to generate values
|
|
12
|
-
* @return Array of values generated by the callback
|
|
13
|
-
*/
|
|
14
|
-
export function range<Callback extends (index: number) => unknown>(
|
|
15
|
-
length: number,
|
|
16
|
-
callback: Callback,
|
|
17
|
-
): ReturnType<Callback>[];
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Get an array with a specified length, filled with a specified value
|
|
21
|
-
* @param length Length of the array
|
|
22
|
-
* @param value Value to fill the array with
|
|
23
|
-
* @return Array filled with the specified value
|
|
24
|
-
*/
|
|
25
|
-
export function range<Value>(length: number, value: Value): Value[];
|
|
26
|
-
|
|
27
|
-
export function range(length: number, value?: unknown): unknown[] {
|
|
28
|
-
if (typeof length !== 'number' || length <= 0) {
|
|
29
|
-
return [];
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const isFunction = typeof value === 'function';
|
|
33
|
-
|
|
34
|
-
return Array.from({length}, (_, index) => (isFunction ? value(index) : (value ?? index)));
|
|
35
|
-
}
|
package/types/array/range.d.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Get an array with a specified length, filled with indices
|
|
3
|
-
* @param length Length of the array
|
|
4
|
-
* @return Arry of indices
|
|
5
|
-
*/
|
|
6
|
-
export declare function range(length: number): number[];
|
|
7
|
-
/**
|
|
8
|
-
* Get an array with a specified length, filled by values from a callback
|
|
9
|
-
* @param length Length of the array
|
|
10
|
-
* @param callback Callback function to generate values
|
|
11
|
-
* @return Array of values generated by the callback
|
|
12
|
-
*/
|
|
13
|
-
export declare function range<Callback extends (index: number) => unknown>(length: number, callback: Callback): ReturnType<Callback>[];
|
|
14
|
-
/**
|
|
15
|
-
* Get an array with a specified length, filled with a specified value
|
|
16
|
-
* @param length Length of the array
|
|
17
|
-
* @param value Value to fill the array with
|
|
18
|
-
* @return Array filled with the specified value
|
|
19
|
-
*/
|
|
20
|
-
export declare function range<Value>(length: number, value: Value): Value[];
|