@drunkcod/argis 0.0.5 → 0.0.6
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/lib/index.d.ts +7 -2
- package/lib/index.js +6 -3
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
|
@@ -5,12 +5,15 @@ export type WithRequired<T, K extends keyof T> = Required<NoNullMembers<Pick<T,
|
|
|
5
5
|
export type WithKey<K extends PropertyKey, V = unknown> = {
|
|
6
6
|
[p in K]: V;
|
|
7
7
|
};
|
|
8
|
+
export type OmitIndex<T> = {
|
|
9
|
+
[K in keyof T as string extends K ? never : number extends K ? never : symbol extends K ? never : K]: T[K];
|
|
10
|
+
};
|
|
8
11
|
export declare class ArgumentError extends Error {
|
|
9
12
|
constructor(message: string);
|
|
10
|
-
static null(message: string):
|
|
13
|
+
static null(message: string): never;
|
|
11
14
|
static missing({ key }: {
|
|
12
15
|
key: PropertyKey;
|
|
13
|
-
}):
|
|
16
|
+
}): never;
|
|
14
17
|
}
|
|
15
18
|
export declare function isNil(x: any): x is null | undefined;
|
|
16
19
|
export declare function isNil<T extends object>(x: T | null, key: keyof T): x is T & WithKey<typeof key, null | undefined>;
|
|
@@ -23,7 +26,9 @@ export declare function argNotNil<T, K extends keyof T>(x: T, key: K): asserts x
|
|
|
23
26
|
[P in K]-?: NonNullable<T[K]>;
|
|
24
27
|
};
|
|
25
28
|
export declare function hasOwn<T extends object, K extends PropertyKey>(x: T, key: K): x is T & WithKey<K>;
|
|
29
|
+
export declare function hasOwn<T extends object, K extends PropertyKey, V>(x: T, key: K, ofType: (found: unknown) => found is V): x is T & WithKey<K, V>;
|
|
26
30
|
export declare function assertOwn<T extends object, K extends PropertyKey>(x: T, key: K): asserts x is T & WithKey<K>;
|
|
31
|
+
export declare function assertOwn<T extends object, K extends PropertyKey, V>(x: T, key: K, ofType: (found: unknown) => found is V): asserts x is T & WithKey<K, V>;
|
|
27
32
|
export declare function nullIfEmpty<T extends {
|
|
28
33
|
length: number;
|
|
29
34
|
}>(x: T | null): T | null;
|
package/lib/index.js
CHANGED
|
@@ -26,11 +26,14 @@ export function assertNotNil(x) {
|
|
|
26
26
|
export function argNotNil(x, key) {
|
|
27
27
|
isNotNil(x, key) || ArgumentError.null(`'${String(key)}' was null or undefined`);
|
|
28
28
|
}
|
|
29
|
-
|
|
29
|
+
function _hasOwn(x, key) {
|
|
30
30
|
return Object.hasOwn(x, key);
|
|
31
31
|
}
|
|
32
|
-
export function
|
|
33
|
-
|
|
32
|
+
export function hasOwn(x, key, ofType) {
|
|
33
|
+
return _hasOwn(x, key) && (ofType == undefined || ofType(x[key]));
|
|
34
|
+
}
|
|
35
|
+
export function assertOwn(x, key, ofType) {
|
|
36
|
+
(ofType ? hasOwn(x, key, ofType) : hasOwn(x, key)) || ArgumentError.missing({ key });
|
|
34
37
|
}
|
|
35
38
|
export function nullIfEmpty(x) {
|
|
36
39
|
return x == null || x.length == 0 ? null : x;
|