@alextheman/utility 3.5.5 → 3.5.7
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 +7 -10
- package/dist/index.d.cts +17 -15
- package/dist/index.d.ts +17 -15
- package/dist/index.js +7 -10
- package/package.json +6 -6
package/dist/index.cjs
CHANGED
|
@@ -51,11 +51,9 @@ var appendSemicolon_default = appendSemicolon;
|
|
|
51
51
|
*
|
|
52
52
|
* If the callback returns at least one Promise, the entire result will be wrapped
|
|
53
53
|
* in a `Promise` and resolved with `Promise.all`. Otherwise, a plain array is returned.
|
|
54
|
-
*
|
|
55
54
|
* @template ItemType
|
|
56
55
|
* @param callback - A function invoked with the current index. May return a value or a Promise.
|
|
57
|
-
* @param [length
|
|
58
|
-
*
|
|
56
|
+
* @param [length] - The desired length of the resulting array.
|
|
59
57
|
* @returns An array of the callback results, or a Promise resolving to one if the callback is async.
|
|
60
58
|
*/
|
|
61
59
|
function fillArray(callback, length = 1) {
|
|
@@ -76,13 +74,10 @@ var fillArray_default = fillArray;
|
|
|
76
74
|
*
|
|
77
75
|
* If `secondArray` is shorter than `firstArray`, the second position in the tuple
|
|
78
76
|
* will be `undefined`. Iteration always uses the length of the first array.
|
|
79
|
-
*
|
|
80
77
|
* @template FirstArrayItem
|
|
81
78
|
* @template SecondArrayItem
|
|
82
|
-
*
|
|
83
79
|
* @param firstArray - The first array. Each item in this will take up the first tuple spot.
|
|
84
80
|
* @param secondArray - The second array. Each item in this will take up the second tuple spot.
|
|
85
|
-
*
|
|
86
81
|
* @returns An array of `[firstItem, secondItem]` tuples for each index in `firstArray`.
|
|
87
82
|
*/
|
|
88
83
|
function paralleliseArrays(firstArray, secondArray) {
|
|
@@ -477,10 +472,12 @@ var APIError_default = APIError;
|
|
|
477
472
|
var DataError = class extends Error {
|
|
478
473
|
data;
|
|
479
474
|
code;
|
|
480
|
-
/**
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
475
|
+
/**
|
|
476
|
+
* @param data - The data that caused the error.
|
|
477
|
+
* @param message - A human-readable error message (e.g. The data provided is invalid).
|
|
478
|
+
* @param code - A standardised code (e.g. UNEXPECTED_DATA).
|
|
479
|
+
* @param options - Extra options to pass to super Error constructor.
|
|
480
|
+
*/
|
|
484
481
|
constructor(data, message = "The data provided is invalid", code = "INVALID_DATA", options) {
|
|
485
482
|
super(message, options);
|
|
486
483
|
if (Error.captureStackTrace) Error.captureStackTrace(this, new.target);
|
package/dist/index.d.cts
CHANGED
|
@@ -12,11 +12,9 @@ declare function appendSemicolon(stringToAppendTo: string): string;
|
|
|
12
12
|
*
|
|
13
13
|
* The callback will be invoked once for each index from `0` to `length - 1`.
|
|
14
14
|
* If no length is provided, a single-element array will be produced.
|
|
15
|
-
*
|
|
16
15
|
* @template ItemType
|
|
17
16
|
* @param callback - An asynchronous function invoked with the current index.
|
|
18
|
-
* @param [length
|
|
19
|
-
*
|
|
17
|
+
* @param [length] - The desired length of the resulting array.
|
|
20
18
|
* @returns A Promise resolving to an array of the callback results.
|
|
21
19
|
*/
|
|
22
20
|
declare function fillArray<ItemType$1>(callback: (index: number) => Promise<ItemType$1>, length?: number): Promise<ItemType$1[]>;
|
|
@@ -25,11 +23,9 @@ declare function fillArray<ItemType$1>(callback: (index: number) => Promise<Item
|
|
|
25
23
|
*
|
|
26
24
|
* The callback will be invoked once for each index from `0` to `length - 1`.
|
|
27
25
|
* If no length is provided, a single-element array will be produced.
|
|
28
|
-
*
|
|
29
26
|
* @template ItemType
|
|
30
27
|
* @param callback - A synchronous function invoked with the current index.
|
|
31
|
-
* @param [length
|
|
32
|
-
*
|
|
28
|
+
* @param [length] - The desired length of the resulting array.
|
|
33
29
|
* @returns An array of the callback results.
|
|
34
30
|
*/
|
|
35
31
|
declare function fillArray<ItemType$1>(callback: (index: number) => ItemType$1, length?: number): ItemType$1[];
|
|
@@ -41,13 +37,10 @@ type ParallelTuple<A, B> = [A, B | undefined];
|
|
|
41
37
|
*
|
|
42
38
|
* If `secondArray` is shorter than `firstArray`, the second position in the tuple
|
|
43
39
|
* will be `undefined`. Iteration always uses the length of the first array.
|
|
44
|
-
*
|
|
45
40
|
* @template FirstArrayItem
|
|
46
41
|
* @template SecondArrayItem
|
|
47
|
-
*
|
|
48
42
|
* @param firstArray - The first array. Each item in this will take up the first tuple spot.
|
|
49
43
|
* @param secondArray - The second array. Each item in this will take up the second tuple spot.
|
|
50
|
-
*
|
|
51
44
|
* @returns An array of `[firstItem, secondItem]` tuples for each index in `firstArray`.
|
|
52
45
|
*/
|
|
53
46
|
declare function paralleliseArrays<FirstArrayItem, SecondArrayItem>(firstArray: readonly FirstArrayItem[], secondArray: readonly SecondArrayItem[]): ParallelTuple<FirstArrayItem, SecondArrayItem>[];
|
|
@@ -77,10 +70,12 @@ declare class APIError extends Error {
|
|
|
77
70
|
declare class DataError extends Error {
|
|
78
71
|
data: unknown;
|
|
79
72
|
code: string;
|
|
80
|
-
/**
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
73
|
+
/**
|
|
74
|
+
* @param data - The data that caused the error.
|
|
75
|
+
* @param message - A human-readable error message (e.g. The data provided is invalid).
|
|
76
|
+
* @param code - A standardised code (e.g. UNEXPECTED_DATA).
|
|
77
|
+
* @param options - Extra options to pass to super Error constructor.
|
|
78
|
+
*/
|
|
84
79
|
constructor(data: unknown, message?: string, code?: string, options?: ErrorOptions);
|
|
85
80
|
static check(input: unknown): input is DataError;
|
|
86
81
|
}
|
|
@@ -243,9 +238,16 @@ interface RemoveIndentsOptions {
|
|
|
243
238
|
preserveTabs?: boolean;
|
|
244
239
|
}
|
|
245
240
|
type RemoveIndentsFunction = (strings: TemplateStringsArray, ...interpolations: unknown[]) => string;
|
|
246
|
-
/**
|
|
241
|
+
/**
|
|
242
|
+
* @param options
|
|
243
|
+
* @deprecated This function has been renamed to normaliseIndents
|
|
244
|
+
*/
|
|
247
245
|
declare function removeIndents(options: RemoveIndentsOptions): RemoveIndentsFunction;
|
|
248
|
-
/**
|
|
246
|
+
/**
|
|
247
|
+
* @param strings
|
|
248
|
+
* @param interpolations
|
|
249
|
+
* @deprecated This function has been renamed to normaliseIndents
|
|
250
|
+
*/
|
|
249
251
|
declare function removeIndents(strings: TemplateStringsArray, ...interpolations: unknown[]): string;
|
|
250
252
|
//#endregion
|
|
251
253
|
//#region src/functions/truncate.d.ts
|
package/dist/index.d.ts
CHANGED
|
@@ -12,11 +12,9 @@ declare function appendSemicolon(stringToAppendTo: string): string;
|
|
|
12
12
|
*
|
|
13
13
|
* The callback will be invoked once for each index from `0` to `length - 1`.
|
|
14
14
|
* If no length is provided, a single-element array will be produced.
|
|
15
|
-
*
|
|
16
15
|
* @template ItemType
|
|
17
16
|
* @param callback - An asynchronous function invoked with the current index.
|
|
18
|
-
* @param [length
|
|
19
|
-
*
|
|
17
|
+
* @param [length] - The desired length of the resulting array.
|
|
20
18
|
* @returns A Promise resolving to an array of the callback results.
|
|
21
19
|
*/
|
|
22
20
|
declare function fillArray<ItemType$1>(callback: (index: number) => Promise<ItemType$1>, length?: number): Promise<ItemType$1[]>;
|
|
@@ -25,11 +23,9 @@ declare function fillArray<ItemType$1>(callback: (index: number) => Promise<Item
|
|
|
25
23
|
*
|
|
26
24
|
* The callback will be invoked once for each index from `0` to `length - 1`.
|
|
27
25
|
* If no length is provided, a single-element array will be produced.
|
|
28
|
-
*
|
|
29
26
|
* @template ItemType
|
|
30
27
|
* @param callback - A synchronous function invoked with the current index.
|
|
31
|
-
* @param [length
|
|
32
|
-
*
|
|
28
|
+
* @param [length] - The desired length of the resulting array.
|
|
33
29
|
* @returns An array of the callback results.
|
|
34
30
|
*/
|
|
35
31
|
declare function fillArray<ItemType$1>(callback: (index: number) => ItemType$1, length?: number): ItemType$1[];
|
|
@@ -41,13 +37,10 @@ type ParallelTuple<A, B> = [A, B | undefined];
|
|
|
41
37
|
*
|
|
42
38
|
* If `secondArray` is shorter than `firstArray`, the second position in the tuple
|
|
43
39
|
* will be `undefined`. Iteration always uses the length of the first array.
|
|
44
|
-
*
|
|
45
40
|
* @template FirstArrayItem
|
|
46
41
|
* @template SecondArrayItem
|
|
47
|
-
*
|
|
48
42
|
* @param firstArray - The first array. Each item in this will take up the first tuple spot.
|
|
49
43
|
* @param secondArray - The second array. Each item in this will take up the second tuple spot.
|
|
50
|
-
*
|
|
51
44
|
* @returns An array of `[firstItem, secondItem]` tuples for each index in `firstArray`.
|
|
52
45
|
*/
|
|
53
46
|
declare function paralleliseArrays<FirstArrayItem, SecondArrayItem>(firstArray: readonly FirstArrayItem[], secondArray: readonly SecondArrayItem[]): ParallelTuple<FirstArrayItem, SecondArrayItem>[];
|
|
@@ -77,10 +70,12 @@ declare class APIError extends Error {
|
|
|
77
70
|
declare class DataError extends Error {
|
|
78
71
|
data: unknown;
|
|
79
72
|
code: string;
|
|
80
|
-
/**
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
73
|
+
/**
|
|
74
|
+
* @param data - The data that caused the error.
|
|
75
|
+
* @param message - A human-readable error message (e.g. The data provided is invalid).
|
|
76
|
+
* @param code - A standardised code (e.g. UNEXPECTED_DATA).
|
|
77
|
+
* @param options - Extra options to pass to super Error constructor.
|
|
78
|
+
*/
|
|
84
79
|
constructor(data: unknown, message?: string, code?: string, options?: ErrorOptions);
|
|
85
80
|
static check(input: unknown): input is DataError;
|
|
86
81
|
}
|
|
@@ -243,9 +238,16 @@ interface RemoveIndentsOptions {
|
|
|
243
238
|
preserveTabs?: boolean;
|
|
244
239
|
}
|
|
245
240
|
type RemoveIndentsFunction = (strings: TemplateStringsArray, ...interpolations: unknown[]) => string;
|
|
246
|
-
/**
|
|
241
|
+
/**
|
|
242
|
+
* @param options
|
|
243
|
+
* @deprecated This function has been renamed to normaliseIndents
|
|
244
|
+
*/
|
|
247
245
|
declare function removeIndents(options: RemoveIndentsOptions): RemoveIndentsFunction;
|
|
248
|
-
/**
|
|
246
|
+
/**
|
|
247
|
+
* @param strings
|
|
248
|
+
* @param interpolations
|
|
249
|
+
* @deprecated This function has been renamed to normaliseIndents
|
|
250
|
+
*/
|
|
249
251
|
declare function removeIndents(strings: TemplateStringsArray, ...interpolations: unknown[]): string;
|
|
250
252
|
//#endregion
|
|
251
253
|
//#region src/functions/truncate.d.ts
|
package/dist/index.js
CHANGED
|
@@ -22,11 +22,9 @@ var appendSemicolon_default = appendSemicolon;
|
|
|
22
22
|
*
|
|
23
23
|
* If the callback returns at least one Promise, the entire result will be wrapped
|
|
24
24
|
* in a `Promise` and resolved with `Promise.all`. Otherwise, a plain array is returned.
|
|
25
|
-
*
|
|
26
25
|
* @template ItemType
|
|
27
26
|
* @param callback - A function invoked with the current index. May return a value or a Promise.
|
|
28
|
-
* @param [length
|
|
29
|
-
*
|
|
27
|
+
* @param [length] - The desired length of the resulting array.
|
|
30
28
|
* @returns An array of the callback results, or a Promise resolving to one if the callback is async.
|
|
31
29
|
*/
|
|
32
30
|
function fillArray(callback, length = 1) {
|
|
@@ -47,13 +45,10 @@ var fillArray_default = fillArray;
|
|
|
47
45
|
*
|
|
48
46
|
* If `secondArray` is shorter than `firstArray`, the second position in the tuple
|
|
49
47
|
* will be `undefined`. Iteration always uses the length of the first array.
|
|
50
|
-
*
|
|
51
48
|
* @template FirstArrayItem
|
|
52
49
|
* @template SecondArrayItem
|
|
53
|
-
*
|
|
54
50
|
* @param firstArray - The first array. Each item in this will take up the first tuple spot.
|
|
55
51
|
* @param secondArray - The second array. Each item in this will take up the second tuple spot.
|
|
56
|
-
*
|
|
57
52
|
* @returns An array of `[firstItem, secondItem]` tuples for each index in `firstArray`.
|
|
58
53
|
*/
|
|
59
54
|
function paralleliseArrays(firstArray, secondArray) {
|
|
@@ -448,10 +443,12 @@ var APIError_default = APIError;
|
|
|
448
443
|
var DataError = class extends Error {
|
|
449
444
|
data;
|
|
450
445
|
code;
|
|
451
|
-
/**
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
446
|
+
/**
|
|
447
|
+
* @param data - The data that caused the error.
|
|
448
|
+
* @param message - A human-readable error message (e.g. The data provided is invalid).
|
|
449
|
+
* @param code - A standardised code (e.g. UNEXPECTED_DATA).
|
|
450
|
+
* @param options - Extra options to pass to super Error constructor.
|
|
451
|
+
*/
|
|
455
452
|
constructor(data, message = "The data provided is invalid", code = "INVALID_DATA", options) {
|
|
456
453
|
super(message, options);
|
|
457
454
|
if (Error.captureStackTrace) Error.captureStackTrace(this, new.target);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alextheman/utility",
|
|
3
|
-
"version": "3.5.
|
|
3
|
+
"version": "3.5.7",
|
|
4
4
|
"description": "Helpful utility functions",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -19,15 +19,15 @@
|
|
|
19
19
|
"zod": "^4.1.13"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
|
-
"@alextheman/eslint-plugin": "^4.
|
|
23
|
-
"@types/node": "^
|
|
22
|
+
"@alextheman/eslint-plugin": "^4.5.1",
|
|
23
|
+
"@types/node": "^25.0.1",
|
|
24
24
|
"dotenv-cli": "^11.0.0",
|
|
25
25
|
"eslint": "^9.39.1",
|
|
26
26
|
"globals": "^16.5.0",
|
|
27
27
|
"husky": "^9.1.7",
|
|
28
|
-
"jsdom": "^27.
|
|
28
|
+
"jsdom": "^27.3.0",
|
|
29
29
|
"prettier": "^3.7.4",
|
|
30
|
-
"tsdown": "^0.17.
|
|
30
|
+
"tsdown": "^0.17.3",
|
|
31
31
|
"typescript": "^5.9.3",
|
|
32
32
|
"vite-tsconfig-paths": "^5.1.4",
|
|
33
33
|
"vitest": "^4.0.15"
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"lint-prettier-typescript": "prettier --check --parser typescript \"./**/*.ts\"",
|
|
51
51
|
"lint-tsc": "tsc --noEmit",
|
|
52
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
|
|
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 file:\"$ESLINT_PLUGIN_PATH\"'",
|
|
54
54
|
"test": "vitest run",
|
|
55
55
|
"test-watch": "vitest",
|
|
56
56
|
"update-dependencies": "pnpm update --latest && pnpm update",
|