@loadmill/universal 0.3.43 → 0.3.46
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/array-utils.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export declare function deleteOne(arr: any[], index: number): void;
|
|
2
2
|
export declare function swap(arr: any[], oldIndex: number, newIndex: number): void;
|
|
3
|
-
export declare const isNonEmptyArray: (arr:
|
|
3
|
+
export declare const isNonEmptyArray: <T>(arr: T | T[] | undefined) => arr is NonEmptyArray<T>;
|
|
4
|
+
export declare type NonEmptyArray<T> = [T, ...T[]];
|
|
4
5
|
export declare const filterFalsyElements: (arr?: any[]) => any[];
|
|
5
6
|
export declare const filterFalsyElementsByProp: (arr: object[], prop: string) => any[];
|
|
6
7
|
export declare const arrayify: (something: any) => any[];
|
package/dist/array-utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"array-utils.js","sourceRoot":"","sources":["../src/array-utils.ts"],"names":[],"mappings":";;;;;;AAAA,2DAAqC;AACrC,yDAAmC;AAEnC,SAAgB,SAAS,CAAC,GAAU,EAAE,KAAa;IACjD,IAAI,KAAK,GAAG,CAAC,CAAC,EAAE;QACd,GAAG,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;KACtB;AACH,CAAC;AAJD,8BAIC;AAED,SAAgB,IAAI,CAAC,GAAU,EAAE,QAAgB,EAAE,QAAgB;IACjE,IAAI,QAAQ,GAAG,QAAQ,EAAE;QACvB,GAAG,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC,EAAE,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC;QACvC,GAAG,CAAC,MAAM,CAAC,QAAQ,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC;KAC7B;SAAM;QACL,GAAG,CAAC,MAAM,CAAC,QAAQ,GAAG,CAAC,EAAE,CAAC,EAAE,GAAG,CAAC,QAAQ,CAAC,CAAC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|
|
1
|
+
/**
|
|
2
|
+
* example usage of this function:
|
|
3
|
+
* arr = [{ id: 1 }, { id: 2 }]
|
|
4
|
+
* b = { uid: 2 }
|
|
5
|
+
* const found = ensure(arr.find((a) => a.id === b.uid)); // TS thinks `find` might return undefined.
|
|
6
|
+
* We know it will never be undefined, so we use `ensure` to tell TS that arg is defined and has value.
|
|
7
|
+
* @param arg a value which should be defined and initialized
|
|
8
|
+
* @param msg custom error message
|
|
9
|
+
* @returns arg if it is defined, otherwise throws TypeError
|
|
10
|
+
* @throws TypeError if arg is null or undefined
|
|
11
|
+
*/
|
|
12
|
+
export declare function ensure<T>(arg?: T | null, msg?: string): T;
|
|
13
|
+
export declare type AllKeys<T> = T extends unknown ? keyof T : never;
|
|
14
|
+
export declare type Id<T> = T extends infer U ? {
|
|
15
|
+
[K in keyof U]: U[K];
|
|
16
|
+
} : never;
|
|
17
|
+
export declare type _ExclusifyUnion<T, K extends PropertyKey> = T extends unknown ? Id<T & Partial<Record<Exclude<K, keyof T>, never>>> : never;
|
|
18
|
+
export declare type XOR<T> = _ExclusifyUnion<T, AllKeys<T>>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ensure = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* example usage of this function:
|
|
6
|
+
* arr = [{ id: 1 }, { id: 2 }]
|
|
7
|
+
* b = { uid: 2 }
|
|
8
|
+
* const found = ensure(arr.find((a) => a.id === b.uid)); // TS thinks `find` might return undefined.
|
|
9
|
+
* We know it will never be undefined, so we use `ensure` to tell TS that arg is defined and has value.
|
|
10
|
+
* @param arg a value which should be defined and initialized
|
|
11
|
+
* @param msg custom error message
|
|
12
|
+
* @returns arg if it is defined, otherwise throws TypeError
|
|
13
|
+
* @throws TypeError if arg is null or undefined
|
|
14
|
+
*/
|
|
15
|
+
function ensure(arg, msg) {
|
|
16
|
+
if (msg === void 0) { msg = 'This value was supposed to be defined'; }
|
|
17
|
+
if (arg == null) {
|
|
18
|
+
throw new TypeError(msg);
|
|
19
|
+
}
|
|
20
|
+
return arg;
|
|
21
|
+
}
|
|
22
|
+
exports.ensure = ensure;
|
|
23
|
+
//# sourceMappingURL=typescript-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typescript-utils.js","sourceRoot":"","sources":["../src/typescript-utils.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;GAUG;AACH,SAAgB,MAAM,CAAI,GAAc,EAAE,GAAqD;IAArD,oBAAA,EAAA,6CAAqD;IAC7F,IAAI,GAAG,IAAI,IAAI,EAAE;QACf,MAAM,IAAI,SAAS,CAAC,GAAG,CAAC,CAAC;KAC1B;IAED,OAAO,GAAG,CAAC;AACb,CAAC;AAND,wBAMC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@loadmill/universal",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.46",
|
|
4
4
|
"description": "Loadmill universal utilities",
|
|
5
5
|
"main": "dist/",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"chalk": "^4.1.0",
|
|
27
27
|
"circular-json": "^0.5.1",
|
|
28
28
|
"country-list": "^2.1.0",
|
|
29
|
-
"cron-parser": "^
|
|
29
|
+
"cron-parser": "^4.3.0",
|
|
30
30
|
"cronstrue": "^1.83.0",
|
|
31
31
|
"dayjs": "^1.10.5",
|
|
32
32
|
"log4js": "6.4.0",
|
package/src/array-utils.ts
CHANGED
|
@@ -17,9 +17,11 @@ export function swap(arr: any[], oldIndex: number, newIndex: number) {
|
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
export const isNonEmptyArray = (arr:
|
|
20
|
+
export const isNonEmptyArray = <T>(arr: T[] | T | undefined): arr is NonEmptyArray<T> =>
|
|
21
21
|
Array.isArray(arr) && arr.length > 0;
|
|
22
22
|
|
|
23
|
+
export type NonEmptyArray<T> = [T, ...T[]];
|
|
24
|
+
|
|
23
25
|
export const filterFalsyElements = (arr: any[] = []): any[] =>
|
|
24
26
|
arr.filter((p) => !!p);
|
|
25
27
|
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* example usage of this function:
|
|
3
|
+
* arr = [{ id: 1 }, { id: 2 }]
|
|
4
|
+
* b = { uid: 2 }
|
|
5
|
+
* const found = ensure(arr.find((a) => a.id === b.uid)); // TS thinks `find` might return undefined.
|
|
6
|
+
* We know it will never be undefined, so we use `ensure` to tell TS that arg is defined and has value.
|
|
7
|
+
* @param arg a value which should be defined and initialized
|
|
8
|
+
* @param msg custom error message
|
|
9
|
+
* @returns arg if it is defined, otherwise throws TypeError
|
|
10
|
+
* @throws TypeError if arg is null or undefined
|
|
11
|
+
*/
|
|
12
|
+
export function ensure<T>(arg?: T | null, msg: string = 'This value was supposed to be defined'): T {
|
|
13
|
+
if (arg == null) {
|
|
14
|
+
throw new TypeError(msg);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return arg;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/*
|
|
21
|
+
* https://giphy.com/gifs/cbs-ghosts-ghostscbs-cbs-zXm8DwxWP2upMOQcQX
|
|
22
|
+
*/
|
|
23
|
+
export type AllKeys<T> = T extends unknown ? keyof T : never;
|
|
24
|
+
export type Id<T> = T extends infer U ? { [K in keyof U]: U[K] } : never;
|
|
25
|
+
export type _ExclusifyUnion<T, K extends PropertyKey> =
|
|
26
|
+
T extends unknown ? Id<T & Partial<Record<Exclude<K, keyof T>, never>>> : never;
|
|
27
|
+
export type XOR<T> = _ExclusifyUnion<T, AllKeys<T>>; // usage: XOR<Type1, Type2> -> only Type1 or Type2, but no overlap
|