@oscarpalmer/atoms 0.146.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 +2 -2
- package/dist/atoms.full.js +19 -7
- package/dist/index.js +2 -2
- package/dist/random.js +1 -1
- package/package.json +1 -1
- package/src/array/from.ts +89 -0
- package/src/array/misc.ts +1 -1
- package/src/array/toggle.ts +2 -2
- package/src/array/update.ts +2 -2
- 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 +1 -1
- package/types/array/toggle.d.ts +2 -2
- package/types/array/update.d.ts +2 -2
- 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 };
|
package/dist/array/misc.js
CHANGED
|
@@ -2,6 +2,7 @@ import { exists } from "./exists.js";
|
|
|
2
2
|
import { filter } from "./filter.js";
|
|
3
3
|
import { find } from "./find.js";
|
|
4
4
|
import { flatten } from "./flatten.js";
|
|
5
|
+
import { range, times } from "./from.js";
|
|
5
6
|
import { getArray } from "./get.js";
|
|
6
7
|
import { indexOf } from "./index-of.js";
|
|
7
8
|
import { chunk } from "../internal/array/chunk.js";
|
|
@@ -10,11 +11,10 @@ import { compact } from "../internal/array/compact.js";
|
|
|
10
11
|
import { shuffle } from "../internal/array/shuffle.js";
|
|
11
12
|
import { partition } from "./partition.js";
|
|
12
13
|
import { push } from "./push.js";
|
|
13
|
-
import { range } from "./range.js";
|
|
14
14
|
import { select } from "./select.js";
|
|
15
15
|
import { sort } from "./sort.js";
|
|
16
16
|
import { splice } from "./splice.js";
|
|
17
17
|
import { toSet } from "./to-set.js";
|
|
18
18
|
import { toggle } from "./toggle.js";
|
|
19
19
|
import { update } from "./update.js";
|
|
20
|
-
export { chunk, compact, exists, filter, find, flatten, getArray, indexOf, insert, partition, push, range, select, shuffle, sort, splice, toSet, toggle, update };
|
|
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
|
@@ -284,6 +284,23 @@ function find(array, ...parameters) {
|
|
|
284
284
|
function flatten(array) {
|
|
285
285
|
return Array.isArray(array) ? array.flat(Number.POSITIVE_INFINITY) : [];
|
|
286
286
|
}
|
|
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;
|
|
296
|
+
}
|
|
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;
|
|
303
|
+
}
|
|
287
304
|
function getArray(value, indiced) {
|
|
288
305
|
if (Array.isArray(value)) return value;
|
|
289
306
|
if (value instanceof Map || value instanceof Set) return [...value.values()];
|
|
@@ -338,11 +355,6 @@ function partition(array, ...parameters) {
|
|
|
338
355
|
function push(array, pushed) {
|
|
339
356
|
return insertValues("push", array, pushed, array.length, 0);
|
|
340
357
|
}
|
|
341
|
-
function range(length, value) {
|
|
342
|
-
if (typeof length !== "number" || length <= 0) return [];
|
|
343
|
-
const isFunction = typeof value === "function";
|
|
344
|
-
return Array.from({ length }, (_, index) => isFunction ? value(index) : value ?? index);
|
|
345
|
-
}
|
|
346
358
|
function select(array, ...parameters) {
|
|
347
359
|
return findValues("all", array, parameters, parameters.pop()).matched;
|
|
348
360
|
}
|
|
@@ -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,6 +2,7 @@ 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";
|
|
@@ -13,7 +14,6 @@ import { getRandomFloat, getRandomInteger } from "./internal/random.js";
|
|
|
13
14
|
import { shuffle } from "./internal/array/shuffle.js";
|
|
14
15
|
import { partition } from "./array/partition.js";
|
|
15
16
|
import { push } from "./array/push.js";
|
|
16
|
-
import { range } from "./array/range.js";
|
|
17
17
|
import { select } from "./array/select.js";
|
|
18
18
|
import { max } from "./internal/math/aggregate.js";
|
|
19
19
|
import { getString, ignoreKey, join, tryDecode, tryEncode, words } from "./internal/string.js";
|
|
@@ -65,4 +65,4 @@ import { QueueError, queue } from "./queue.js";
|
|
|
65
65
|
import { getRandomBoolean, getRandomCharacters, getRandomColor, getRandomHex, getRandomItem, getRandomItems } from "./random.js";
|
|
66
66
|
import { attempt, error, isError, isOk, isResult, ok, unwrap } from "./result.js";
|
|
67
67
|
import { SizedSet } from "./sized/set.js";
|
|
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, 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
package/package.json
CHANGED
|
@@ -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
|
+
}
|
package/src/array/misc.ts
CHANGED
|
@@ -6,12 +6,12 @@ export * from './exists';
|
|
|
6
6
|
export * from './filter';
|
|
7
7
|
export * from './find';
|
|
8
8
|
export * from './flatten';
|
|
9
|
+
export * from './from';
|
|
9
10
|
export * from './get';
|
|
10
11
|
export * from './index-of';
|
|
11
12
|
export * from './insert';
|
|
12
13
|
export * from './partition';
|
|
13
14
|
export * from './push';
|
|
14
|
-
export * from './range';
|
|
15
15
|
export * from './select';
|
|
16
16
|
export * from './sort';
|
|
17
17
|
export * from './splice';
|
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/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[];
|
package/types/array/misc.d.ts
CHANGED
|
@@ -5,12 +5,12 @@ export * from './exists';
|
|
|
5
5
|
export * from './filter';
|
|
6
6
|
export * from './find';
|
|
7
7
|
export * from './flatten';
|
|
8
|
+
export * from './from';
|
|
8
9
|
export * from './get';
|
|
9
10
|
export * from './index-of';
|
|
10
11
|
export * from './insert';
|
|
11
12
|
export * from './partition';
|
|
12
13
|
export * from './push';
|
|
13
|
-
export * from './range';
|
|
14
14
|
export * from './select';
|
|
15
15
|
export * from './sort';
|
|
16
16
|
export * from './splice';
|
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/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[];
|