@loadmill/universal 0.3.45 → 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,7 +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
3
|
export declare const isNonEmptyArray: <T>(arr: T | T[] | undefined) => arr is NonEmptyArray<T>;
|
|
4
|
-
declare type NonEmptyArray<T> = [T, ...T[]];
|
|
4
|
+
export declare type NonEmptyArray<T> = [T, ...T[]];
|
|
5
5
|
export declare const filterFalsyElements: (arr?: any[]) => any[];
|
|
6
6
|
export declare const filterFalsyElementsByProp: (arr: object[], prop: string) => any[];
|
|
7
7
|
export declare const arrayify: (something: any) => any[];
|
|
@@ -18,4 +18,3 @@ export declare function uniqByKeepLast(arr: any[], cmp: any): any[];
|
|
|
18
18
|
* @returns undefined if arr is not an array, or is an empty array, or target . Otherwise, returns the closest element to target in arr.
|
|
19
19
|
*/
|
|
20
20
|
export declare const getClosestNumberifyableElement: (arr: any[], target: any, toNumber?: (n: any) => number) => any;
|
|
21
|
-
export {};
|
|
@@ -10,3 +10,9 @@
|
|
|
10
10
|
* @throws TypeError if arg is null or undefined
|
|
11
11
|
*/
|
|
12
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>>;
|
package/package.json
CHANGED
package/src/array-utils.ts
CHANGED
|
@@ -20,7 +20,7 @@ export function swap(arr: any[], oldIndex: number, newIndex: number) {
|
|
|
20
20
|
export const isNonEmptyArray = <T>(arr: T[] | T | undefined): arr is NonEmptyArray<T> =>
|
|
21
21
|
Array.isArray(arr) && arr.length > 0;
|
|
22
22
|
|
|
23
|
-
type NonEmptyArray<T> = [T, ...T[]];
|
|
23
|
+
export type NonEmptyArray<T> = [T, ...T[]];
|
|
24
24
|
|
|
25
25
|
export const filterFalsyElements = (arr: any[] = []): any[] =>
|
|
26
26
|
arr.filter((p) => !!p);
|
package/src/typescript-utils.ts
CHANGED
|
@@ -16,3 +16,12 @@ export function ensure<T>(arg?: T | null, msg: string = 'This value was supposed
|
|
|
16
16
|
|
|
17
17
|
return arg;
|
|
18
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
|