@nu-art/ts-common 0.401.2 → 0.401.3
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/package.json +3 -3
- package/utils/array-tools.d.ts +1 -0
- package/utils/array-tools.js +5 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nu-art/ts-common",
|
|
3
|
-
"version": "0.401.
|
|
3
|
+
"version": "0.401.3",
|
|
4
4
|
"description": "Core TypeScript infrastructure library for building modular applications with lifecycle management, logging, validation, and utilities",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"keywords": [
|
|
@@ -37,8 +37,8 @@
|
|
|
37
37
|
"run-tests": "ts-mocha --timeout 50000 -p src/test/tsconfig.json src/test/run-all-tests.ts"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@nu-art/testalot": "0.401.
|
|
41
|
-
"@nu-art/logger": "0.401.
|
|
40
|
+
"@nu-art/testalot": "0.401.3",
|
|
41
|
+
"@nu-art/logger": "0.401.3",
|
|
42
42
|
"fast-csv": "^5.0.2",
|
|
43
43
|
"export-to-csv": "0.2.1",
|
|
44
44
|
"moment": "^2.29.4",
|
package/utils/array-tools.d.ts
CHANGED
|
@@ -234,4 +234,5 @@ export declare function clearArrayInstance<T extends any[]>(arr: T): void;
|
|
|
234
234
|
export declare function arrayIncludesAll<T>(arr1: T[], arr2: T[]): boolean;
|
|
235
235
|
export declare function getMax<T>(arr: T[], mapper?: (item: T) => number): T | undefined;
|
|
236
236
|
export declare function getMin<T>(arr: T[], mapper?: (item: T) => number): T | undefined;
|
|
237
|
+
export declare function randomFromArray<T>(arr?: T[]): T | undefined;
|
|
237
238
|
export {};
|
package/utils/array-tools.js
CHANGED
|
@@ -416,3 +416,8 @@ export function getMin(arr, mapper = (item) => item) {
|
|
|
416
416
|
const sorted = sortArray(arr, mapper);
|
|
417
417
|
return sorted[0];
|
|
418
418
|
}
|
|
419
|
+
export function randomFromArray(arr) {
|
|
420
|
+
if (!arr?.length)
|
|
421
|
+
return;
|
|
422
|
+
return arr[Math.floor((Math.random() * arr.length))];
|
|
423
|
+
}
|