@bemoje/array 1.0.1 → 1.0.2
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/index.d.ts +367 -55
- package/index.mjs +54 -159
- package/package.json +1 -1
- package/lib/arrAverage.d.ts +0 -12
- package/lib/arrEachToString.d.ts +0 -12
- package/lib/arrFindIndicesOf.d.ts +0 -7
- package/lib/arrGetOrDefault.d.ts +0 -4
- package/lib/arrHasDuplicates.d.ts +0 -7
- package/lib/arrIndicesOf.d.ts +0 -14
- package/lib/arrLast.d.ts +0 -12
- package/lib/arrMapMutable.d.ts +0 -12
- package/lib/arrObjectsToTable.d.ts +0 -22
- package/lib/arrObjectsUniqueKeys.d.ts +0 -16
- package/lib/arrRemove.d.ts +0 -4
- package/lib/arrRemoveDuplicates.d.ts +0 -13
- package/lib/arrRemoveMutable.d.ts +0 -4
- package/lib/arrShuffle.d.ts +0 -13
- package/lib/arrSortNumeric.d.ts +0 -14
- package/lib/arrSortedInsertionIndex.d.ts +0 -16
- package/lib/arrSum.d.ts +0 -11
- package/lib/arrSwap.d.ts +0 -14
- package/lib/arrTableAssertRowsSameLength.d.ts +0 -25
- package/lib/arrTableEachToString.d.ts +0 -12
- package/lib/arrTableIterateAsObjects.d.ts +0 -4
- package/lib/arrTableRemoveColumns.d.ts +0 -7
- package/lib/arrTableToCsv.d.ts +0 -20
- package/lib/arrTableToObjects.d.ts +0 -22
- package/lib/arrayToString.d.ts +0 -4
package/index.d.ts
CHANGED
|
@@ -1,56 +1,368 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Calculates the average of an array of numbers.
|
|
3
|
+
* @returns The average of all numbers in the array.
|
|
4
|
+
* @throws an error if the input array is empty.
|
|
5
|
+
* @param array The array of numbers.
|
|
6
|
+
* @example ```ts
|
|
7
|
+
* const numbers = [1, 2, 3, 4, 5];
|
|
8
|
+
* arrAverage(numbers);
|
|
9
|
+
* //=> 3
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
declare function arrAverage(array: number[]): number;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Coerce each element of an array to string.
|
|
16
|
+
* @template T - The type of elements in the input array.
|
|
17
|
+
* @returns A new array where each element is the string representation of the corresponding element in the input array.
|
|
18
|
+
* @param array The array to iterate over.
|
|
19
|
+
* @example ```ts
|
|
20
|
+
* const numbers = [1, 2, 3];
|
|
21
|
+
* arrEachToString(numbers);
|
|
22
|
+
* //=> ['1', '2', '3']
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
declare function arrEachToString<T>(array: T[]): string[];
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Returns an array of indices where the predicate function returns true for the corresponding element in the input array.
|
|
29
|
+
* @param input - The array to search.
|
|
30
|
+
* @param predicate - The function to test each element of the array.
|
|
31
|
+
* @returns An array of indices where the predicate function returns true.
|
|
32
|
+
*/
|
|
33
|
+
declare function arrFindIndicesOf<T>(input: Array<T>, predicate: (value: T) => boolean): number[];
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Get array element at index or create it using factory function if it doesn't exist.
|
|
37
|
+
*/
|
|
38
|
+
declare function arrGetOrDefault<V>(array: V[], index: number, factory: (index: number) => V): V;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Checks if an array has any duplicate elements.
|
|
42
|
+
* @param arr - The array to check for duplicates.
|
|
43
|
+
* @returns A boolean indicating whether the array has duplicates.
|
|
44
|
+
* @typeParam T - The type of elements in the array.
|
|
45
|
+
*/
|
|
46
|
+
declare function arrHasDuplicates<T>(arr: T[]): boolean;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Returns all indexes at which an element is found.
|
|
50
|
+
* @param input The array to search
|
|
51
|
+
* @template T - The type of elements in the input array.
|
|
52
|
+
* @returns An array of indices where the specified element can be found.
|
|
53
|
+
* @param element The element to find
|
|
54
|
+
* @example ```ts
|
|
55
|
+
* const inputArray = [1, 2, 3, 2, 4, 2, 5];
|
|
56
|
+
* const elementToFind = 2;
|
|
57
|
+
* arrIndicesOf(inputArray, elementToFind);
|
|
58
|
+
* //=> [1, 3, 5]
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
declare function arrIndicesOf<T>(input: Array<T>, element: T): number[];
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Returns the last element of an array.
|
|
65
|
+
* Throws an error if the array is empty.
|
|
66
|
+
* @template T The type of elements in the array.
|
|
67
|
+
* @param array The array to get the last element from.
|
|
68
|
+
* @returns The last element of the array.
|
|
69
|
+
* @throws If the array is empty.
|
|
70
|
+
* @example const numbers = [1, 2, 3, 4, 5];
|
|
71
|
+
* const lastNumber = arrLast(numbers);
|
|
72
|
+
* //=> 5
|
|
73
|
+
*/
|
|
74
|
+
declare function arrLast<T>(array: T[]): T;
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* This function takes an array and a callback function as arguments. It applies the callback function to each element of the array, mutating the original array in the process.
|
|
78
|
+
* @template T The type of elements in the input array.
|
|
79
|
+
* @param input The array to be mapped over.
|
|
80
|
+
* @param f The callback function to be applied to each element of the array. This function takes three arguments: the current element, its index, and the original array.
|
|
81
|
+
* @returns The original array, mutated by the callback function.
|
|
82
|
+
* @example ```ts
|
|
83
|
+
* arrMapMutable([1, 2, 3], (value: number) => value * 2);
|
|
84
|
+
* //=> [2, 4, 6]
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
87
|
+
declare function arrMapMutable<T>(input: Array<T>, f: (value: T, index: number, array: T[]) => T): Array<T>;
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Convert an array of objects to a two-dimensional table.
|
|
91
|
+
* @param objects The array of objects to convert to a table.
|
|
92
|
+
* @template T - The type of the values in the objects.
|
|
93
|
+
* @param options.headers An optional array of strings specifying the headers (property names) to use. If not provided, the function will use all unique keys found in the objects.
|
|
94
|
+
* @param options.emptyCell An optional value to use for empty cells. If not provided, the function will use `undefined`.
|
|
95
|
+
* @returns A 2D array (table) where each row represents an object and each column represents a property of the object.
|
|
96
|
+
* @param options The options for converting the objects to a table.
|
|
97
|
+
* @example ```ts
|
|
98
|
+
* arrObjectsToTable(
|
|
99
|
+
* [
|
|
100
|
+
* { a: 1, b: 2 },
|
|
101
|
+
* { a: 3, b: 4, c: 5 },
|
|
102
|
+
* ],
|
|
103
|
+
* { emptyCell:1 },
|
|
104
|
+
* ) //=> [ [ 'a', 'b', 'c' ], [ 1, 2,1 ], [ 3, 4, 5 ] ]
|
|
105
|
+
* ```
|
|
106
|
+
*/
|
|
107
|
+
declare function arrObjectsToTable<T, E>(
|
|
108
|
+
objects: Record<string, T | undefined>[],
|
|
109
|
+
options?: {
|
|
110
|
+
headers?: string[];
|
|
111
|
+
emptyCell?: E;
|
|
112
|
+
},
|
|
113
|
+
): Array<Array<string | T | E>>;
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Returns an array of all unique object keys found in an array of objects.
|
|
117
|
+
* @template T - The type of values in the input objects.
|
|
118
|
+
* @returns An array of unique keys present in the input objects.
|
|
119
|
+
* @param objects The array of objects.
|
|
120
|
+
* @example ```ts
|
|
121
|
+
* const objects = [
|
|
122
|
+
* { name: 'John', age: 25 },
|
|
123
|
+
* { name: 'Jane', gender: 'female' },
|
|
124
|
+
* { name: 'Bob', age: 30, gender: 'male' },
|
|
125
|
+
* ];
|
|
126
|
+
* arrObjectsUniqueKeys(objects);
|
|
127
|
+
* //=> ['name', 'age', 'gender']
|
|
128
|
+
* ```
|
|
129
|
+
*/
|
|
130
|
+
declare function arrObjectsUniqueKeys<T>(objects: Record<string, T>[]): string[];
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Remove a given element from a copy of a given array and return the resulting array.
|
|
134
|
+
*/
|
|
135
|
+
declare function arrRemove<T>(arr: T[], elementToRemove: T): T[];
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Remove duplicates from an array
|
|
139
|
+
* @remarks This function uses the JavaScript Set object to remove duplicate values from an array.
|
|
140
|
+
* @typeparam T - The type of elements in the array.
|
|
141
|
+
* @returns The new array with duplicates removed.
|
|
142
|
+
* @param array The array from which to remove duplicates.
|
|
143
|
+
* @example ```ts
|
|
144
|
+
* const array = [1, 2, 2, 3, 4, 4, 5];
|
|
145
|
+
* arrRemoveDuplicates(array);
|
|
146
|
+
* //=> [1, 2, 3, 4, 5]
|
|
147
|
+
* ```
|
|
148
|
+
*/
|
|
149
|
+
declare function arrRemoveDuplicates<T>(array: T[]): T[];
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Remove elements in-place from an array.
|
|
153
|
+
*/
|
|
154
|
+
declare function arrRemoveMutable<T>(arr: T[], elementToRemove: T): void;
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Shuffle items in an array in-place. Guarantees changes.
|
|
158
|
+
* @remarks This function does not guarantee that the order of the elements will be different after shuffling.
|
|
159
|
+
* @typeparam T - The type of the elements in the input array.
|
|
160
|
+
* @returns The same array, but shuffled.
|
|
161
|
+
* @param input The array to shuffle.
|
|
162
|
+
* @example ```ts
|
|
163
|
+
* const input = [1, 2, 3, 4, 5];
|
|
164
|
+
* arrShuffle(input);
|
|
165
|
+
* //=> [3, 1, 5, 2, 4]
|
|
166
|
+
* ```
|
|
167
|
+
*/
|
|
168
|
+
declare function arrShuffle<T>(input: Array<T>): Array<T>;
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Sorts an array of numbers, bigints, or booleans in ascending order.
|
|
172
|
+
* @returns The sorted array.
|
|
173
|
+
* @remarks This function uses the JavaScript `Array.prototype.sort()` method, which sorts elements in place.
|
|
174
|
+
* Therefore, the original array will be modified.
|
|
175
|
+
* @throws If any element in the input array is not a number, bigint, or boolean.
|
|
176
|
+
* @param input The array to be sorted.
|
|
177
|
+
* @example ```ts
|
|
178
|
+
* const input = [5, 2n, true, 10, false];
|
|
179
|
+
* arrSortNumeric(input);
|
|
180
|
+
* //=> [false, true, 2n, 5, 10]
|
|
181
|
+
* ```
|
|
182
|
+
*/
|
|
183
|
+
declare function arrSortNumeric(input: Array<number | bigint | boolean>): Array<number | bigint | boolean>;
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Returns an index in the sorted array where the specified value could be inserted while maintaining the sorted order of the array.
|
|
187
|
+
* If the element is already in the array, returns the index after the last instance of the element.
|
|
188
|
+
* @param array - The sorted array to search.
|
|
189
|
+
* @param value - The value to locate in the array.
|
|
190
|
+
* @param comparator - A function that defines the sort order. If omitted, the array elements are converted to strings, then sorted according to each character's Unicode code point value.
|
|
191
|
+
* @returns The index at which the value could be inserted into array to maintain the array's sorted order.
|
|
192
|
+
* @example ```ts
|
|
193
|
+
* const array = [1, 2, 3, 5, 6];
|
|
194
|
+
* const value = 4;
|
|
195
|
+
* const comparator = (a, b) => a - b;
|
|
196
|
+
* const index = arrSortedLowerBound(array, value, comparator);
|
|
197
|
+
* console.log(index); // Output: 3
|
|
198
|
+
* ```
|
|
199
|
+
*/
|
|
200
|
+
declare function arrSortedInsertionIndex<T>(
|
|
201
|
+
array: readonly T[],
|
|
202
|
+
value: T,
|
|
203
|
+
comparator: (a: T, b: T) => number,
|
|
204
|
+
): number;
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Calculates the sum of an array of numbers.
|
|
208
|
+
* @returns The sum of all numbers in the array.
|
|
209
|
+
* @param array The array of numbers to sum.
|
|
210
|
+
* @example ```ts
|
|
211
|
+
* const numbers = [1, 2, 3, 4, 5];
|
|
212
|
+
* arrSum(numbers);
|
|
213
|
+
* //=> 15
|
|
214
|
+
* ```
|
|
215
|
+
*/
|
|
216
|
+
declare function arrSum(array: number[]): number;
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Swaps two elements in an array. This function takes an input array and swaps the elements at the specified indices.
|
|
220
|
+
* @param to The index of the element to swap to.
|
|
221
|
+
* @param from The index of the element to swap from.
|
|
222
|
+
* @template T - The type of elements in the array.
|
|
223
|
+
* @returns The modified array with swapped elements.
|
|
224
|
+
* @throws Will throw an error if 'from' or 'to' is not a valid index in the array.
|
|
225
|
+
* @param input The input array.
|
|
226
|
+
* @example ```ts
|
|
227
|
+
* const arr = [1, 2, 3, 4, 5]
|
|
228
|
+
* arrSwap(arr, 1, 3) //=> [1, 4, 3, 2, 5]
|
|
229
|
+
* ```
|
|
230
|
+
*/
|
|
231
|
+
declare function arrSwap<T>(input: Array<T>, from: number, to: number): Array<T>;
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* Asserts that all rows in a 2D array have the same length.
|
|
235
|
+
* @param - Optional array of headers to compare the row length against.
|
|
236
|
+
* @throws If any row in the array has a different length than the others.
|
|
237
|
+
* @param headers Optional. An array of headers. If provided, each row must have the same length as this array.
|
|
238
|
+
* @typeparam T - The type of elements in the rows.
|
|
239
|
+
* @param rows The 2D array to check.
|
|
240
|
+
* @example ```ts
|
|
241
|
+
* const rows = [
|
|
242
|
+
* [1, 2, 3],
|
|
243
|
+
* [4, 5, 6],
|
|
244
|
+
* [7, 8, 9],
|
|
245
|
+
* ];
|
|
246
|
+
* arrTableAssertRowsSameLength(rows);
|
|
247
|
+
* //=> undefined
|
|
248
|
+
* const rowsWithDifferentLength = [
|
|
249
|
+
* [1, 2, 3],
|
|
250
|
+
* [4, 5],
|
|
251
|
+
* [7, 8, 9],
|
|
252
|
+
* ];
|
|
253
|
+
* arrTableAssertRowsSameLength(rowsWithDifferentLength);
|
|
254
|
+
* //=> Error: Expected 3 columns, got 2
|
|
255
|
+
* ```
|
|
256
|
+
*/
|
|
257
|
+
declare function arrTableAssertRowsSameLength<T>(rows: T[][], headers?: string[]): void;
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* Coerce each value of a 2D array table to string.
|
|
261
|
+
* @template T - The type of the elements in the input array.
|
|
262
|
+
* @returns The converted 2D array where each element is a string.
|
|
263
|
+
* @param table The 2D array to convert.
|
|
264
|
+
* @example ```ts
|
|
265
|
+
* const input: number[][] = [[1, 2, 3], [4, 5, 6], [7, 8, 9]];
|
|
266
|
+
* arrTableEachToString(input);
|
|
267
|
+
* //=> [['1', '2', '3'], ['4', '5', '6'], ['7', '8', '9']]
|
|
268
|
+
* ```
|
|
269
|
+
*/
|
|
270
|
+
declare function arrTableEachToString<T>(table: T[][]): string[][];
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* Generator that iterates through a 2D array table, yielding objects with header keys and row values.
|
|
274
|
+
*/
|
|
275
|
+
declare function arrTableIterateAsObjects<T>(
|
|
276
|
+
rows: T[][],
|
|
277
|
+
headers: string[],
|
|
278
|
+
ignoreHeaders?: Set<string>,
|
|
279
|
+
): Generator<Record<string, T>, void, unknown>;
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* Removes specified columns from a 2D array table.
|
|
283
|
+
* @param table - The 2D array (table) from which columns will be removed. The first row of the table is assumed to contain column names.
|
|
284
|
+
* @param removeColumnNames - The names of the columns to be removed. These should match the entries in the first row of the table.
|
|
285
|
+
* @returns A new 2D array (table) with the specified columns removed.
|
|
286
|
+
*/
|
|
287
|
+
declare function arrTableRemoveColumns(table: string[][], ...removeColumnNames: string[]): string[][];
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
* Converts a 2D array to a CSV string.
|
|
291
|
+
* @param input The input 2D array.
|
|
292
|
+
* @remarks This function is useful for exporting data to CSV format.
|
|
293
|
+
* @param replaceLinebreakWith The character used to replace line breaks in the CSV string. Defaults to '|'.
|
|
294
|
+
* @typeparam T - The type of the elements in the input array.
|
|
295
|
+
* @returns The CSV string representation of the input array.
|
|
296
|
+
* @param delimiter The delimiter to use for separating values in the CSV string.
|
|
297
|
+
* @example ```ts
|
|
298
|
+
* const input = [
|
|
299
|
+
* ['Name', 'Age', 'Country'],
|
|
300
|
+
* ['John', '25', 'USA'],
|
|
301
|
+
* ['Alice', '30', 'Canada'],
|
|
302
|
+
* ['Bob', '35', 'UK'],
|
|
303
|
+
* ];
|
|
304
|
+
* arrTableToCsv(input);
|
|
305
|
+
* //=> "Name;Age;Country\nJohn;25;USA\nAlice;30;Canada\nBob;35;UK"
|
|
306
|
+
* ```
|
|
307
|
+
*/
|
|
308
|
+
declare function arrTableToCsv<T>(input: T[][], delimiter?: string, replaceLinebreakWith?: string): string;
|
|
309
|
+
|
|
310
|
+
/**
|
|
311
|
+
* Converts a 2D array representing a table into an array of objects.
|
|
312
|
+
* @param rows The 2D array representing the table.
|
|
313
|
+
* @template T - The type of the elements in the rows.
|
|
314
|
+
* @param headers The headers to use as keys for the objects. If not provided, the first row of the table is used as headers.
|
|
315
|
+
* @returns An array of objects, where each object represents a row in the table.
|
|
316
|
+
* @throws Throws an error if the headers are not provided and the table is empty or only contains one row.
|
|
317
|
+
* @param headers Optional array of headers for the table.
|
|
318
|
+
* @example ```ts
|
|
319
|
+
* const table = [
|
|
320
|
+
* ['Name', 'Age', 'Country'],
|
|
321
|
+
* ['John', 25, 'USA'],
|
|
322
|
+
* ['Jane', 30, 'Canada'],
|
|
323
|
+
* ];
|
|
324
|
+
* const headers = ['Name', 'Age', 'Country'];
|
|
325
|
+
* arrTableToObjects(table, headers) //=> [
|
|
326
|
+
* // { Name: 'John', Age: 25, Country: 'USA' },
|
|
327
|
+
* // { Name: 'Jane', Age: 30, Country: 'Canada' },
|
|
328
|
+
* // ]
|
|
329
|
+
* ```
|
|
330
|
+
*/
|
|
331
|
+
declare function arrTableToObjects<T>(
|
|
332
|
+
rows: T[][],
|
|
333
|
+
headers?: string[],
|
|
334
|
+
ignoreKeys?: Set<string>,
|
|
335
|
+
): Record<string, T>[];
|
|
336
|
+
|
|
337
|
+
/**
|
|
338
|
+
* Short and condensed string representation of an array, easy to read for error outputs or similar.
|
|
339
|
+
*/
|
|
340
|
+
declare function arrayToString<T>(array: T[]): string;
|
|
341
|
+
|
|
342
|
+
export {
|
|
343
|
+
arrAverage,
|
|
344
|
+
arrEachToString,
|
|
345
|
+
arrFindIndicesOf,
|
|
346
|
+
arrGetOrDefault,
|
|
347
|
+
arrHasDuplicates,
|
|
348
|
+
arrIndicesOf,
|
|
349
|
+
arrLast,
|
|
350
|
+
arrMapMutable,
|
|
351
|
+
arrObjectsToTable,
|
|
352
|
+
arrObjectsUniqueKeys,
|
|
353
|
+
arrRemove,
|
|
354
|
+
arrRemoveDuplicates,
|
|
355
|
+
arrRemoveMutable,
|
|
356
|
+
arrShuffle,
|
|
357
|
+
arrSortNumeric,
|
|
358
|
+
arrSortedInsertionIndex,
|
|
359
|
+
arrSum,
|
|
360
|
+
arrSwap,
|
|
361
|
+
arrTableAssertRowsSameLength,
|
|
362
|
+
arrTableEachToString,
|
|
363
|
+
arrTableIterateAsObjects,
|
|
364
|
+
arrTableRemoveColumns,
|
|
365
|
+
arrTableToCsv,
|
|
366
|
+
arrTableToObjects,
|
|
367
|
+
arrayToString,
|
|
55
368
|
};
|
|
56
|
-
export default _default;
|
package/index.mjs
CHANGED
|
@@ -1,50 +1,34 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
2
|
+
var __name = (target, value) => {
|
|
3
|
+
return __defProp(target, 'name', { value, configurable: true });
|
|
5
4
|
};
|
|
6
5
|
|
|
7
|
-
// src/lib/arrAverage.ts
|
|
8
|
-
var arrAverage_exports = {};
|
|
9
|
-
__export(arrAverage_exports, {
|
|
10
|
-
arrAverage: () => arrAverage
|
|
11
|
-
});
|
|
12
|
-
|
|
13
6
|
// src/lib/arrSum.ts
|
|
14
|
-
var arrSum_exports = {};
|
|
15
|
-
__export(arrSum_exports, {
|
|
16
|
-
arrSum: () => arrSum
|
|
17
|
-
});
|
|
18
7
|
function arrSum(array) {
|
|
19
8
|
return array.reduce((acc, cur) => {
|
|
20
9
|
return acc + cur;
|
|
21
10
|
}, 0);
|
|
22
11
|
}
|
|
12
|
+
__name(arrSum, 'arrSum');
|
|
23
13
|
|
|
24
14
|
// src/lib/arrAverage.ts
|
|
25
15
|
function arrAverage(array) {
|
|
26
16
|
if (!array.length) {
|
|
27
|
-
throw new Error(
|
|
17
|
+
throw new Error('Cannot take an average of zero values.');
|
|
28
18
|
}
|
|
29
19
|
return arrSum(array) / array.length;
|
|
30
20
|
}
|
|
21
|
+
__name(arrAverage, 'arrAverage');
|
|
31
22
|
|
|
32
23
|
// src/lib/arrEachToString.ts
|
|
33
|
-
var arrEachToString_exports = {};
|
|
34
|
-
__export(arrEachToString_exports, {
|
|
35
|
-
arrEachToString: () => arrEachToString
|
|
36
|
-
});
|
|
37
24
|
function arrEachToString(array) {
|
|
38
25
|
return array.map((element) => {
|
|
39
26
|
return `${element}`;
|
|
40
27
|
});
|
|
41
28
|
}
|
|
29
|
+
__name(arrEachToString, 'arrEachToString');
|
|
42
30
|
|
|
43
31
|
// src/lib/arrFindIndicesOf.ts
|
|
44
|
-
var arrFindIndicesOf_exports = {};
|
|
45
|
-
__export(arrFindIndicesOf_exports, {
|
|
46
|
-
arrFindIndicesOf: () => arrFindIndicesOf
|
|
47
|
-
});
|
|
48
32
|
function arrFindIndicesOf(input, predicate) {
|
|
49
33
|
const result = [];
|
|
50
34
|
for (let i = 0; i < input.length; i++) {
|
|
@@ -54,25 +38,19 @@ function arrFindIndicesOf(input, predicate) {
|
|
|
54
38
|
}
|
|
55
39
|
return result;
|
|
56
40
|
}
|
|
41
|
+
__name(arrFindIndicesOf, 'arrFindIndicesOf');
|
|
57
42
|
|
|
58
43
|
// src/lib/arrGetOrDefault.ts
|
|
59
|
-
var arrGetOrDefault_exports = {};
|
|
60
|
-
__export(arrGetOrDefault_exports, {
|
|
61
|
-
arrGetOrDefault: () => arrGetOrDefault
|
|
62
|
-
});
|
|
63
44
|
function arrGetOrDefault(array, index, factory) {
|
|
64
45
|
const value = array[index];
|
|
65
46
|
if (value !== void 0 || Object.hasOwn(array, index)) {
|
|
66
47
|
return value;
|
|
67
48
|
}
|
|
68
|
-
return array[index] = factory(index);
|
|
49
|
+
return (array[index] = factory(index));
|
|
69
50
|
}
|
|
51
|
+
__name(arrGetOrDefault, 'arrGetOrDefault');
|
|
70
52
|
|
|
71
53
|
// src/lib/arrHasDuplicates.ts
|
|
72
|
-
var arrHasDuplicates_exports = {};
|
|
73
|
-
__export(arrHasDuplicates_exports, {
|
|
74
|
-
arrHasDuplicates: () => arrHasDuplicates
|
|
75
|
-
});
|
|
76
54
|
function arrHasDuplicates(arr) {
|
|
77
55
|
const seen = /* @__PURE__ */ new Set();
|
|
78
56
|
for (const e of arr) {
|
|
@@ -83,12 +61,9 @@ function arrHasDuplicates(arr) {
|
|
|
83
61
|
}
|
|
84
62
|
return false;
|
|
85
63
|
}
|
|
64
|
+
__name(arrHasDuplicates, 'arrHasDuplicates');
|
|
86
65
|
|
|
87
66
|
// src/lib/arrIndicesOf.ts
|
|
88
|
-
var arrIndicesOf_exports = {};
|
|
89
|
-
__export(arrIndicesOf_exports, {
|
|
90
|
-
arrIndicesOf: () => arrIndicesOf
|
|
91
|
-
});
|
|
92
67
|
function arrIndicesOf(input, element) {
|
|
93
68
|
const result = [];
|
|
94
69
|
for (let i = 0; i < input.length; i++) {
|
|
@@ -98,42 +73,27 @@ function arrIndicesOf(input, element) {
|
|
|
98
73
|
}
|
|
99
74
|
return result;
|
|
100
75
|
}
|
|
76
|
+
__name(arrIndicesOf, 'arrIndicesOf');
|
|
101
77
|
|
|
102
78
|
// src/lib/arrLast.ts
|
|
103
|
-
var arrLast_exports = {};
|
|
104
|
-
__export(arrLast_exports, {
|
|
105
|
-
arrLast: () => arrLast
|
|
106
|
-
});
|
|
107
79
|
function arrLast(array) {
|
|
108
80
|
if (!array.length) {
|
|
109
|
-
throw new Error(
|
|
81
|
+
throw new Error('Cannot get last element of empty array.');
|
|
110
82
|
}
|
|
111
83
|
return array[array.length - 1];
|
|
112
84
|
}
|
|
85
|
+
__name(arrLast, 'arrLast');
|
|
113
86
|
|
|
114
87
|
// src/lib/arrMapMutable.ts
|
|
115
|
-
var arrMapMutable_exports = {};
|
|
116
|
-
__export(arrMapMutable_exports, {
|
|
117
|
-
arrMapMutable: () => arrMapMutable
|
|
118
|
-
});
|
|
119
88
|
function arrMapMutable(input, f) {
|
|
120
89
|
for (let i = 0; i < input.length; i++) {
|
|
121
90
|
input[i] = f(input[i], i, input);
|
|
122
91
|
}
|
|
123
92
|
return input;
|
|
124
93
|
}
|
|
125
|
-
|
|
126
|
-
// src/lib/arrObjectsToTable.ts
|
|
127
|
-
var arrObjectsToTable_exports = {};
|
|
128
|
-
__export(arrObjectsToTable_exports, {
|
|
129
|
-
arrObjectsToTable: () => arrObjectsToTable
|
|
130
|
-
});
|
|
94
|
+
__name(arrMapMutable, 'arrMapMutable');
|
|
131
95
|
|
|
132
96
|
// src/lib/arrObjectsUniqueKeys.ts
|
|
133
|
-
var arrObjectsUniqueKeys_exports = {};
|
|
134
|
-
__export(arrObjectsUniqueKeys_exports, {
|
|
135
|
-
arrObjectsUniqueKeys: () => arrObjectsUniqueKeys
|
|
136
|
-
});
|
|
137
97
|
function arrObjectsUniqueKeys(objects) {
|
|
138
98
|
const keys = /* @__PURE__ */ new Set();
|
|
139
99
|
for (const o of objects) {
|
|
@@ -143,6 +103,7 @@ function arrObjectsUniqueKeys(objects) {
|
|
|
143
103
|
}
|
|
144
104
|
return Array.from(keys);
|
|
145
105
|
}
|
|
106
|
+
__name(arrObjectsUniqueKeys, 'arrObjectsUniqueKeys');
|
|
146
107
|
|
|
147
108
|
// src/lib/arrObjectsToTable.ts
|
|
148
109
|
function arrObjectsToTable(objects, options = {}) {
|
|
@@ -157,32 +118,23 @@ function arrObjectsToTable(objects, options = {}) {
|
|
|
157
118
|
}
|
|
158
119
|
return table;
|
|
159
120
|
}
|
|
121
|
+
__name(arrObjectsToTable, 'arrObjectsToTable');
|
|
160
122
|
|
|
161
123
|
// src/lib/arrRemove.ts
|
|
162
|
-
var arrRemove_exports = {};
|
|
163
|
-
__export(arrRemove_exports, {
|
|
164
|
-
arrRemove: () => arrRemove
|
|
165
|
-
});
|
|
166
124
|
function arrRemove(arr, elementToRemove) {
|
|
167
125
|
return arr.filter((element) => {
|
|
168
126
|
return element !== elementToRemove;
|
|
169
127
|
});
|
|
170
128
|
}
|
|
129
|
+
__name(arrRemove, 'arrRemove');
|
|
171
130
|
|
|
172
131
|
// src/lib/arrRemoveDuplicates.ts
|
|
173
|
-
var arrRemoveDuplicates_exports = {};
|
|
174
|
-
__export(arrRemoveDuplicates_exports, {
|
|
175
|
-
arrRemoveDuplicates: () => arrRemoveDuplicates
|
|
176
|
-
});
|
|
177
132
|
function arrRemoveDuplicates(array) {
|
|
178
133
|
return Array.from(new Set(array));
|
|
179
134
|
}
|
|
135
|
+
__name(arrRemoveDuplicates, 'arrRemoveDuplicates');
|
|
180
136
|
|
|
181
137
|
// src/lib/arrRemoveMutable.ts
|
|
182
|
-
var arrRemoveMutable_exports = {};
|
|
183
|
-
__export(arrRemoveMutable_exports, {
|
|
184
|
-
arrRemoveMutable: () => arrRemoveMutable
|
|
185
|
-
});
|
|
186
138
|
function arrRemoveMutable(arr, elementToRemove) {
|
|
187
139
|
let index = arr.indexOf(elementToRemove);
|
|
188
140
|
while (index !== -1) {
|
|
@@ -190,26 +142,17 @@ function arrRemoveMutable(arr, elementToRemove) {
|
|
|
190
142
|
index = arr.indexOf(elementToRemove);
|
|
191
143
|
}
|
|
192
144
|
}
|
|
193
|
-
|
|
194
|
-
// src/lib/arrShuffle.ts
|
|
195
|
-
var arrShuffle_exports = {};
|
|
196
|
-
__export(arrShuffle_exports, {
|
|
197
|
-
arrShuffle: () => arrShuffle
|
|
198
|
-
});
|
|
145
|
+
__name(arrRemoveMutable, 'arrRemoveMutable');
|
|
199
146
|
|
|
200
147
|
// src/lib/arrSwap.ts
|
|
201
|
-
var arrSwap_exports = {};
|
|
202
|
-
__export(arrSwap_exports, {
|
|
203
|
-
arrSwap: () => arrSwap
|
|
204
|
-
});
|
|
205
148
|
function arrSwap(input, from, to) {
|
|
206
149
|
if (from === to) {
|
|
207
150
|
return input;
|
|
208
151
|
}
|
|
209
|
-
;
|
|
210
152
|
[input[from], input[to]] = [input[to], input[from]];
|
|
211
153
|
return input;
|
|
212
154
|
}
|
|
155
|
+
__name(arrSwap, 'arrSwap');
|
|
213
156
|
|
|
214
157
|
// src/lib/arrShuffle.ts
|
|
215
158
|
function arrShuffle(input) {
|
|
@@ -223,16 +166,13 @@ function arrShuffle(input) {
|
|
|
223
166
|
const newIndex = Math.floor(Math.random() * input.length);
|
|
224
167
|
arrSwap(input, i, newIndex);
|
|
225
168
|
}
|
|
226
|
-
equal = input.join(
|
|
169
|
+
equal = input.join(',') === original.join(',');
|
|
227
170
|
}
|
|
228
171
|
return input;
|
|
229
172
|
}
|
|
173
|
+
__name(arrShuffle, 'arrShuffle');
|
|
230
174
|
|
|
231
175
|
// src/lib/arrSortNumeric.ts
|
|
232
|
-
var arrSortNumeric_exports = {};
|
|
233
|
-
__export(arrSortNumeric_exports, {
|
|
234
|
-
arrSortNumeric: () => arrSortNumeric
|
|
235
|
-
});
|
|
236
176
|
function arrSortNumeric(input) {
|
|
237
177
|
return input.sort((a, b) => {
|
|
238
178
|
if (a < b) {
|
|
@@ -244,12 +184,9 @@ function arrSortNumeric(input) {
|
|
|
244
184
|
return 0;
|
|
245
185
|
});
|
|
246
186
|
}
|
|
187
|
+
__name(arrSortNumeric, 'arrSortNumeric');
|
|
247
188
|
|
|
248
189
|
// src/lib/arrSortedInsertionIndex.ts
|
|
249
|
-
var arrSortedInsertionIndex_exports = {};
|
|
250
|
-
__export(arrSortedInsertionIndex_exports, {
|
|
251
|
-
arrSortedInsertionIndex: () => arrSortedInsertionIndex
|
|
252
|
-
});
|
|
253
190
|
function arrSortedInsertionIndex(array, value, comparator) {
|
|
254
191
|
let first = 0;
|
|
255
192
|
let count = array.length;
|
|
@@ -266,12 +203,9 @@ function arrSortedInsertionIndex(array, value, comparator) {
|
|
|
266
203
|
}
|
|
267
204
|
return first;
|
|
268
205
|
}
|
|
206
|
+
__name(arrSortedInsertionIndex, 'arrSortedInsertionIndex');
|
|
269
207
|
|
|
270
208
|
// src/lib/arrTableAssertRowsSameLength.ts
|
|
271
|
-
var arrTableAssertRowsSameLength_exports = {};
|
|
272
|
-
__export(arrTableAssertRowsSameLength_exports, {
|
|
273
|
-
arrTableAssertRowsSameLength: () => arrTableAssertRowsSameLength
|
|
274
|
-
});
|
|
275
209
|
function arrTableAssertRowsSameLength(rows, headers) {
|
|
276
210
|
const numHeaders = (headers || rows[0]).length;
|
|
277
211
|
for (const row of rows) {
|
|
@@ -280,24 +214,18 @@ function arrTableAssertRowsSameLength(rows, headers) {
|
|
|
280
214
|
}
|
|
281
215
|
}
|
|
282
216
|
}
|
|
217
|
+
__name(arrTableAssertRowsSameLength, 'arrTableAssertRowsSameLength');
|
|
283
218
|
|
|
284
219
|
// src/lib/arrTableEachToString.ts
|
|
285
|
-
var arrTableEachToString_exports = {};
|
|
286
|
-
__export(arrTableEachToString_exports, {
|
|
287
|
-
arrTableEachToString: () => arrTableEachToString
|
|
288
|
-
});
|
|
289
220
|
function arrTableEachToString(table) {
|
|
290
221
|
return table.map(arrEachToString);
|
|
291
222
|
}
|
|
223
|
+
__name(arrTableEachToString, 'arrTableEachToString');
|
|
292
224
|
|
|
293
225
|
// src/lib/arrTableIterateAsObjects.ts
|
|
294
|
-
var arrTableIterateAsObjects_exports = {};
|
|
295
|
-
__export(arrTableIterateAsObjects_exports, {
|
|
296
|
-
arrTableIterateAsObjects: () => arrTableIterateAsObjects
|
|
297
|
-
});
|
|
298
226
|
function* arrTableIterateAsObjects(rows, headers, ignoreHeaders = /* @__PURE__ */ new Set()) {
|
|
299
227
|
if (!headers.length) {
|
|
300
|
-
throw new Error(
|
|
228
|
+
throw new Error('No headers provided');
|
|
301
229
|
}
|
|
302
230
|
ignoreHeaders.forEach((h) => {
|
|
303
231
|
if (!headers.includes(h)) {
|
|
@@ -305,7 +233,7 @@ function* arrTableIterateAsObjects(rows, headers, ignoreHeaders = /* @__PURE__ *
|
|
|
305
233
|
}
|
|
306
234
|
});
|
|
307
235
|
if (new Set(headers).size === ignoreHeaders.size) {
|
|
308
|
-
throw new Error(
|
|
236
|
+
throw new Error('All headers are ignored');
|
|
309
237
|
}
|
|
310
238
|
for (let r = 0; r < rows.length; r++) {
|
|
311
239
|
if (rows[r].length !== headers.length) {
|
|
@@ -321,20 +249,19 @@ function* arrTableIterateAsObjects(rows, headers, ignoreHeaders = /* @__PURE__ *
|
|
|
321
249
|
yield o;
|
|
322
250
|
}
|
|
323
251
|
}
|
|
252
|
+
__name(arrTableIterateAsObjects, 'arrTableIterateAsObjects');
|
|
324
253
|
|
|
325
254
|
// src/lib/arrTableRemoveColumns.ts
|
|
326
|
-
var arrTableRemoveColumns_exports = {};
|
|
327
|
-
__export(arrTableRemoveColumns_exports, {
|
|
328
|
-
arrTableRemoveColumns: () => arrTableRemoveColumns
|
|
329
|
-
});
|
|
330
255
|
function arrTableRemoveColumns(table, ...removeColumnNames) {
|
|
331
256
|
if (!removeColumnNames.length || !table.length) {
|
|
332
257
|
return table;
|
|
333
258
|
}
|
|
334
259
|
const set = new Set(
|
|
335
|
-
removeColumnNames
|
|
336
|
-
|
|
337
|
-
|
|
260
|
+
removeColumnNames
|
|
261
|
+
.map((col) => {
|
|
262
|
+
return arrIndicesOf(table[0], col);
|
|
263
|
+
})
|
|
264
|
+
.flat(),
|
|
338
265
|
);
|
|
339
266
|
return table.map((row) => {
|
|
340
267
|
return row.filter((_, i) => {
|
|
@@ -342,25 +269,23 @@ function arrTableRemoveColumns(table, ...removeColumnNames) {
|
|
|
342
269
|
});
|
|
343
270
|
});
|
|
344
271
|
}
|
|
272
|
+
__name(arrTableRemoveColumns, 'arrTableRemoveColumns');
|
|
345
273
|
|
|
346
274
|
// src/lib/arrTableToCsv.ts
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
})
|
|
356
|
-
|
|
275
|
+
function arrTableToCsv(input, delimiter = ';', replaceLinebreakWith = '<br>') {
|
|
276
|
+
return input
|
|
277
|
+
.map((row) => {
|
|
278
|
+
return row
|
|
279
|
+
.map((item) => {
|
|
280
|
+
return String(item).replace(new RegExp(';', 'g'), '').replace(/\r*\n/g, replaceLinebreakWith);
|
|
281
|
+
})
|
|
282
|
+
.join(delimiter);
|
|
283
|
+
})
|
|
284
|
+
.join('\n');
|
|
357
285
|
}
|
|
286
|
+
__name(arrTableToCsv, 'arrTableToCsv');
|
|
358
287
|
|
|
359
288
|
// src/lib/arrTableToObjects.ts
|
|
360
|
-
var arrTableToObjects_exports = {};
|
|
361
|
-
__export(arrTableToObjects_exports, {
|
|
362
|
-
arrTableToObjects: () => arrTableToObjects
|
|
363
|
-
});
|
|
364
289
|
function arrTableToObjects(rows, headers, ignoreKeys) {
|
|
365
290
|
if (headers) {
|
|
366
291
|
if (!rows.length) {
|
|
@@ -371,7 +296,7 @@ function arrTableToObjects(rows, headers, ignoreKeys) {
|
|
|
371
296
|
return [];
|
|
372
297
|
}
|
|
373
298
|
headers = rows[0].map((header) => {
|
|
374
|
-
return header === null || header === void 0 ?
|
|
299
|
+
return header === null || header === void 0 ? '' : String(header);
|
|
375
300
|
});
|
|
376
301
|
rows = rows.slice(1);
|
|
377
302
|
}
|
|
@@ -388,47 +313,18 @@ function arrTableToObjects(rows, headers, ignoreKeys) {
|
|
|
388
313
|
return o;
|
|
389
314
|
});
|
|
390
315
|
}
|
|
316
|
+
__name(arrTableToObjects, 'arrTableToObjects');
|
|
391
317
|
|
|
392
318
|
// src/lib/arrayToString.ts
|
|
393
|
-
var arrayToString_exports = {};
|
|
394
|
-
__export(arrayToString_exports, {
|
|
395
|
-
arrayToString: () => arrayToString
|
|
396
|
-
});
|
|
397
319
|
function arrayToString(array) {
|
|
398
|
-
return `[${array
|
|
399
|
-
|
|
400
|
-
|
|
320
|
+
return `[${array
|
|
321
|
+
.map((item) => {
|
|
322
|
+
return item == null ? String(item) : Array.isArray(item) ? arrayToString(item) : item.toString();
|
|
323
|
+
})
|
|
324
|
+
.join(',')}]`;
|
|
401
325
|
}
|
|
326
|
+
__name(arrayToString, 'arrayToString');
|
|
402
327
|
|
|
403
|
-
// src/index.ts
|
|
404
|
-
var src_default = {
|
|
405
|
-
...arrAverage_exports,
|
|
406
|
-
//
|
|
407
|
-
...arrEachToString_exports,
|
|
408
|
-
...arrFindIndicesOf_exports,
|
|
409
|
-
...arrGetOrDefault_exports,
|
|
410
|
-
...arrHasDuplicates_exports,
|
|
411
|
-
...arrIndicesOf_exports,
|
|
412
|
-
...arrLast_exports,
|
|
413
|
-
...arrMapMutable_exports,
|
|
414
|
-
...arrObjectsToTable_exports,
|
|
415
|
-
...arrObjectsUniqueKeys_exports,
|
|
416
|
-
...arrRemove_exports,
|
|
417
|
-
...arrRemoveDuplicates_exports,
|
|
418
|
-
...arrRemoveMutable_exports,
|
|
419
|
-
...arrShuffle_exports,
|
|
420
|
-
...arrSortNumeric_exports,
|
|
421
|
-
...arrSortedInsertionIndex_exports,
|
|
422
|
-
...arrSum_exports,
|
|
423
|
-
...arrSwap_exports,
|
|
424
|
-
...arrTableAssertRowsSameLength_exports,
|
|
425
|
-
...arrTableEachToString_exports,
|
|
426
|
-
...arrTableIterateAsObjects_exports,
|
|
427
|
-
...arrTableRemoveColumns_exports,
|
|
428
|
-
...arrTableToCsv_exports,
|
|
429
|
-
...arrTableToObjects_exports,
|
|
430
|
-
...arrayToString_exports
|
|
431
|
-
};
|
|
432
328
|
export {
|
|
433
329
|
arrAverage,
|
|
434
330
|
arrEachToString,
|
|
@@ -455,5 +351,4 @@ export {
|
|
|
455
351
|
arrTableToCsv,
|
|
456
352
|
arrTableToObjects,
|
|
457
353
|
arrayToString,
|
|
458
|
-
src_default as default
|
|
459
354
|
};
|
package/package.json
CHANGED
package/lib/arrAverage.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Calculates the average of an array of numbers.
|
|
3
|
-
* @returns The average of all numbers in the array.
|
|
4
|
-
* @throws an error if the input array is empty.
|
|
5
|
-
* @param array The array of numbers.
|
|
6
|
-
* @example ```ts
|
|
7
|
-
* const numbers = [1, 2, 3, 4, 5];
|
|
8
|
-
* arrAverage(numbers);
|
|
9
|
-
* //=> 3
|
|
10
|
-
* ```
|
|
11
|
-
*/
|
|
12
|
-
export declare function arrAverage(array: number[]): number;
|
package/lib/arrEachToString.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Coerce each element of an array to string.
|
|
3
|
-
* @template T - The type of elements in the input array.
|
|
4
|
-
* @returns A new array where each element is the string representation of the corresponding element in the input array.
|
|
5
|
-
* @param array The array to iterate over.
|
|
6
|
-
* @example ```ts
|
|
7
|
-
* const numbers = [1, 2, 3];
|
|
8
|
-
* arrEachToString(numbers);
|
|
9
|
-
* //=> ['1', '2', '3']
|
|
10
|
-
* ```
|
|
11
|
-
*/
|
|
12
|
-
export declare function arrEachToString<T>(array: T[]): string[];
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Returns an array of indices where the predicate function returns true for the corresponding element in the input array.
|
|
3
|
-
* @param input - The array to search.
|
|
4
|
-
* @param predicate - The function to test each element of the array.
|
|
5
|
-
* @returns An array of indices where the predicate function returns true.
|
|
6
|
-
*/
|
|
7
|
-
export declare function arrFindIndicesOf<T>(input: Array<T>, predicate: (value: T) => boolean): number[];
|
package/lib/arrGetOrDefault.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Checks if an array has any duplicate elements.
|
|
3
|
-
* @param arr - The array to check for duplicates.
|
|
4
|
-
* @returns A boolean indicating whether the array has duplicates.
|
|
5
|
-
* @typeParam T - The type of elements in the array.
|
|
6
|
-
*/
|
|
7
|
-
export declare function arrHasDuplicates<T>(arr: T[]): boolean;
|
package/lib/arrIndicesOf.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Returns all indexes at which an element is found.
|
|
3
|
-
* @param input The array to search
|
|
4
|
-
* @template T - The type of elements in the input array.
|
|
5
|
-
* @returns An array of indices where the specified element can be found.
|
|
6
|
-
* @param element The element to find
|
|
7
|
-
* @example ```ts
|
|
8
|
-
* const inputArray = [1, 2, 3, 2, 4, 2, 5];
|
|
9
|
-
* const elementToFind = 2;
|
|
10
|
-
* arrIndicesOf(inputArray, elementToFind);
|
|
11
|
-
* //=> [1, 3, 5]
|
|
12
|
-
* ```
|
|
13
|
-
*/
|
|
14
|
-
export declare function arrIndicesOf<T>(input: Array<T>, element: T): number[];
|
package/lib/arrLast.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Returns the last element of an array.
|
|
3
|
-
* Throws an error if the array is empty.
|
|
4
|
-
* @template T The type of elements in the array.
|
|
5
|
-
* @param array The array to get the last element from.
|
|
6
|
-
* @returns The last element of the array.
|
|
7
|
-
* @throws If the array is empty.
|
|
8
|
-
* @example const numbers = [1, 2, 3, 4, 5];
|
|
9
|
-
* const lastNumber = arrLast(numbers);
|
|
10
|
-
* //=> 5
|
|
11
|
-
*/
|
|
12
|
-
export declare function arrLast<T>(array: T[]): T;
|
package/lib/arrMapMutable.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This function takes an array and a callback function as arguments. It applies the callback function to each element of the array, mutating the original array in the process.
|
|
3
|
-
* @template T The type of elements in the input array.
|
|
4
|
-
* @param input The array to be mapped over.
|
|
5
|
-
* @param f The callback function to be applied to each element of the array. This function takes three arguments: the current element, its index, and the original array.
|
|
6
|
-
* @returns The original array, mutated by the callback function.
|
|
7
|
-
* @example ```ts
|
|
8
|
-
* arrMapMutable([1, 2, 3], (value: number) => value * 2);
|
|
9
|
-
* //=> [2, 4, 6]
|
|
10
|
-
* ```
|
|
11
|
-
*/
|
|
12
|
-
export declare function arrMapMutable<T>(input: Array<T>, f: (value: T, index: number, array: T[]) => T): Array<T>;
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Convert an array of objects to a two-dimensional table.
|
|
3
|
-
* @param objects The array of objects to convert to a table.
|
|
4
|
-
* @template T - The type of the values in the objects.
|
|
5
|
-
* @param options.headers An optional array of strings specifying the headers (property names) to use. If not provided, the function will use all unique keys found in the objects.
|
|
6
|
-
* @param options.emptyCell An optional value to use for empty cells. If not provided, the function will use `undefined`.
|
|
7
|
-
* @returns A 2D array (table) where each row represents an object and each column represents a property of the object.
|
|
8
|
-
* @param options The options for converting the objects to a table.
|
|
9
|
-
* @example ```ts
|
|
10
|
-
* arrObjectsToTable(
|
|
11
|
-
* [
|
|
12
|
-
* { a: 1, b: 2 },
|
|
13
|
-
* { a: 3, b: 4, c: 5 },
|
|
14
|
-
* ],
|
|
15
|
-
* { emptyCell:1 },
|
|
16
|
-
* ) //=> [ [ 'a', 'b', 'c' ], [ 1, 2,1 ], [ 3, 4, 5 ] ]
|
|
17
|
-
* ```
|
|
18
|
-
*/
|
|
19
|
-
export declare function arrObjectsToTable<T, E>(objects: Record<string, T | undefined>[], options?: {
|
|
20
|
-
headers?: string[];
|
|
21
|
-
emptyCell?: E;
|
|
22
|
-
}): Array<Array<string | T | E>>;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Returns an array of all unique object keys found in an array of objects.
|
|
3
|
-
* @template T - The type of values in the input objects.
|
|
4
|
-
* @returns An array of unique keys present in the input objects.
|
|
5
|
-
* @param objects The array of objects.
|
|
6
|
-
* @example ```ts
|
|
7
|
-
* const objects = [
|
|
8
|
-
* { name: 'John', age: 25 },
|
|
9
|
-
* { name: 'Jane', gender: 'female' },
|
|
10
|
-
* { name: 'Bob', age: 30, gender: 'male' },
|
|
11
|
-
* ];
|
|
12
|
-
* arrObjectsUniqueKeys(objects);
|
|
13
|
-
* //=> ['name', 'age', 'gender']
|
|
14
|
-
* ```
|
|
15
|
-
*/
|
|
16
|
-
export declare function arrObjectsUniqueKeys<T>(objects: Record<string, T>[]): string[];
|
package/lib/arrRemove.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Remove duplicates from an array
|
|
3
|
-
* @remarks This function uses the JavaScript Set object to remove duplicate values from an array.
|
|
4
|
-
* @typeparam T - The type of elements in the array.
|
|
5
|
-
* @returns The new array with duplicates removed.
|
|
6
|
-
* @param array The array from which to remove duplicates.
|
|
7
|
-
* @example ```ts
|
|
8
|
-
* const array = [1, 2, 2, 3, 4, 4, 5];
|
|
9
|
-
* arrRemoveDuplicates(array);
|
|
10
|
-
* //=> [1, 2, 3, 4, 5]
|
|
11
|
-
* ```
|
|
12
|
-
*/
|
|
13
|
-
export declare function arrRemoveDuplicates<T>(array: T[]): T[];
|
package/lib/arrShuffle.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Shuffle items in an array in-place. Guarantees changes.
|
|
3
|
-
* @remarks This function does not guarantee that the order of the elements will be different after shuffling.
|
|
4
|
-
* @typeparam T - The type of the elements in the input array.
|
|
5
|
-
* @returns The same array, but shuffled.
|
|
6
|
-
* @param input The array to shuffle.
|
|
7
|
-
* @example ```ts
|
|
8
|
-
* const input = [1, 2, 3, 4, 5];
|
|
9
|
-
* arrShuffle(input);
|
|
10
|
-
* //=> [3, 1, 5, 2, 4]
|
|
11
|
-
* ```
|
|
12
|
-
*/
|
|
13
|
-
export declare function arrShuffle<T>(input: Array<T>): Array<T>;
|
package/lib/arrSortNumeric.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Sorts an array of numbers, bigints, or booleans in ascending order.
|
|
3
|
-
* @returns The sorted array.
|
|
4
|
-
* @remarks This function uses the JavaScript `Array.prototype.sort()` method, which sorts elements in place.
|
|
5
|
-
* Therefore, the original array will be modified.
|
|
6
|
-
* @throws If any element in the input array is not a number, bigint, or boolean.
|
|
7
|
-
* @param input The array to be sorted.
|
|
8
|
-
* @example ```ts
|
|
9
|
-
* const input = [5, 2n, true, 10, false];
|
|
10
|
-
* arrSortNumeric(input);
|
|
11
|
-
* //=> [false, true, 2n, 5, 10]
|
|
12
|
-
* ```
|
|
13
|
-
*/
|
|
14
|
-
export declare function arrSortNumeric(input: Array<number | bigint | boolean>): Array<number | bigint | boolean>;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Returns an index in the sorted array where the specified value could be inserted while maintaining the sorted order of the array.
|
|
3
|
-
* If the element is already in the array, returns the index after the last instance of the element.
|
|
4
|
-
* @param array - The sorted array to search.
|
|
5
|
-
* @param value - The value to locate in the array.
|
|
6
|
-
* @param comparator - A function that defines the sort order. If omitted, the array elements are converted to strings, then sorted according to each character's Unicode code point value.
|
|
7
|
-
* @returns The index at which the value could be inserted into array to maintain the array's sorted order.
|
|
8
|
-
* @example ```ts
|
|
9
|
-
* const array = [1, 2, 3, 5, 6];
|
|
10
|
-
* const value = 4;
|
|
11
|
-
* const comparator = (a, b) => a - b;
|
|
12
|
-
* const index = arrSortedLowerBound(array, value, comparator);
|
|
13
|
-
* console.log(index); // Output: 3
|
|
14
|
-
* ```
|
|
15
|
-
*/
|
|
16
|
-
export declare function arrSortedInsertionIndex<T>(array: readonly T[], value: T, comparator: (a: T, b: T) => number): number;
|
package/lib/arrSum.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Calculates the sum of an array of numbers.
|
|
3
|
-
* @returns The sum of all numbers in the array.
|
|
4
|
-
* @param array The array of numbers to sum.
|
|
5
|
-
* @example ```ts
|
|
6
|
-
* const numbers = [1, 2, 3, 4, 5];
|
|
7
|
-
* arrSum(numbers);
|
|
8
|
-
* //=> 15
|
|
9
|
-
* ```
|
|
10
|
-
*/
|
|
11
|
-
export declare function arrSum(array: number[]): number;
|
package/lib/arrSwap.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Swaps two elements in an array. This function takes an input array and swaps the elements at the specified indices.
|
|
3
|
-
* @param to The index of the element to swap to.
|
|
4
|
-
* @param from The index of the element to swap from.
|
|
5
|
-
* @template T - The type of elements in the array.
|
|
6
|
-
* @returns The modified array with swapped elements.
|
|
7
|
-
* @throws Will throw an error if 'from' or 'to' is not a valid index in the array.
|
|
8
|
-
* @param input The input array.
|
|
9
|
-
* @example ```ts
|
|
10
|
-
* const arr = [1, 2, 3, 4, 5]
|
|
11
|
-
* arrSwap(arr, 1, 3) //=> [1, 4, 3, 2, 5]
|
|
12
|
-
* ```
|
|
13
|
-
*/
|
|
14
|
-
export declare function arrSwap<T>(input: Array<T>, from: number, to: number): Array<T>;
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Asserts that all rows in a 2D array have the same length.
|
|
3
|
-
* @param - Optional array of headers to compare the row length against.
|
|
4
|
-
* @throws If any row in the array has a different length than the others.
|
|
5
|
-
* @param headers Optional. An array of headers. If provided, each row must have the same length as this array.
|
|
6
|
-
* @typeparam T - The type of elements in the rows.
|
|
7
|
-
* @param rows The 2D array to check.
|
|
8
|
-
* @example ```ts
|
|
9
|
-
* const rows = [
|
|
10
|
-
* [1, 2, 3],
|
|
11
|
-
* [4, 5, 6],
|
|
12
|
-
* [7, 8, 9],
|
|
13
|
-
* ];
|
|
14
|
-
* arrTableAssertRowsSameLength(rows);
|
|
15
|
-
* //=> undefined
|
|
16
|
-
* const rowsWithDifferentLength = [
|
|
17
|
-
* [1, 2, 3],
|
|
18
|
-
* [4, 5],
|
|
19
|
-
* [7, 8, 9],
|
|
20
|
-
* ];
|
|
21
|
-
* arrTableAssertRowsSameLength(rowsWithDifferentLength);
|
|
22
|
-
* //=> Error: Expected 3 columns, got 2
|
|
23
|
-
* ```
|
|
24
|
-
*/
|
|
25
|
-
export declare function arrTableAssertRowsSameLength<T>(rows: T[][], headers?: string[]): void;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Coerce each value of a 2D array table to string.
|
|
3
|
-
* @template T - The type of the elements in the input array.
|
|
4
|
-
* @returns The converted 2D array where each element is a string.
|
|
5
|
-
* @param table The 2D array to convert.
|
|
6
|
-
* @example ```ts
|
|
7
|
-
* const input: number[][] = [[1, 2, 3], [4, 5, 6], [7, 8, 9]];
|
|
8
|
-
* arrTableEachToString(input);
|
|
9
|
-
* //=> [['1', '2', '3'], ['4', '5', '6'], ['7', '8', '9']]
|
|
10
|
-
* ```
|
|
11
|
-
*/
|
|
12
|
-
export declare function arrTableEachToString<T>(table: T[][]): string[][];
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Removes specified columns from a 2D array table.
|
|
3
|
-
* @param table - The 2D array (table) from which columns will be removed. The first row of the table is assumed to contain column names.
|
|
4
|
-
* @param removeColumnNames - The names of the columns to be removed. These should match the entries in the first row of the table.
|
|
5
|
-
* @returns A new 2D array (table) with the specified columns removed.
|
|
6
|
-
*/
|
|
7
|
-
export declare function arrTableRemoveColumns(table: string[][], ...removeColumnNames: string[]): string[][];
|
package/lib/arrTableToCsv.d.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Converts a 2D array to a CSV string.
|
|
3
|
-
* @param input The input 2D array.
|
|
4
|
-
* @remarks This function is useful for exporting data to CSV format.
|
|
5
|
-
* @param replaceLinebreakWith The character used to replace line breaks in the CSV string. Defaults to '|'.
|
|
6
|
-
* @typeparam T - The type of the elements in the input array.
|
|
7
|
-
* @returns The CSV string representation of the input array.
|
|
8
|
-
* @param delimiter The delimiter to use for separating values in the CSV string.
|
|
9
|
-
* @example ```ts
|
|
10
|
-
* const input = [
|
|
11
|
-
* ['Name', 'Age', 'Country'],
|
|
12
|
-
* ['John', '25', 'USA'],
|
|
13
|
-
* ['Alice', '30', 'Canada'],
|
|
14
|
-
* ['Bob', '35', 'UK'],
|
|
15
|
-
* ];
|
|
16
|
-
* arrTableToCsv(input);
|
|
17
|
-
* //=> "Name;Age;Country\nJohn;25;USA\nAlice;30;Canada\nBob;35;UK"
|
|
18
|
-
* ```
|
|
19
|
-
*/
|
|
20
|
-
export declare function arrTableToCsv<T>(input: T[][], delimiter?: string, replaceLinebreakWith?: string): string;
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Converts a 2D array representing a table into an array of objects.
|
|
3
|
-
* @param rows The 2D array representing the table.
|
|
4
|
-
* @template T - The type of the elements in the rows.
|
|
5
|
-
* @param headers The headers to use as keys for the objects. If not provided, the first row of the table is used as headers.
|
|
6
|
-
* @returns An array of objects, where each object represents a row in the table.
|
|
7
|
-
* @throws Throws an error if the headers are not provided and the table is empty or only contains one row.
|
|
8
|
-
* @param headers Optional array of headers for the table.
|
|
9
|
-
* @example ```ts
|
|
10
|
-
* const table = [
|
|
11
|
-
* ['Name', 'Age', 'Country'],
|
|
12
|
-
* ['John', 25, 'USA'],
|
|
13
|
-
* ['Jane', 30, 'Canada'],
|
|
14
|
-
* ];
|
|
15
|
-
* const headers = ['Name', 'Age', 'Country'];
|
|
16
|
-
* arrTableToObjects(table, headers) //=> [
|
|
17
|
-
* // { Name: 'John', Age: 25, Country: 'USA' },
|
|
18
|
-
* // { Name: 'Jane', Age: 30, Country: 'Canada' },
|
|
19
|
-
* // ]
|
|
20
|
-
* ```
|
|
21
|
-
*/
|
|
22
|
-
export declare function arrTableToObjects<T>(rows: T[][], headers?: string[], ignoreKeys?: Set<string>): Record<string, T>[];
|
package/lib/arrayToString.d.ts
DELETED