@alextheman/utility 3.5.4 → 3.5.6

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 CHANGED
@@ -46,6 +46,16 @@ 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
+ * @template ItemType
55
+ * @param callback - A function invoked with the current index. May return a value or a Promise.
56
+ * @param [length] - The desired length of the resulting array.
57
+ * @returns An array of the callback results, or a Promise resolving to one if the callback is async.
58
+ */
49
59
  function fillArray(callback, length = 1) {
50
60
  const outputArray = new Array(length).fill(null).map((_, index) => {
51
61
  return callback(index);
@@ -59,6 +69,17 @@ var fillArray_default = fillArray;
59
69
 
60
70
  //#endregion
61
71
  //#region src/functions/arrayHelpers/paralleliseArrays.ts
72
+ /**
73
+ * Creates a new array of tuples, each containing the item at the given index from both arrays.
74
+ *
75
+ * If `secondArray` is shorter than `firstArray`, the second position in the tuple
76
+ * will be `undefined`. Iteration always uses the length of the first array.
77
+ * @template FirstArrayItem
78
+ * @template SecondArrayItem
79
+ * @param firstArray - The first array. Each item in this will take up the first tuple spot.
80
+ * @param secondArray - The second array. Each item in this will take up the second tuple spot.
81
+ * @returns An array of `[firstItem, secondItem]` tuples for each index in `firstArray`.
82
+ */
62
83
  function paralleliseArrays(firstArray, secondArray) {
63
84
  const outputArray = [];
64
85
  for (let i = 0; i < firstArray.length; i++) outputArray.push([firstArray[i], secondArray[i]]);
@@ -451,10 +472,12 @@ var APIError_default = APIError;
451
472
  var DataError = class extends Error {
452
473
  data;
453
474
  code;
454
- /** @param data - The data that caused the error. */
455
- /** @param message - A human-readable error message (e.g. The data provided is invalid). */
456
- /** @param code - A standardised code (e.g. UNEXPECTED_DATA). */
457
- /** @param options - Extra options to pass to super Error constructor. */
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
+ */
458
481
  constructor(data, message = "The data provided is invalid", code = "INVALID_DATA", options) {
459
482
  super(message, options);
460
483
  if (Error.captureStackTrace) Error.captureStackTrace(this, new.target);
package/dist/index.d.cts CHANGED
@@ -7,12 +7,43 @@ 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
- declare function fillArray<T>(callback: (index: number) => Promise<T>, length?: number): Promise<T[]>;
11
- declare function fillArray<T>(callback: (index: number) => T, length?: number): T[];
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
+ * @template ItemType
16
+ * @param callback - An asynchronous function invoked with the current index.
17
+ * @param [length] - The desired length of the resulting array.
18
+ * @returns A Promise resolving to an array of the callback results.
19
+ */
20
+ declare function fillArray<ItemType$1>(callback: (index: number) => Promise<ItemType$1>, length?: number): Promise<ItemType$1[]>;
21
+ /**
22
+ * Creates a new array where each element is the result of the provided synchronous callback.
23
+ *
24
+ * The callback will be invoked once for each index from `0` to `length - 1`.
25
+ * If no length is provided, a single-element array will be produced.
26
+ * @template ItemType
27
+ * @param callback - A synchronous function invoked with the current index.
28
+ * @param [length] - The desired length of the resulting array.
29
+ * @returns An array of the callback results.
30
+ */
31
+ declare function fillArray<ItemType$1>(callback: (index: number) => ItemType$1, length?: number): ItemType$1[];
12
32
  //#endregion
13
33
  //#region src/functions/arrayHelpers/paralleliseArrays.d.ts
14
34
  type ParallelTuple<A, B> = [A, B | undefined];
15
- declare function paralleliseArrays<FirstArrayItem, SecondArrayItem>(firstArray: FirstArrayItem[] | readonly FirstArrayItem[], secondArray: SecondArrayItem[] | readonly SecondArrayItem[]): ParallelTuple<FirstArrayItem, SecondArrayItem>[];
35
+ /**
36
+ * Creates a new array of tuples, each containing the item at the given index from both arrays.
37
+ *
38
+ * If `secondArray` is shorter than `firstArray`, the second position in the tuple
39
+ * will be `undefined`. Iteration always uses the length of the first array.
40
+ * @template FirstArrayItem
41
+ * @template SecondArrayItem
42
+ * @param firstArray - The first array. Each item in this will take up the first tuple spot.
43
+ * @param secondArray - The second array. Each item in this will take up the second tuple spot.
44
+ * @returns An array of `[firstItem, secondItem]` tuples for each index in `firstArray`.
45
+ */
46
+ declare function paralleliseArrays<FirstArrayItem, SecondArrayItem>(firstArray: readonly FirstArrayItem[], secondArray: readonly SecondArrayItem[]): ParallelTuple<FirstArrayItem, SecondArrayItem>[];
16
47
  //#endregion
17
48
  //#region src/functions/arrayHelpers/randomiseArray.d.ts
18
49
  declare function randomiseArray<T>(array: T[]): T[];
@@ -39,10 +70,12 @@ declare class APIError extends Error {
39
70
  declare class DataError extends Error {
40
71
  data: unknown;
41
72
  code: string;
42
- /** @param data - The data that caused the error. */
43
- /** @param message - A human-readable error message (e.g. The data provided is invalid). */
44
- /** @param code - A standardised code (e.g. UNEXPECTED_DATA). */
45
- /** @param options - Extra options to pass to super Error constructor. */
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
+ */
46
79
  constructor(data: unknown, message?: string, code?: string, options?: ErrorOptions);
47
80
  static check(input: unknown): input is DataError;
48
81
  }
@@ -205,9 +238,16 @@ interface RemoveIndentsOptions {
205
238
  preserveTabs?: boolean;
206
239
  }
207
240
  type RemoveIndentsFunction = (strings: TemplateStringsArray, ...interpolations: unknown[]) => string;
208
- /** @deprecated This function has been renamed to normaliseIndents */
241
+ /**
242
+ * @param options
243
+ * @deprecated This function has been renamed to normaliseIndents
244
+ */
209
245
  declare function removeIndents(options: RemoveIndentsOptions): RemoveIndentsFunction;
210
- /** @deprecated This function has been renamed to normaliseIndents */
246
+ /**
247
+ * @param strings
248
+ * @param interpolations
249
+ * @deprecated This function has been renamed to normaliseIndents
250
+ */
211
251
  declare function removeIndents(strings: TemplateStringsArray, ...interpolations: unknown[]): string;
212
252
  //#endregion
213
253
  //#region src/functions/truncate.d.ts
package/dist/index.d.ts CHANGED
@@ -7,12 +7,43 @@ 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
- declare function fillArray<T>(callback: (index: number) => Promise<T>, length?: number): Promise<T[]>;
11
- declare function fillArray<T>(callback: (index: number) => T, length?: number): T[];
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
+ * @template ItemType
16
+ * @param callback - An asynchronous function invoked with the current index.
17
+ * @param [length] - The desired length of the resulting array.
18
+ * @returns A Promise resolving to an array of the callback results.
19
+ */
20
+ declare function fillArray<ItemType$1>(callback: (index: number) => Promise<ItemType$1>, length?: number): Promise<ItemType$1[]>;
21
+ /**
22
+ * Creates a new array where each element is the result of the provided synchronous callback.
23
+ *
24
+ * The callback will be invoked once for each index from `0` to `length - 1`.
25
+ * If no length is provided, a single-element array will be produced.
26
+ * @template ItemType
27
+ * @param callback - A synchronous function invoked with the current index.
28
+ * @param [length] - The desired length of the resulting array.
29
+ * @returns An array of the callback results.
30
+ */
31
+ declare function fillArray<ItemType$1>(callback: (index: number) => ItemType$1, length?: number): ItemType$1[];
12
32
  //#endregion
13
33
  //#region src/functions/arrayHelpers/paralleliseArrays.d.ts
14
34
  type ParallelTuple<A, B> = [A, B | undefined];
15
- declare function paralleliseArrays<FirstArrayItem, SecondArrayItem>(firstArray: FirstArrayItem[] | readonly FirstArrayItem[], secondArray: SecondArrayItem[] | readonly SecondArrayItem[]): ParallelTuple<FirstArrayItem, SecondArrayItem>[];
35
+ /**
36
+ * Creates a new array of tuples, each containing the item at the given index from both arrays.
37
+ *
38
+ * If `secondArray` is shorter than `firstArray`, the second position in the tuple
39
+ * will be `undefined`. Iteration always uses the length of the first array.
40
+ * @template FirstArrayItem
41
+ * @template SecondArrayItem
42
+ * @param firstArray - The first array. Each item in this will take up the first tuple spot.
43
+ * @param secondArray - The second array. Each item in this will take up the second tuple spot.
44
+ * @returns An array of `[firstItem, secondItem]` tuples for each index in `firstArray`.
45
+ */
46
+ declare function paralleliseArrays<FirstArrayItem, SecondArrayItem>(firstArray: readonly FirstArrayItem[], secondArray: readonly SecondArrayItem[]): ParallelTuple<FirstArrayItem, SecondArrayItem>[];
16
47
  //#endregion
17
48
  //#region src/functions/arrayHelpers/randomiseArray.d.ts
18
49
  declare function randomiseArray<T>(array: T[]): T[];
@@ -39,10 +70,12 @@ declare class APIError extends Error {
39
70
  declare class DataError extends Error {
40
71
  data: unknown;
41
72
  code: string;
42
- /** @param data - The data that caused the error. */
43
- /** @param message - A human-readable error message (e.g. The data provided is invalid). */
44
- /** @param code - A standardised code (e.g. UNEXPECTED_DATA). */
45
- /** @param options - Extra options to pass to super Error constructor. */
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
+ */
46
79
  constructor(data: unknown, message?: string, code?: string, options?: ErrorOptions);
47
80
  static check(input: unknown): input is DataError;
48
81
  }
@@ -205,9 +238,16 @@ interface RemoveIndentsOptions {
205
238
  preserveTabs?: boolean;
206
239
  }
207
240
  type RemoveIndentsFunction = (strings: TemplateStringsArray, ...interpolations: unknown[]) => string;
208
- /** @deprecated This function has been renamed to normaliseIndents */
241
+ /**
242
+ * @param options
243
+ * @deprecated This function has been renamed to normaliseIndents
244
+ */
209
245
  declare function removeIndents(options: RemoveIndentsOptions): RemoveIndentsFunction;
210
- /** @deprecated This function has been renamed to normaliseIndents */
246
+ /**
247
+ * @param strings
248
+ * @param interpolations
249
+ * @deprecated This function has been renamed to normaliseIndents
250
+ */
211
251
  declare function removeIndents(strings: TemplateStringsArray, ...interpolations: unknown[]): string;
212
252
  //#endregion
213
253
  //#region src/functions/truncate.d.ts
package/dist/index.js CHANGED
@@ -17,6 +17,16 @@ 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
+ * @template ItemType
26
+ * @param callback - A function invoked with the current index. May return a value or a Promise.
27
+ * @param [length] - The desired length of the resulting array.
28
+ * @returns An array of the callback results, or a Promise resolving to one if the callback is async.
29
+ */
20
30
  function fillArray(callback, length = 1) {
21
31
  const outputArray = new Array(length).fill(null).map((_, index) => {
22
32
  return callback(index);
@@ -30,6 +40,17 @@ var fillArray_default = fillArray;
30
40
 
31
41
  //#endregion
32
42
  //#region src/functions/arrayHelpers/paralleliseArrays.ts
43
+ /**
44
+ * Creates a new array of tuples, each containing the item at the given index from both arrays.
45
+ *
46
+ * If `secondArray` is shorter than `firstArray`, the second position in the tuple
47
+ * will be `undefined`. Iteration always uses the length of the first array.
48
+ * @template FirstArrayItem
49
+ * @template SecondArrayItem
50
+ * @param firstArray - The first array. Each item in this will take up the first tuple spot.
51
+ * @param secondArray - The second array. Each item in this will take up the second tuple spot.
52
+ * @returns An array of `[firstItem, secondItem]` tuples for each index in `firstArray`.
53
+ */
33
54
  function paralleliseArrays(firstArray, secondArray) {
34
55
  const outputArray = [];
35
56
  for (let i = 0; i < firstArray.length; i++) outputArray.push([firstArray[i], secondArray[i]]);
@@ -422,10 +443,12 @@ var APIError_default = APIError;
422
443
  var DataError = class extends Error {
423
444
  data;
424
445
  code;
425
- /** @param data - The data that caused the error. */
426
- /** @param message - A human-readable error message (e.g. The data provided is invalid). */
427
- /** @param code - A standardised code (e.g. UNEXPECTED_DATA). */
428
- /** @param options - Extra options to pass to super Error constructor. */
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
+ */
429
452
  constructor(data, message = "The data provided is invalid", code = "INVALID_DATA", options) {
430
453
  super(message, options);
431
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.4",
3
+ "version": "3.5.6",
4
4
  "description": "Helpful utility functions",
5
5
  "repository": {
6
6
  "type": "git",
@@ -19,14 +19,15 @@
19
19
  "zod": "^4.1.13"
20
20
  },
21
21
  "devDependencies": {
22
- "@alextheman/eslint-plugin": "^4.3.0",
23
- "@types/node": "^24.10.1",
22
+ "@alextheman/eslint-plugin": "^4.5.1",
23
+ "@types/node": "^25.0.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",
27
- "jsdom": "^27.2.0",
28
+ "jsdom": "^27.3.0",
28
29
  "prettier": "^3.7.4",
29
- "tsdown": "^0.17.0",
30
+ "tsdown": "^0.17.3",
30
31
  "typescript": "^5.9.3",
31
32
  "vite-tsconfig-paths": "^5.1.4",
32
33
  "vitest": "^4.0.15"
@@ -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 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 uninstall @alextheman/eslint-plugin && pnpm install --save-dev @alextheman/eslint-plugin",
55
- "use-local-eslint-plugin": "npm --prefix ../eslint-plugin run create-local-package && pnpm uninstall @alextheman/eslint-plugin && pnpm install --save-dev ../eslint-plugin/alextheman-eslint-plugin-*.tgz"
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
  }