@drunkcod/argis 0.0.13 → 0.0.14
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/Json.d.ts +16 -0
- package/lib/Json.js +2 -0
- package/lib/TypeUtils.d.ts +36 -0
- package/lib/TypeUtils.js +2 -0
- package/lib/cjs/Json.d.ts +16 -0
- package/lib/cjs/Json.js +3 -0
- package/lib/cjs/TypeUtils.d.ts +36 -0
- package/lib/cjs/TypeUtils.js +3 -0
- package/lib/cjs/index.d.ts +3 -0
- package/lib/cjs/index.js +4 -1
- package/lib/cjs/parseBool.d.ts +2 -0
- package/lib/cjs/parseBool.js +16 -0
- package/lib/index.d.ts +3 -0
- package/lib/index.js +1 -0
- package/lib/parseBool.d.ts +2 -0
- package/lib/parseBool.js +11 -0
- package/package.json +7 -6
package/lib/Json.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export interface Jsonable<Json> {
|
|
2
|
+
toJSON(): Json;
|
|
3
|
+
}
|
|
4
|
+
type AnyFn = (...args: any[]) => any;
|
|
5
|
+
type NeverJson = undefined | symbol | AnyFn;
|
|
6
|
+
type EmptyJson = Map<any, any> | Set<any> | WeakMap<any, any> | WeakSet<any> | RegExp;
|
|
7
|
+
declare const JsonErrorSym: unique symbol;
|
|
8
|
+
export type JsonError<T> = {
|
|
9
|
+
[JsonErrorSym]: T;
|
|
10
|
+
};
|
|
11
|
+
export type Json<T, IsRoot = true> = T extends Jsonable<infer J> ? (IsRoot extends true ? Json<J, false> : Json<Omit<T, 'toJSON'>>) : T extends NeverJson ? never : T extends EmptyJson ? Record<string, never> : T extends bigint ? JsonError<'bigint-not-serializeable'> : T extends readonly any[] ? {
|
|
12
|
+
[I in keyof T]: [Json<T[I]>] extends [never] ? null : Json<T[I]>;
|
|
13
|
+
} : T extends object ? {
|
|
14
|
+
[P in keyof T as P extends string | number ? Json<T[P]> extends never ? never : P : never]: Json<T[P]>;
|
|
15
|
+
} : T;
|
|
16
|
+
export {};
|
package/lib/Json.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
type Pretty<T> = {
|
|
2
|
+
[P in keyof T]: T[P];
|
|
3
|
+
} & {};
|
|
4
|
+
declare const SPECIAL_TAG: unique symbol;
|
|
5
|
+
type SpecialTag<T> = {
|
|
6
|
+
readonly [SPECIAL_TAG]: T;
|
|
7
|
+
};
|
|
8
|
+
type TagAny = SpecialTag<'any'>;
|
|
9
|
+
type TagOptional = SpecialTag<'?'>;
|
|
10
|
+
type TagUnknown = SpecialTag<'unknown'>;
|
|
11
|
+
export type IsAny<T> = 0 extends 1 & T ? true : false;
|
|
12
|
+
export type IsUnknown<T> = unknown extends T ? (IsAny<T> extends true ? false : true) : false;
|
|
13
|
+
export type IsOptional<T, K extends keyof T> = {
|
|
14
|
+
[P in K]?: T[K];
|
|
15
|
+
} extends Pick<T, K> ? true : false;
|
|
16
|
+
type TagSpecial<T> = {
|
|
17
|
+
[P in keyof T]: (IsOptional<T, P> extends true ? TagOptional : never) | (IsAny<T[P]> extends true ? TagAny : IsUnknown<T[P]> extends true ? TagUnknown : T[P]);
|
|
18
|
+
};
|
|
19
|
+
type IsTagged<T, X extends SpecialTag<any>> = [Extract<T, X>] extends [never] ? false : true;
|
|
20
|
+
type UnwrapOptional<T> = {
|
|
21
|
+
[P in keyof T as IsTagged<T[P], TagOptional> extends false ? P : never]: T[P];
|
|
22
|
+
} & {
|
|
23
|
+
[P in keyof T as IsTagged<T[P], TagOptional> extends true ? P : never]?: Exclude<T[P], TagOptional>;
|
|
24
|
+
};
|
|
25
|
+
type UnwrapTagsCore<T> = {
|
|
26
|
+
[P in keyof T]: IsTagged<T[P], TagAny> extends true ? any : IsTagged<T[P], TagUnknown> extends true ? unknown : T[P];
|
|
27
|
+
};
|
|
28
|
+
type UnwrapTags<T> = UnwrapTagsCore<UnwrapOptional<T>>;
|
|
29
|
+
type UnionMergeCore<A, B> = {
|
|
30
|
+
[K in keyof A | keyof B]: (K extends keyof A ? A[K] : TagOptional) | (K extends keyof B ? B[K] : TagOptional);
|
|
31
|
+
};
|
|
32
|
+
export type UnionMerge<A, B> = Pretty<UnwrapTags<UnionMergeCore<TagSpecial<A>, TagSpecial<B>>>>;
|
|
33
|
+
export type PickRequired<T> = {
|
|
34
|
+
[P in keyof T as IsOptional<T, P> extends true ? never : P]: T[P];
|
|
35
|
+
};
|
|
36
|
+
export {};
|
package/lib/TypeUtils.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export interface Jsonable<Json> {
|
|
2
|
+
toJSON(): Json;
|
|
3
|
+
}
|
|
4
|
+
type AnyFn = (...args: any[]) => any;
|
|
5
|
+
type NeverJson = undefined | symbol | AnyFn;
|
|
6
|
+
type EmptyJson = Map<any, any> | Set<any> | WeakMap<any, any> | WeakSet<any> | RegExp;
|
|
7
|
+
declare const JsonErrorSym: unique symbol;
|
|
8
|
+
export type JsonError<T> = {
|
|
9
|
+
[JsonErrorSym]: T;
|
|
10
|
+
};
|
|
11
|
+
export type Json<T, IsRoot = true> = T extends Jsonable<infer J> ? (IsRoot extends true ? Json<J, false> : Json<Omit<T, 'toJSON'>>) : T extends NeverJson ? never : T extends EmptyJson ? Record<string, never> : T extends bigint ? JsonError<'bigint-not-serializeable'> : T extends readonly any[] ? {
|
|
12
|
+
[I in keyof T]: [Json<T[I]>] extends [never] ? null : Json<T[I]>;
|
|
13
|
+
} : T extends object ? {
|
|
14
|
+
[P in keyof T as P extends string | number ? Json<T[P]> extends never ? never : P : never]: Json<T[P]>;
|
|
15
|
+
} : T;
|
|
16
|
+
export {};
|
package/lib/cjs/Json.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
type Pretty<T> = {
|
|
2
|
+
[P in keyof T]: T[P];
|
|
3
|
+
} & {};
|
|
4
|
+
declare const SPECIAL_TAG: unique symbol;
|
|
5
|
+
type SpecialTag<T> = {
|
|
6
|
+
readonly [SPECIAL_TAG]: T;
|
|
7
|
+
};
|
|
8
|
+
type TagAny = SpecialTag<'any'>;
|
|
9
|
+
type TagOptional = SpecialTag<'?'>;
|
|
10
|
+
type TagUnknown = SpecialTag<'unknown'>;
|
|
11
|
+
export type IsAny<T> = 0 extends 1 & T ? true : false;
|
|
12
|
+
export type IsUnknown<T> = unknown extends T ? (IsAny<T> extends true ? false : true) : false;
|
|
13
|
+
export type IsOptional<T, K extends keyof T> = {
|
|
14
|
+
[P in K]?: T[K];
|
|
15
|
+
} extends Pick<T, K> ? true : false;
|
|
16
|
+
type TagSpecial<T> = {
|
|
17
|
+
[P in keyof T]: (IsOptional<T, P> extends true ? TagOptional : never) | (IsAny<T[P]> extends true ? TagAny : IsUnknown<T[P]> extends true ? TagUnknown : T[P]);
|
|
18
|
+
};
|
|
19
|
+
type IsTagged<T, X extends SpecialTag<any>> = [Extract<T, X>] extends [never] ? false : true;
|
|
20
|
+
type UnwrapOptional<T> = {
|
|
21
|
+
[P in keyof T as IsTagged<T[P], TagOptional> extends false ? P : never]: T[P];
|
|
22
|
+
} & {
|
|
23
|
+
[P in keyof T as IsTagged<T[P], TagOptional> extends true ? P : never]?: Exclude<T[P], TagOptional>;
|
|
24
|
+
};
|
|
25
|
+
type UnwrapTagsCore<T> = {
|
|
26
|
+
[P in keyof T]: IsTagged<T[P], TagAny> extends true ? any : IsTagged<T[P], TagUnknown> extends true ? unknown : T[P];
|
|
27
|
+
};
|
|
28
|
+
type UnwrapTags<T> = UnwrapTagsCore<UnwrapOptional<T>>;
|
|
29
|
+
type UnionMergeCore<A, B> = {
|
|
30
|
+
[K in keyof A | keyof B]: (K extends keyof A ? A[K] : TagOptional) | (K extends keyof B ? B[K] : TagOptional);
|
|
31
|
+
};
|
|
32
|
+
export type UnionMerge<A, B> = Pretty<UnwrapTags<UnionMergeCore<TagSpecial<A>, TagSpecial<B>>>>;
|
|
33
|
+
export type PickRequired<T> = {
|
|
34
|
+
[P in keyof T as IsOptional<T, P> extends true ? never : P]: T[P];
|
|
35
|
+
};
|
|
36
|
+
export {};
|
package/lib/cjs/index.d.ts
CHANGED
|
@@ -63,3 +63,6 @@ export declare function intOrUndefined(x?: string | null): number | undefined;
|
|
|
63
63
|
export declare function omit<T extends object, K extends OfType<keyof T, string>>(x: T, ...keys: readonly K[]): Omit<T, K>;
|
|
64
64
|
export declare function pick<T extends object, K extends OfType<keyof T, string>>(x: T, ...keys: readonly K[]): Pick<T, K>;
|
|
65
65
|
export { select } from './select.js';
|
|
66
|
+
export { parseBool, isBool } from './parseBool.js';
|
|
67
|
+
export type { Json } from './Json.js';
|
|
68
|
+
export type * from './TypeUtils.js';
|
package/lib/cjs/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.select = exports.ArgumentError = void 0;
|
|
3
|
+
exports.isBool = exports.parseBool = exports.select = exports.ArgumentError = void 0;
|
|
4
4
|
exports.isNil = isNil;
|
|
5
5
|
exports.isNotNil = isNotNil;
|
|
6
6
|
exports.isThenable = isThenable;
|
|
@@ -87,3 +87,6 @@ function pick(x, ...keys) {
|
|
|
87
87
|
}
|
|
88
88
|
var select_js_1 = require("./select.js");
|
|
89
89
|
Object.defineProperty(exports, "select", { enumerable: true, get: function () { return select_js_1.select; } });
|
|
90
|
+
var parseBool_js_1 = require("./parseBool.js");
|
|
91
|
+
Object.defineProperty(exports, "parseBool", { enumerable: true, get: function () { return parseBool_js_1.parseBool; } });
|
|
92
|
+
Object.defineProperty(exports, "isBool", { enumerable: true, get: function () { return parseBool_js_1.isBool; } });
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseBool = void 0;
|
|
4
|
+
exports.isBool = isBool;
|
|
5
|
+
const parseBool = (b) => {
|
|
6
|
+
if (b == null)
|
|
7
|
+
return null;
|
|
8
|
+
const p = b.match(/^(?:\s*)(?:(t(?:rue)?|1|y(?:es)?|on)|(?:f(?:alse)?|0|n(?:o)?|off))(?:\s*)$/i);
|
|
9
|
+
if (p)
|
|
10
|
+
return p[1] !== undefined;
|
|
11
|
+
return null;
|
|
12
|
+
};
|
|
13
|
+
exports.parseBool = parseBool;
|
|
14
|
+
function isBool(x) {
|
|
15
|
+
return x !== null;
|
|
16
|
+
}
|
package/lib/index.d.ts
CHANGED
|
@@ -63,3 +63,6 @@ export declare function intOrUndefined(x?: string | null): number | undefined;
|
|
|
63
63
|
export declare function omit<T extends object, K extends OfType<keyof T, string>>(x: T, ...keys: readonly K[]): Omit<T, K>;
|
|
64
64
|
export declare function pick<T extends object, K extends OfType<keyof T, string>>(x: T, ...keys: readonly K[]): Pick<T, K>;
|
|
65
65
|
export { select } from './select.js';
|
|
66
|
+
export { parseBool, isBool } from './parseBool.js';
|
|
67
|
+
export type { Json } from './Json.js';
|
|
68
|
+
export type * from './TypeUtils.js';
|
package/lib/index.js
CHANGED
package/lib/parseBool.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export const parseBool = (b) => {
|
|
2
|
+
if (b == null)
|
|
3
|
+
return null;
|
|
4
|
+
const p = b.match(/^(?:\s*)(?:(t(?:rue)?|1|y(?:es)?|on)|(?:f(?:alse)?|0|n(?:o)?|off))(?:\s*)$/i);
|
|
5
|
+
if (p)
|
|
6
|
+
return p[1] !== undefined;
|
|
7
|
+
return null;
|
|
8
|
+
};
|
|
9
|
+
export function isBool(x) {
|
|
10
|
+
return x !== null;
|
|
11
|
+
}
|
package/package.json
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@drunkcod/argis",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
5
|
-
"description": "
|
|
4
|
+
"version": "0.0.14",
|
|
5
|
+
"description": "A tiny, type-first toolkit for runtime argument validation and structural object utilities.",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"clean": "rimraf lib",
|
|
8
8
|
"compile": "tsc",
|
|
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": "node --experimental-vm-modules --disable-warning=ExperimentalWarning node_modules/jest/bin/jest.js"
|
|
12
|
+
"test": "node --experimental-vm-modules --disable-warning=ExperimentalWarning node_modules/jest/bin/jest.js",
|
|
13
|
+
"test:typecheck": "tsc --project tsconfig.test.json --noEmit"
|
|
13
14
|
},
|
|
14
15
|
"author": "Tobbe Gyllebring",
|
|
15
16
|
"license": "MIT",
|
|
@@ -33,10 +34,10 @@
|
|
|
33
34
|
},
|
|
34
35
|
"devDependencies": {
|
|
35
36
|
"@jest/globals": "^30.0.4",
|
|
36
|
-
"jest": "^30.
|
|
37
|
+
"jest": "^30.1.1",
|
|
37
38
|
"npm-run-all": "^4.1.5",
|
|
38
39
|
"rimraf": "^6.0.1",
|
|
39
|
-
"ts-jest": "^29.4.
|
|
40
|
-
"typescript": "^5.
|
|
40
|
+
"ts-jest": "^29.4.1",
|
|
41
|
+
"typescript": "^5.9.2"
|
|
41
42
|
}
|
|
42
43
|
}
|