@alextheman/utility 3.5.7 → 3.5.9

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
@@ -51,9 +51,12 @@ 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
+ *
54
55
  * @template ItemType
56
+ *
55
57
  * @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.
58
+ * @param length - The desired length of the resulting array.
59
+ *
57
60
  * @returns An array of the callback results, or a Promise resolving to one if the callback is async.
58
61
  */
59
62
  function fillArray(callback, length = 1) {
@@ -74,10 +77,13 @@ var fillArray_default = fillArray;
74
77
  *
75
78
  * If `secondArray` is shorter than `firstArray`, the second position in the tuple
76
79
  * will be `undefined`. Iteration always uses the length of the first array.
80
+ *
77
81
  * @template FirstArrayItem
78
82
  * @template SecondArrayItem
83
+ *
79
84
  * @param firstArray - The first array. Each item in this will take up the first tuple spot.
80
85
  * @param secondArray - The second array. Each item in this will take up the second tuple spot.
86
+ *
81
87
  * @returns An array of `[firstItem, secondItem]` tuples for each index in `firstArray`.
82
88
  */
83
89
  function paralleliseArrays(firstArray, secondArray) {
@@ -113,6 +119,15 @@ var getRandomNumber_default = getRandomNumber;
113
119
 
114
120
  //#endregion
115
121
  //#region src/functions/arrayHelpers/randomiseArray.ts
122
+ /**
123
+ * Randomises the order of a given array and returns the result in a new array without mutating the original.
124
+ *
125
+ * @template ItemType - The type of the array items.
126
+ *
127
+ * @param array - The array to randomise.
128
+ *
129
+ * @returns A new array with the items randomised.
130
+ */
116
131
  function randomiseArray(array) {
117
132
  const mutableArray = [...array];
118
133
  const outputArray = [];
@@ -126,6 +141,21 @@ var randomiseArray_default = randomiseArray;
126
141
 
127
142
  //#endregion
128
143
  //#region src/functions/arrayHelpers/range.ts
144
+ /**
145
+ * Creates an array of numbers within a given range.
146
+ *
147
+ * The range is inclusive of `start` and exclusive of `stop`.
148
+ * The sign of `step` must match the direction of the range.
149
+ *
150
+ * @param start - The number to start at (inclusive).
151
+ * @param stop - The number to stop at (exclusive).
152
+ * @param step - The step size between numbers, defaulting to 1.
153
+ *
154
+ * @throws {Error} If `step` is `0`.
155
+ * @throws {Error} If `step` direction does not match the order of `start` and `stop`.
156
+ *
157
+ * @returns An array of numbers satisfying the range provided.
158
+ */
129
159
  function range(start, stop, step = 1) {
130
160
  const numbers = [];
131
161
  if (step === 0) throw new Error("ZERO_STEP_SIZE_NOT_ALLOWED");
package/dist/index.d.cts CHANGED
@@ -12,9 +12,12 @@ 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
+ *
15
16
  * @template ItemType
17
+ *
16
18
  * @param callback - An asynchronous function invoked with the current index.
17
- * @param [length] - The desired length of the resulting array.
19
+ * @param length - The desired length of the resulting array.
20
+ *
18
21
  * @returns A Promise resolving to an array of the callback results.
19
22
  */
20
23
  declare function fillArray<ItemType$1>(callback: (index: number) => Promise<ItemType$1>, length?: number): Promise<ItemType$1[]>;
@@ -23,9 +26,12 @@ declare function fillArray<ItemType$1>(callback: (index: number) => Promise<Item
23
26
  *
24
27
  * The callback will be invoked once for each index from `0` to `length - 1`.
25
28
  * If no length is provided, a single-element array will be produced.
29
+ *
26
30
  * @template ItemType
31
+ *
27
32
  * @param callback - A synchronous function invoked with the current index.
28
- * @param [length] - The desired length of the resulting array.
33
+ * @param length - The desired length of the resulting array.
34
+ *
29
35
  * @returns An array of the callback results.
30
36
  */
31
37
  declare function fillArray<ItemType$1>(callback: (index: number) => ItemType$1, length?: number): ItemType$1[];
@@ -37,18 +43,45 @@ type ParallelTuple<A, B> = [A, B | undefined];
37
43
  *
38
44
  * If `secondArray` is shorter than `firstArray`, the second position in the tuple
39
45
  * will be `undefined`. Iteration always uses the length of the first array.
46
+ *
40
47
  * @template FirstArrayItem
41
48
  * @template SecondArrayItem
49
+ *
42
50
  * @param firstArray - The first array. Each item in this will take up the first tuple spot.
43
51
  * @param secondArray - The second array. Each item in this will take up the second tuple spot.
52
+ *
44
53
  * @returns An array of `[firstItem, secondItem]` tuples for each index in `firstArray`.
45
54
  */
46
55
  declare function paralleliseArrays<FirstArrayItem, SecondArrayItem>(firstArray: readonly FirstArrayItem[], secondArray: readonly SecondArrayItem[]): ParallelTuple<FirstArrayItem, SecondArrayItem>[];
47
56
  //#endregion
48
57
  //#region src/functions/arrayHelpers/randomiseArray.d.ts
49
- declare function randomiseArray<T>(array: T[]): T[];
58
+ /**
59
+ * Randomises the order of a given array and returns the result in a new array without mutating the original.
60
+ *
61
+ * @template ItemType - The type of the array items.
62
+ *
63
+ * @param array - The array to randomise.
64
+ *
65
+ * @returns A new array with the items randomised.
66
+ */
67
+ declare function randomiseArray<ItemType$1>(array: ItemType$1[]): ItemType$1[];
50
68
  //#endregion
51
69
  //#region src/functions/arrayHelpers/range.d.ts
70
+ /**
71
+ * Creates an array of numbers within a given range.
72
+ *
73
+ * The range is inclusive of `start` and exclusive of `stop`.
74
+ * The sign of `step` must match the direction of the range.
75
+ *
76
+ * @param start - The number to start at (inclusive).
77
+ * @param stop - The number to stop at (exclusive).
78
+ * @param step - The step size between numbers, defaulting to 1.
79
+ *
80
+ * @throws {Error} If `step` is `0`.
81
+ * @throws {Error} If `step` direction does not match the order of `start` and `stop`.
82
+ *
83
+ * @returns An array of numbers satisfying the range provided.
84
+ */
52
85
  declare function range(start: number, stop: number, step?: number): number[];
53
86
  //#endregion
54
87
  //#region src/functions/camelToKebab.d.ts
package/dist/index.d.ts CHANGED
@@ -12,9 +12,12 @@ 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
+ *
15
16
  * @template ItemType
17
+ *
16
18
  * @param callback - An asynchronous function invoked with the current index.
17
- * @param [length] - The desired length of the resulting array.
19
+ * @param length - The desired length of the resulting array.
20
+ *
18
21
  * @returns A Promise resolving to an array of the callback results.
19
22
  */
20
23
  declare function fillArray<ItemType$1>(callback: (index: number) => Promise<ItemType$1>, length?: number): Promise<ItemType$1[]>;
@@ -23,9 +26,12 @@ declare function fillArray<ItemType$1>(callback: (index: number) => Promise<Item
23
26
  *
24
27
  * The callback will be invoked once for each index from `0` to `length - 1`.
25
28
  * If no length is provided, a single-element array will be produced.
29
+ *
26
30
  * @template ItemType
31
+ *
27
32
  * @param callback - A synchronous function invoked with the current index.
28
- * @param [length] - The desired length of the resulting array.
33
+ * @param length - The desired length of the resulting array.
34
+ *
29
35
  * @returns An array of the callback results.
30
36
  */
31
37
  declare function fillArray<ItemType$1>(callback: (index: number) => ItemType$1, length?: number): ItemType$1[];
@@ -37,18 +43,45 @@ type ParallelTuple<A, B> = [A, B | undefined];
37
43
  *
38
44
  * If `secondArray` is shorter than `firstArray`, the second position in the tuple
39
45
  * will be `undefined`. Iteration always uses the length of the first array.
46
+ *
40
47
  * @template FirstArrayItem
41
48
  * @template SecondArrayItem
49
+ *
42
50
  * @param firstArray - The first array. Each item in this will take up the first tuple spot.
43
51
  * @param secondArray - The second array. Each item in this will take up the second tuple spot.
52
+ *
44
53
  * @returns An array of `[firstItem, secondItem]` tuples for each index in `firstArray`.
45
54
  */
46
55
  declare function paralleliseArrays<FirstArrayItem, SecondArrayItem>(firstArray: readonly FirstArrayItem[], secondArray: readonly SecondArrayItem[]): ParallelTuple<FirstArrayItem, SecondArrayItem>[];
47
56
  //#endregion
48
57
  //#region src/functions/arrayHelpers/randomiseArray.d.ts
49
- declare function randomiseArray<T>(array: T[]): T[];
58
+ /**
59
+ * Randomises the order of a given array and returns the result in a new array without mutating the original.
60
+ *
61
+ * @template ItemType - The type of the array items.
62
+ *
63
+ * @param array - The array to randomise.
64
+ *
65
+ * @returns A new array with the items randomised.
66
+ */
67
+ declare function randomiseArray<ItemType$1>(array: ItemType$1[]): ItemType$1[];
50
68
  //#endregion
51
69
  //#region src/functions/arrayHelpers/range.d.ts
70
+ /**
71
+ * Creates an array of numbers within a given range.
72
+ *
73
+ * The range is inclusive of `start` and exclusive of `stop`.
74
+ * The sign of `step` must match the direction of the range.
75
+ *
76
+ * @param start - The number to start at (inclusive).
77
+ * @param stop - The number to stop at (exclusive).
78
+ * @param step - The step size between numbers, defaulting to 1.
79
+ *
80
+ * @throws {Error} If `step` is `0`.
81
+ * @throws {Error} If `step` direction does not match the order of `start` and `stop`.
82
+ *
83
+ * @returns An array of numbers satisfying the range provided.
84
+ */
52
85
  declare function range(start: number, stop: number, step?: number): number[];
53
86
  //#endregion
54
87
  //#region src/functions/camelToKebab.d.ts
package/dist/index.js CHANGED
@@ -22,9 +22,12 @@ 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
+ *
25
26
  * @template ItemType
27
+ *
26
28
  * @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.
29
+ * @param length - The desired length of the resulting array.
30
+ *
28
31
  * @returns An array of the callback results, or a Promise resolving to one if the callback is async.
29
32
  */
30
33
  function fillArray(callback, length = 1) {
@@ -45,10 +48,13 @@ var fillArray_default = fillArray;
45
48
  *
46
49
  * If `secondArray` is shorter than `firstArray`, the second position in the tuple
47
50
  * will be `undefined`. Iteration always uses the length of the first array.
51
+ *
48
52
  * @template FirstArrayItem
49
53
  * @template SecondArrayItem
54
+ *
50
55
  * @param firstArray - The first array. Each item in this will take up the first tuple spot.
51
56
  * @param secondArray - The second array. Each item in this will take up the second tuple spot.
57
+ *
52
58
  * @returns An array of `[firstItem, secondItem]` tuples for each index in `firstArray`.
53
59
  */
54
60
  function paralleliseArrays(firstArray, secondArray) {
@@ -84,6 +90,15 @@ var getRandomNumber_default = getRandomNumber;
84
90
 
85
91
  //#endregion
86
92
  //#region src/functions/arrayHelpers/randomiseArray.ts
93
+ /**
94
+ * Randomises the order of a given array and returns the result in a new array without mutating the original.
95
+ *
96
+ * @template ItemType - The type of the array items.
97
+ *
98
+ * @param array - The array to randomise.
99
+ *
100
+ * @returns A new array with the items randomised.
101
+ */
87
102
  function randomiseArray(array) {
88
103
  const mutableArray = [...array];
89
104
  const outputArray = [];
@@ -97,6 +112,21 @@ var randomiseArray_default = randomiseArray;
97
112
 
98
113
  //#endregion
99
114
  //#region src/functions/arrayHelpers/range.ts
115
+ /**
116
+ * Creates an array of numbers within a given range.
117
+ *
118
+ * The range is inclusive of `start` and exclusive of `stop`.
119
+ * The sign of `step` must match the direction of the range.
120
+ *
121
+ * @param start - The number to start at (inclusive).
122
+ * @param stop - The number to stop at (exclusive).
123
+ * @param step - The step size between numbers, defaulting to 1.
124
+ *
125
+ * @throws {Error} If `step` is `0`.
126
+ * @throws {Error} If `step` direction does not match the order of `start` and `stop`.
127
+ *
128
+ * @returns An array of numbers satisfying the range provided.
129
+ */
100
130
  function range(start, stop, step = 1) {
101
131
  const numbers = [];
102
132
  if (step === 0) throw new Error("ZERO_STEP_SIZE_NOT_ALLOWED");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alextheman/utility",
3
- "version": "3.5.7",
3
+ "version": "3.5.9",
4
4
  "description": "Helpful utility functions",
5
5
  "repository": {
6
6
  "type": "git",
@@ -19,7 +19,7 @@
19
19
  "zod": "^4.1.13"
20
20
  },
21
21
  "devDependencies": {
22
- "@alextheman/eslint-plugin": "^4.5.1",
22
+ "@alextheman/eslint-plugin": "^4.8.0",
23
23
  "@types/node": "^25.0.1",
24
24
  "dotenv-cli": "^11.0.0",
25
25
  "eslint": "^9.39.1",