@alextheman/utility 3.5.4 → 3.5.5
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/index.cjs +26 -0
- package/dist/index.d.cts +41 -3
- package/dist/index.d.ts +41 -3
- package/dist/index.js +26 -0
- package/package.json +6 -3
package/dist/index.cjs
CHANGED
|
@@ -46,6 +46,18 @@ var appendSemicolon_default = appendSemicolon;
|
|
|
46
46
|
|
|
47
47
|
//#endregion
|
|
48
48
|
//#region src/functions/arrayHelpers/fillArray.ts
|
|
49
|
+
/**
|
|
50
|
+
* Creates a new array where each element is the result of the provided callback.
|
|
51
|
+
*
|
|
52
|
+
* If the callback returns at least one Promise, the entire result will be wrapped
|
|
53
|
+
* in a `Promise` and resolved with `Promise.all`. Otherwise, a plain array is returned.
|
|
54
|
+
*
|
|
55
|
+
* @template ItemType
|
|
56
|
+
* @param callback - A function invoked with the current index. May return a value or a Promise.
|
|
57
|
+
* @param [length=1] - The desired length of the resulting array.
|
|
58
|
+
*
|
|
59
|
+
* @returns An array of the callback results, or a Promise resolving to one if the callback is async.
|
|
60
|
+
*/
|
|
49
61
|
function fillArray(callback, length = 1) {
|
|
50
62
|
const outputArray = new Array(length).fill(null).map((_, index) => {
|
|
51
63
|
return callback(index);
|
|
@@ -59,6 +71,20 @@ var fillArray_default = fillArray;
|
|
|
59
71
|
|
|
60
72
|
//#endregion
|
|
61
73
|
//#region src/functions/arrayHelpers/paralleliseArrays.ts
|
|
74
|
+
/**
|
|
75
|
+
* Creates a new array of tuples, each containing the item at the given index from both arrays.
|
|
76
|
+
*
|
|
77
|
+
* If `secondArray` is shorter than `firstArray`, the second position in the tuple
|
|
78
|
+
* will be `undefined`. Iteration always uses the length of the first array.
|
|
79
|
+
*
|
|
80
|
+
* @template FirstArrayItem
|
|
81
|
+
* @template SecondArrayItem
|
|
82
|
+
*
|
|
83
|
+
* @param firstArray - The first array. Each item in this will take up the first tuple spot.
|
|
84
|
+
* @param secondArray - The second array. Each item in this will take up the second tuple spot.
|
|
85
|
+
*
|
|
86
|
+
* @returns An array of `[firstItem, secondItem]` tuples for each index in `firstArray`.
|
|
87
|
+
*/
|
|
62
88
|
function paralleliseArrays(firstArray, secondArray) {
|
|
63
89
|
const outputArray = [];
|
|
64
90
|
for (let i = 0; i < firstArray.length; i++) outputArray.push([firstArray[i], secondArray[i]]);
|
package/dist/index.d.cts
CHANGED
|
@@ -7,12 +7,50 @@ declare const NAMESPACE_EXPORT_REGEX = "export\\s+\\*\\s+from";
|
|
|
7
7
|
declare function appendSemicolon(stringToAppendTo: string): string;
|
|
8
8
|
//#endregion
|
|
9
9
|
//#region src/functions/arrayHelpers/fillArray.d.ts
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
/**
|
|
11
|
+
* Creates a new array where each element is the resolved result of the provided asynchronous callback.
|
|
12
|
+
*
|
|
13
|
+
* The callback will be invoked once for each index from `0` to `length - 1`.
|
|
14
|
+
* If no length is provided, a single-element array will be produced.
|
|
15
|
+
*
|
|
16
|
+
* @template ItemType
|
|
17
|
+
* @param callback - An asynchronous function invoked with the current index.
|
|
18
|
+
* @param [length=1] - The desired length of the resulting array.
|
|
19
|
+
*
|
|
20
|
+
* @returns A Promise resolving to an array of the callback results.
|
|
21
|
+
*/
|
|
22
|
+
declare function fillArray<ItemType$1>(callback: (index: number) => Promise<ItemType$1>, length?: number): Promise<ItemType$1[]>;
|
|
23
|
+
/**
|
|
24
|
+
* Creates a new array where each element is the result of the provided synchronous callback.
|
|
25
|
+
*
|
|
26
|
+
* The callback will be invoked once for each index from `0` to `length - 1`.
|
|
27
|
+
* If no length is provided, a single-element array will be produced.
|
|
28
|
+
*
|
|
29
|
+
* @template ItemType
|
|
30
|
+
* @param callback - A synchronous function invoked with the current index.
|
|
31
|
+
* @param [length=1] - The desired length of the resulting array.
|
|
32
|
+
*
|
|
33
|
+
* @returns An array of the callback results.
|
|
34
|
+
*/
|
|
35
|
+
declare function fillArray<ItemType$1>(callback: (index: number) => ItemType$1, length?: number): ItemType$1[];
|
|
12
36
|
//#endregion
|
|
13
37
|
//#region src/functions/arrayHelpers/paralleliseArrays.d.ts
|
|
14
38
|
type ParallelTuple<A, B> = [A, B | undefined];
|
|
15
|
-
|
|
39
|
+
/**
|
|
40
|
+
* Creates a new array of tuples, each containing the item at the given index from both arrays.
|
|
41
|
+
*
|
|
42
|
+
* If `secondArray` is shorter than `firstArray`, the second position in the tuple
|
|
43
|
+
* will be `undefined`. Iteration always uses the length of the first array.
|
|
44
|
+
*
|
|
45
|
+
* @template FirstArrayItem
|
|
46
|
+
* @template SecondArrayItem
|
|
47
|
+
*
|
|
48
|
+
* @param firstArray - The first array. Each item in this will take up the first tuple spot.
|
|
49
|
+
* @param secondArray - The second array. Each item in this will take up the second tuple spot.
|
|
50
|
+
*
|
|
51
|
+
* @returns An array of `[firstItem, secondItem]` tuples for each index in `firstArray`.
|
|
52
|
+
*/
|
|
53
|
+
declare function paralleliseArrays<FirstArrayItem, SecondArrayItem>(firstArray: readonly FirstArrayItem[], secondArray: readonly SecondArrayItem[]): ParallelTuple<FirstArrayItem, SecondArrayItem>[];
|
|
16
54
|
//#endregion
|
|
17
55
|
//#region src/functions/arrayHelpers/randomiseArray.d.ts
|
|
18
56
|
declare function randomiseArray<T>(array: T[]): T[];
|
package/dist/index.d.ts
CHANGED
|
@@ -7,12 +7,50 @@ declare const NAMESPACE_EXPORT_REGEX = "export\\s+\\*\\s+from";
|
|
|
7
7
|
declare function appendSemicolon(stringToAppendTo: string): string;
|
|
8
8
|
//#endregion
|
|
9
9
|
//#region src/functions/arrayHelpers/fillArray.d.ts
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
/**
|
|
11
|
+
* Creates a new array where each element is the resolved result of the provided asynchronous callback.
|
|
12
|
+
*
|
|
13
|
+
* The callback will be invoked once for each index from `0` to `length - 1`.
|
|
14
|
+
* If no length is provided, a single-element array will be produced.
|
|
15
|
+
*
|
|
16
|
+
* @template ItemType
|
|
17
|
+
* @param callback - An asynchronous function invoked with the current index.
|
|
18
|
+
* @param [length=1] - The desired length of the resulting array.
|
|
19
|
+
*
|
|
20
|
+
* @returns A Promise resolving to an array of the callback results.
|
|
21
|
+
*/
|
|
22
|
+
declare function fillArray<ItemType$1>(callback: (index: number) => Promise<ItemType$1>, length?: number): Promise<ItemType$1[]>;
|
|
23
|
+
/**
|
|
24
|
+
* Creates a new array where each element is the result of the provided synchronous callback.
|
|
25
|
+
*
|
|
26
|
+
* The callback will be invoked once for each index from `0` to `length - 1`.
|
|
27
|
+
* If no length is provided, a single-element array will be produced.
|
|
28
|
+
*
|
|
29
|
+
* @template ItemType
|
|
30
|
+
* @param callback - A synchronous function invoked with the current index.
|
|
31
|
+
* @param [length=1] - The desired length of the resulting array.
|
|
32
|
+
*
|
|
33
|
+
* @returns An array of the callback results.
|
|
34
|
+
*/
|
|
35
|
+
declare function fillArray<ItemType$1>(callback: (index: number) => ItemType$1, length?: number): ItemType$1[];
|
|
12
36
|
//#endregion
|
|
13
37
|
//#region src/functions/arrayHelpers/paralleliseArrays.d.ts
|
|
14
38
|
type ParallelTuple<A, B> = [A, B | undefined];
|
|
15
|
-
|
|
39
|
+
/**
|
|
40
|
+
* Creates a new array of tuples, each containing the item at the given index from both arrays.
|
|
41
|
+
*
|
|
42
|
+
* If `secondArray` is shorter than `firstArray`, the second position in the tuple
|
|
43
|
+
* will be `undefined`. Iteration always uses the length of the first array.
|
|
44
|
+
*
|
|
45
|
+
* @template FirstArrayItem
|
|
46
|
+
* @template SecondArrayItem
|
|
47
|
+
*
|
|
48
|
+
* @param firstArray - The first array. Each item in this will take up the first tuple spot.
|
|
49
|
+
* @param secondArray - The second array. Each item in this will take up the second tuple spot.
|
|
50
|
+
*
|
|
51
|
+
* @returns An array of `[firstItem, secondItem]` tuples for each index in `firstArray`.
|
|
52
|
+
*/
|
|
53
|
+
declare function paralleliseArrays<FirstArrayItem, SecondArrayItem>(firstArray: readonly FirstArrayItem[], secondArray: readonly SecondArrayItem[]): ParallelTuple<FirstArrayItem, SecondArrayItem>[];
|
|
16
54
|
//#endregion
|
|
17
55
|
//#region src/functions/arrayHelpers/randomiseArray.d.ts
|
|
18
56
|
declare function randomiseArray<T>(array: T[]): T[];
|
package/dist/index.js
CHANGED
|
@@ -17,6 +17,18 @@ var appendSemicolon_default = appendSemicolon;
|
|
|
17
17
|
|
|
18
18
|
//#endregion
|
|
19
19
|
//#region src/functions/arrayHelpers/fillArray.ts
|
|
20
|
+
/**
|
|
21
|
+
* Creates a new array where each element is the result of the provided callback.
|
|
22
|
+
*
|
|
23
|
+
* If the callback returns at least one Promise, the entire result will be wrapped
|
|
24
|
+
* in a `Promise` and resolved with `Promise.all`. Otherwise, a plain array is returned.
|
|
25
|
+
*
|
|
26
|
+
* @template ItemType
|
|
27
|
+
* @param callback - A function invoked with the current index. May return a value or a Promise.
|
|
28
|
+
* @param [length=1] - The desired length of the resulting array.
|
|
29
|
+
*
|
|
30
|
+
* @returns An array of the callback results, or a Promise resolving to one if the callback is async.
|
|
31
|
+
*/
|
|
20
32
|
function fillArray(callback, length = 1) {
|
|
21
33
|
const outputArray = new Array(length).fill(null).map((_, index) => {
|
|
22
34
|
return callback(index);
|
|
@@ -30,6 +42,20 @@ var fillArray_default = fillArray;
|
|
|
30
42
|
|
|
31
43
|
//#endregion
|
|
32
44
|
//#region src/functions/arrayHelpers/paralleliseArrays.ts
|
|
45
|
+
/**
|
|
46
|
+
* Creates a new array of tuples, each containing the item at the given index from both arrays.
|
|
47
|
+
*
|
|
48
|
+
* If `secondArray` is shorter than `firstArray`, the second position in the tuple
|
|
49
|
+
* will be `undefined`. Iteration always uses the length of the first array.
|
|
50
|
+
*
|
|
51
|
+
* @template FirstArrayItem
|
|
52
|
+
* @template SecondArrayItem
|
|
53
|
+
*
|
|
54
|
+
* @param firstArray - The first array. Each item in this will take up the first tuple spot.
|
|
55
|
+
* @param secondArray - The second array. Each item in this will take up the second tuple spot.
|
|
56
|
+
*
|
|
57
|
+
* @returns An array of `[firstItem, secondItem]` tuples for each index in `firstArray`.
|
|
58
|
+
*/
|
|
33
59
|
function paralleliseArrays(firstArray, secondArray) {
|
|
34
60
|
const outputArray = [];
|
|
35
61
|
for (let i = 0; i < firstArray.length; i++) outputArray.push([firstArray[i], secondArray[i]]);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alextheman/utility",
|
|
3
|
-
"version": "3.5.
|
|
3
|
+
"version": "3.5.5",
|
|
4
4
|
"description": "Helpful utility functions",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
"devDependencies": {
|
|
22
22
|
"@alextheman/eslint-plugin": "^4.3.0",
|
|
23
23
|
"@types/node": "^24.10.1",
|
|
24
|
+
"dotenv-cli": "^11.0.0",
|
|
24
25
|
"eslint": "^9.39.1",
|
|
25
26
|
"globals": "^16.5.0",
|
|
26
27
|
"husky": "^9.1.7",
|
|
@@ -48,10 +49,12 @@
|
|
|
48
49
|
"lint-prettier-javascript": "prettier --check \"./**/*.js\"",
|
|
49
50
|
"lint-prettier-typescript": "prettier --check --parser typescript \"./**/*.ts\"",
|
|
50
51
|
"lint-tsc": "tsc --noEmit",
|
|
52
|
+
"prepare-live-eslint-plugin": "pnpm uninstall @alextheman/eslint-plugin && pnpm install --save-dev @alextheman/eslint-plugin",
|
|
53
|
+
"prepare-local-eslint-plugin": "dotenv -e .env -- sh -c 'ESLINT_PLUGIN_PATH=${LOCAL_ESLINT_PLUGIN_PATH:-../eslint-plugin}; pnpm --prefix \"$ESLINT_PLUGIN_PATH\" run build && pnpm uninstall @alextheman/eslint-plugin && pnpm install --save-dev -w file:\"$ESLINT_PLUGIN_PATH\"'",
|
|
51
54
|
"test": "vitest run",
|
|
52
55
|
"test-watch": "vitest",
|
|
53
56
|
"update-dependencies": "pnpm update --latest && pnpm update",
|
|
54
|
-
"use-live-eslint-plugin": "pnpm
|
|
55
|
-
"use-local-eslint-plugin": "
|
|
57
|
+
"use-live-eslint-plugin": "pnpm run prepare-live-eslint-plugin && pnpm run lint",
|
|
58
|
+
"use-local-eslint-plugin": "pnpm run prepare-local-eslint-plugin && pnpm run lint"
|
|
56
59
|
}
|
|
57
60
|
}
|