@drunkcod/argis 0.0.11 → 0.0.12
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/cjs/index.d.ts +1 -0
- package/lib/cjs/index.js +10 -10
- package/lib/index.d.ts +1 -0
- package/lib/index.js +9 -10
- package/package.json +6 -6
package/lib/cjs/index.d.ts
CHANGED
|
@@ -28,6 +28,7 @@ export declare function isNotNil<T>(x?: T): x is T;
|
|
|
28
28
|
export declare function isNotNil<T, K extends keyof T>(x: T, key: K): x is T & {
|
|
29
29
|
[P in K]-?: NonNullable<T[K]>;
|
|
30
30
|
};
|
|
31
|
+
export declare function isThenable(x: unknown): boolean;
|
|
31
32
|
export declare function assertNotNil<T>(x: T | null): asserts x is T;
|
|
32
33
|
export declare function argNotNil<T, K extends keyof T>(x: T, key: K): asserts x is T & {
|
|
33
34
|
[P in K]-?: NonNullable<T[K]>;
|
package/lib/cjs/index.js
CHANGED
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.ArgumentError = void 0;
|
|
4
4
|
exports.isNil = isNil;
|
|
5
5
|
exports.isNotNil = isNotNil;
|
|
6
|
+
exports.isThenable = isThenable;
|
|
6
7
|
exports.assertNotNil = assertNotNil;
|
|
7
8
|
exports.argNotNil = argNotNil;
|
|
8
9
|
exports.hasOwn = hasOwn;
|
|
@@ -35,6 +36,9 @@ function isNil(x, key) {
|
|
|
35
36
|
function isNotNil(x, key) {
|
|
36
37
|
return !isNil(x) && (key === undefined || !isNil(x[key]));
|
|
37
38
|
}
|
|
39
|
+
function isThenable(x) {
|
|
40
|
+
return x != null && typeof x === 'object' && 'then' in x && typeof x.then === 'function';
|
|
41
|
+
}
|
|
38
42
|
function assertNotNil(x) {
|
|
39
43
|
if (x == null)
|
|
40
44
|
ArgumentError.null('Unexpected null');
|
|
@@ -69,18 +73,14 @@ function intOrUndefined(x) {
|
|
|
69
73
|
const v = Number.parseInt(x);
|
|
70
74
|
return Number.isNaN(v) ? undefined : v;
|
|
71
75
|
}
|
|
72
|
-
function
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
return x;
|
|
77
|
-
return Object.fromEntries(Object.entries(x).filter(p));
|
|
76
|
+
function* excludeEntries(x, p) {
|
|
77
|
+
for (const k in x)
|
|
78
|
+
if (!p(k))
|
|
79
|
+
yield [k, Reflect.get(x, k)];
|
|
78
80
|
}
|
|
79
81
|
function omit(x, ...keys) {
|
|
80
|
-
|
|
81
|
-
return filterEntries(x, ([key]) => !ks.includes(key));
|
|
82
|
+
return Object.fromEntries(excludeEntries(x, Array.prototype.includes.bind(keys)));
|
|
82
83
|
}
|
|
83
84
|
function pick(x, ...keys) {
|
|
84
|
-
|
|
85
|
-
return filterEntries(x, ([key]) => ks.includes(key));
|
|
85
|
+
return Object.fromEntries(keys.map((k) => [keys, x[k]]));
|
|
86
86
|
}
|
package/lib/index.d.ts
CHANGED
|
@@ -28,6 +28,7 @@ export declare function isNotNil<T>(x?: T): x is T;
|
|
|
28
28
|
export declare function isNotNil<T, K extends keyof T>(x: T, key: K): x is T & {
|
|
29
29
|
[P in K]-?: NonNullable<T[K]>;
|
|
30
30
|
};
|
|
31
|
+
export declare function isThenable(x: unknown): boolean;
|
|
31
32
|
export declare function assertNotNil<T>(x: T | null): asserts x is T;
|
|
32
33
|
export declare function argNotNil<T, K extends keyof T>(x: T, key: K): asserts x is T & {
|
|
33
34
|
[P in K]-?: NonNullable<T[K]>;
|
package/lib/index.js
CHANGED
|
@@ -19,6 +19,9 @@ export function isNil(x, key) {
|
|
|
19
19
|
export function isNotNil(x, key) {
|
|
20
20
|
return !isNil(x) && (key === undefined || !isNil(x[key]));
|
|
21
21
|
}
|
|
22
|
+
export function isThenable(x) {
|
|
23
|
+
return x != null && typeof x === 'object' && 'then' in x && typeof x.then === 'function';
|
|
24
|
+
}
|
|
22
25
|
export function assertNotNil(x) {
|
|
23
26
|
if (x == null)
|
|
24
27
|
ArgumentError.null('Unexpected null');
|
|
@@ -53,18 +56,14 @@ export function intOrUndefined(x) {
|
|
|
53
56
|
const v = Number.parseInt(x);
|
|
54
57
|
return Number.isNaN(v) ? undefined : v;
|
|
55
58
|
}
|
|
56
|
-
function
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
return x;
|
|
61
|
-
return Object.fromEntries(Object.entries(x).filter(p));
|
|
59
|
+
function* excludeEntries(x, p) {
|
|
60
|
+
for (const k in x)
|
|
61
|
+
if (!p(k))
|
|
62
|
+
yield [k, Reflect.get(x, k)];
|
|
62
63
|
}
|
|
63
64
|
export function omit(x, ...keys) {
|
|
64
|
-
|
|
65
|
-
return filterEntries(x, ([key]) => !ks.includes(key));
|
|
65
|
+
return Object.fromEntries(excludeEntries(x, Array.prototype.includes.bind(keys)));
|
|
66
66
|
}
|
|
67
67
|
export function pick(x, ...keys) {
|
|
68
|
-
|
|
69
|
-
return filterEntries(x, ([key]) => ks.includes(key));
|
|
68
|
+
return Object.fromEntries(keys.map((k) => [keys, x[k]]));
|
|
70
69
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@drunkcod/argis",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.12",
|
|
5
5
|
"description": "Tiny method arg checking with strong types.",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"clean": "rimraf lib",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"cjs:compile": "tsc --module commonjs --outdir lib/cjs",
|
|
10
10
|
"cjs:fixup": "echo '{\"type\": \"commonjs\"}' > lib/cjs/package.json",
|
|
11
11
|
"build": "npm-run-all clean -p compile cjs:compile -s cjs:fixup --silent",
|
|
12
|
-
"test": "jest"
|
|
12
|
+
"test": "node --experimental-vm-modules --disable-warning=ExperimentalWarning node_modules/jest/bin/jest.js"
|
|
13
13
|
},
|
|
14
14
|
"author": "Tobbe Gyllebring",
|
|
15
15
|
"license": "MIT",
|
|
@@ -32,11 +32,11 @@
|
|
|
32
32
|
}
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
|
-
"@jest/globals": "^
|
|
36
|
-
"jest": "^
|
|
35
|
+
"@jest/globals": "^30.0.4",
|
|
36
|
+
"jest": "^30.0.4",
|
|
37
37
|
"npm-run-all": "^4.1.5",
|
|
38
38
|
"rimraf": "^6.0.1",
|
|
39
|
-
"ts-jest": "^29.
|
|
40
|
-
"typescript": "^5.
|
|
39
|
+
"ts-jest": "^29.4.0",
|
|
40
|
+
"typescript": "^5.8.3"
|
|
41
41
|
}
|
|
42
42
|
}
|