pema 0.1.0
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/private/AbstractConstructor.d.ts +3 -0
- package/lib/private/AbstractConstructor.js +2 -0
- package/lib/private/ArrayType.d.ts +12 -0
- package/lib/private/ArrayType.js +48 -0
- package/lib/private/BigIntType.d.ts +5 -0
- package/lib/private/BigIntType.js +7 -0
- package/lib/private/BlobType.d.ts +5 -0
- package/lib/private/BlobType.js +7 -0
- package/lib/private/BooleanType.d.ts +5 -0
- package/lib/private/BooleanType.js +7 -0
- package/lib/private/BuiltinType.d.ts +10 -0
- package/lib/private/BuiltinType.js +26 -0
- package/lib/private/ConstructorType.d.ts +12 -0
- package/lib/private/ConstructorType.js +28 -0
- package/lib/private/DateType.d.ts +5 -0
- package/lib/private/DateType.js +7 -0
- package/lib/private/DefaultType.d.ts +10 -0
- package/lib/private/DefaultType.js +27 -0
- package/lib/private/FileType.d.ts +5 -0
- package/lib/private/FileType.js +7 -0
- package/lib/private/GenericType.d.ts +7 -0
- package/lib/private/GenericType.js +10 -0
- package/lib/private/Infer.d.ts +4 -0
- package/lib/private/Infer.js +2 -0
- package/lib/private/InferSchema.d.ts +20 -0
- package/lib/private/InferSchema.js +2 -0
- package/lib/private/IntType.d.ts +7 -0
- package/lib/private/IntType.js +16 -0
- package/lib/private/LiteralType.d.ts +12 -0
- package/lib/private/LiteralType.js +24 -0
- package/lib/private/MaybeInt.d.ts +3 -0
- package/lib/private/MaybeInt.js +2 -0
- package/lib/private/NormalizeSchema.d.ts +16 -0
- package/lib/private/NormalizeSchema.js +2 -0
- package/lib/private/NullType.d.ts +7 -0
- package/lib/private/NullType.js +20 -0
- package/lib/private/NumberType.d.ts +5 -0
- package/lib/private/NumberType.js +7 -0
- package/lib/private/OptionalType.d.ts +10 -0
- package/lib/private/OptionalType.js +20 -0
- package/lib/private/PrimitiveType.d.ts +11 -0
- package/lib/private/PrimitiveType.js +31 -0
- package/lib/private/RecordType.d.ts +13 -0
- package/lib/private/RecordType.js +58 -0
- package/lib/private/RecordTypeKey.d.ts +6 -0
- package/lib/private/RecordTypeKey.js +2 -0
- package/lib/private/Schema.d.ts +7 -0
- package/lib/private/Schema.js +2 -0
- package/lib/private/SchemaType.d.ts +13 -0
- package/lib/private/SchemaType.js +63 -0
- package/lib/private/StringType.d.ts +8 -0
- package/lib/private/StringType.js +23 -0
- package/lib/private/SymbolType.d.ts +5 -0
- package/lib/private/SymbolType.js +7 -0
- package/lib/private/TupleType.d.ts +17 -0
- package/lib/private/TupleType.js +40 -0
- package/lib/private/Type.d.ts +10 -0
- package/lib/private/Type.js +15 -0
- package/lib/private/URLType.d.ts +5 -0
- package/lib/private/URLType.js +7 -0
- package/lib/private/UintType.d.ts +9 -0
- package/lib/private/UintType.js +16 -0
- package/lib/private/UndefinedType.d.ts +7 -0
- package/lib/private/UndefinedType.js +7 -0
- package/lib/private/UnionType.d.ts +18 -0
- package/lib/private/UnionType.js +63 -0
- package/lib/private/Validated.d.ts +8 -0
- package/lib/private/Validated.js +10 -0
- package/lib/private/ValidatedKey.d.ts +4 -0
- package/lib/private/ValidatedKey.js +3 -0
- package/lib/private/Validator.d.ts +3 -0
- package/lib/private/Validator.js +2 -0
- package/lib/private/array.d.ts +5 -0
- package/lib/private/array.js +3 -0
- package/lib/private/bigint.d.ts +4 -0
- package/lib/private/bigint.js +3 -0
- package/lib/private/blob.d.ts +4 -0
- package/lib/private/blob.js +3 -0
- package/lib/private/boolean.d.ts +4 -0
- package/lib/private/boolean.js +3 -0
- package/lib/private/constructor.d.ts +5 -0
- package/lib/private/constructor.js +3 -0
- package/lib/private/date.d.ts +4 -0
- package/lib/private/date.js +3 -0
- package/lib/private/error.d.ts +3 -0
- package/lib/private/error.js +4 -0
- package/lib/private/expect.d.ts +21 -0
- package/lib/private/expect.js +21 -0
- package/lib/private/expected.d.ts +3 -0
- package/lib/private/expected.js +2 -0
- package/lib/private/file.d.ts +4 -0
- package/lib/private/file.js +3 -0
- package/lib/private/index.d.ts +5 -0
- package/lib/private/index.js +43 -0
- package/lib/private/int.d.ts +4 -0
- package/lib/private/int.js +3 -0
- package/lib/private/is-int.d.ts +3 -0
- package/lib/private/is-int.js +5 -0
- package/lib/private/is_validated_type.d.ts +4 -0
- package/lib/private/is_validated_type.js +5 -0
- package/lib/private/literal.d.ts +5 -0
- package/lib/private/literal.js +3 -0
- package/lib/private/null.d.ts +4 -0
- package/lib/private/null.js +3 -0
- package/lib/private/number.d.ts +4 -0
- package/lib/private/number.js +3 -0
- package/lib/private/optional.d.ts +5 -0
- package/lib/private/optional.js +3 -0
- package/lib/private/record.d.ts +6 -0
- package/lib/private/record.js +3 -0
- package/lib/private/string.d.ts +4 -0
- package/lib/private/string.js +3 -0
- package/lib/private/symbol.d.ts +4 -0
- package/lib/private/symbol.js +3 -0
- package/lib/private/tuple.d.ts +5 -0
- package/lib/private/tuple.js +3 -0
- package/lib/private/uint.d.ts +4 -0
- package/lib/private/uint.js +3 -0
- package/lib/private/undefined.d.ts +4 -0
- package/lib/private/undefined.js +3 -0
- package/lib/private/union.d.ts +9 -0
- package/lib/private/union.js +3 -0
- package/lib/private/url.d.ts +4 -0
- package/lib/private/url.js +3 -0
- package/lib/public/Schema.d.ts +2 -0
- package/lib/public/Schema.js +2 -0
- package/lib/public/blob.d.ts +2 -0
- package/lib/public/blob.js +2 -0
- package/lib/public/boolean.d.ts +2 -0
- package/lib/public/boolean.js +2 -0
- package/lib/public/constructor.d.ts +2 -0
- package/lib/public/constructor.js +2 -0
- package/lib/public/date.d.ts +2 -0
- package/lib/public/date.js +2 -0
- package/lib/public/file.d.ts +2 -0
- package/lib/public/file.js +2 -0
- package/lib/public/index.d.ts +2 -0
- package/lib/public/index.js +2 -0
- package/lib/public/int.d.ts +2 -0
- package/lib/public/int.js +2 -0
- package/lib/public/number.d.ts +2 -0
- package/lib/public/number.js +2 -0
- package/lib/public/object.d.ts +2 -0
- package/lib/public/object.js +2 -0
- package/lib/public/optional.d.ts +2 -0
- package/lib/public/optional.js +2 -0
- package/lib/public/record.d.ts +2 -0
- package/lib/public/record.js +2 -0
- package/lib/public/string.d.ts +2 -0
- package/lib/public/string.js +2 -0
- package/lib/public/symbol.d.ts +2 -0
- package/lib/public/symbol.js +2 -0
- package/lib/public/union.d.ts +2 -0
- package/lib/public/union.js +2 -0
- package/package.json +45 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import GenericType from "#GenericType";
|
|
2
|
+
import type Infer from "#Infer";
|
|
3
|
+
import type InferSchema from "#InferSchema";
|
|
4
|
+
import OptionalType from "#OptionalType";
|
|
5
|
+
import type Schema from "#Schema";
|
|
6
|
+
export default class SchemaType<S extends Schema> extends GenericType<S, InferSchema<S>, "SchemaType"> {
|
|
7
|
+
#private;
|
|
8
|
+
constructor(s: S);
|
|
9
|
+
optional(): OptionalType<this>;
|
|
10
|
+
get name(): string;
|
|
11
|
+
validate(x: unknown, key?: string): Infer<this>;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=SchemaType.d.ts.map
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import GenericType from "#GenericType";
|
|
2
|
+
import OptionalType from "#OptionalType";
|
|
3
|
+
import Validated from "#Validated";
|
|
4
|
+
import schema from "#index";
|
|
5
|
+
export default class SchemaType extends GenericType {
|
|
6
|
+
#schema;
|
|
7
|
+
constructor(s) {
|
|
8
|
+
super();
|
|
9
|
+
this.#schema = s;
|
|
10
|
+
}
|
|
11
|
+
optional() {
|
|
12
|
+
return new OptionalType(this);
|
|
13
|
+
}
|
|
14
|
+
get name() {
|
|
15
|
+
return "schema";
|
|
16
|
+
}
|
|
17
|
+
validate(x, key) {
|
|
18
|
+
const s = this.#schema;
|
|
19
|
+
if (s instanceof Validated) {
|
|
20
|
+
return s.validate(x, key);
|
|
21
|
+
}
|
|
22
|
+
if (Array.isArray(s)) {
|
|
23
|
+
if (s.length === 1) {
|
|
24
|
+
if (!Array.isArray(x))
|
|
25
|
+
throw new Error("Expected array");
|
|
26
|
+
return x.map((item) => schema(s[0]).validate(item, key));
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
if (!Array.isArray(x))
|
|
30
|
+
throw new Error("Expected tuple");
|
|
31
|
+
if (x.length !== s.length)
|
|
32
|
+
throw new Error("Tuple length mismatch");
|
|
33
|
+
return s.map((sch, i) => schema(sch).validate(x[i], key));
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
if (typeof s === "object" && s !== null) {
|
|
37
|
+
if (typeof x !== "object" || x === null) {
|
|
38
|
+
throw new Error("Expected object");
|
|
39
|
+
}
|
|
40
|
+
const result = {};
|
|
41
|
+
for (const k in s) {
|
|
42
|
+
const r = schema(s[k]).validate(x[k], `.${k}`);
|
|
43
|
+
// exclude undefined (optionals)
|
|
44
|
+
if (r !== undefined) {
|
|
45
|
+
result[k] = r;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return result;
|
|
49
|
+
}
|
|
50
|
+
if (s === null) {
|
|
51
|
+
if (x !== null)
|
|
52
|
+
throw new Error("Expected null");
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
if (s === undefined) {
|
|
56
|
+
if (x !== undefined)
|
|
57
|
+
throw new Error("Expected undefined");
|
|
58
|
+
return undefined;
|
|
59
|
+
}
|
|
60
|
+
throw new Error("Invalid schema structure");
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=SchemaType.js.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import PrimitiveType from "#PrimitiveType";
|
|
2
|
+
import type Validator from "#Validator";
|
|
3
|
+
export default class StringType extends PrimitiveType<string, "StringType"> {
|
|
4
|
+
constructor(validators?: Validator<string>[]);
|
|
5
|
+
startsWith(prefix: string): StringType;
|
|
6
|
+
endsWith(suffix: string): StringType;
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=StringType.d.ts.map
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import PrimitiveType from "#PrimitiveType";
|
|
2
|
+
const starts_with_validator = (prefix) => (x) => {
|
|
3
|
+
if (!x.startsWith(prefix)) {
|
|
4
|
+
throw new Error(`"${x}" does not start with "${prefix}"`);
|
|
5
|
+
}
|
|
6
|
+
};
|
|
7
|
+
const ends_with_validator = (suffix) => (x) => {
|
|
8
|
+
if (!x.endsWith(suffix)) {
|
|
9
|
+
throw new Error(`"${x}" does not end with "${suffix}"`);
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
export default class StringType extends PrimitiveType {
|
|
13
|
+
constructor(validators) {
|
|
14
|
+
super("string", validators);
|
|
15
|
+
}
|
|
16
|
+
startsWith(prefix) {
|
|
17
|
+
return new StringType([...this.validators, starts_with_validator(prefix)]);
|
|
18
|
+
}
|
|
19
|
+
endsWith(suffix) {
|
|
20
|
+
return new StringType([...this.validators, ends_with_validator(suffix)]);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=StringType.js.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import GenericType from "#GenericType";
|
|
2
|
+
import type Infer from "#Infer";
|
|
3
|
+
import type InferSchema from "#InferSchema";
|
|
4
|
+
import OptionalType from "#OptionalType";
|
|
5
|
+
import type Schema from "#Schema";
|
|
6
|
+
type InferTuple<T extends Schema[]> = {
|
|
7
|
+
[K in keyof T]: T[K] extends Schema ? InferSchema<T[K]> : "tuple-never";
|
|
8
|
+
};
|
|
9
|
+
export default class TupleType<T extends Schema[]> extends GenericType<T, InferTuple<T>, "TupleType"> {
|
|
10
|
+
#private;
|
|
11
|
+
constructor(members: T);
|
|
12
|
+
optional(): OptionalType<this>;
|
|
13
|
+
get name(): string;
|
|
14
|
+
validate(x: unknown, key?: string): Infer<this>;
|
|
15
|
+
}
|
|
16
|
+
export {};
|
|
17
|
+
//# sourceMappingURL=TupleType.d.ts.map
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import error from "#error";
|
|
2
|
+
import expected from "#expected";
|
|
3
|
+
import GenericType from "#GenericType";
|
|
4
|
+
import schema from "#index";
|
|
5
|
+
import is_validated_type from "#is_validated_type";
|
|
6
|
+
import OptionalType from "#OptionalType";
|
|
7
|
+
const member_error = (i, key) => {
|
|
8
|
+
return key === undefined
|
|
9
|
+
? `[${i}]`
|
|
10
|
+
: `${key}[${i}]`;
|
|
11
|
+
};
|
|
12
|
+
export default class TupleType extends GenericType {
|
|
13
|
+
#members;
|
|
14
|
+
constructor(members) {
|
|
15
|
+
super();
|
|
16
|
+
this.#members = members;
|
|
17
|
+
}
|
|
18
|
+
optional() {
|
|
19
|
+
return new OptionalType(this);
|
|
20
|
+
}
|
|
21
|
+
get name() {
|
|
22
|
+
return "tuple";
|
|
23
|
+
}
|
|
24
|
+
validate(x, key) {
|
|
25
|
+
if (!(!!x && Array.isArray(x))) {
|
|
26
|
+
throw new Error(error(expected("array", x), key));
|
|
27
|
+
}
|
|
28
|
+
this.#members.forEach((v, i) => {
|
|
29
|
+
const validator = is_validated_type(v) ? v : schema(v);
|
|
30
|
+
validator.validate(x[i], `${member_error(i, key)}`);
|
|
31
|
+
});
|
|
32
|
+
x.forEach((v, i) => {
|
|
33
|
+
const member = this.#members[i];
|
|
34
|
+
const validator = is_validated_type(member) ? member : schema(member);
|
|
35
|
+
validator.validate(v, `${member_error(i, key)}`);
|
|
36
|
+
});
|
|
37
|
+
return x;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=TupleType.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import DefaultType from "#DefaultType";
|
|
2
|
+
import OptionalType from "#OptionalType";
|
|
3
|
+
import Validated from "#Validated";
|
|
4
|
+
import type Printable from "@rcompat/type/Printable";
|
|
5
|
+
export default abstract class Type<Type, Name extends string> extends Validated<Type> implements Printable {
|
|
6
|
+
optional(): OptionalType<this>;
|
|
7
|
+
default<const S extends Type>(value: S | (() => S)): DefaultType<this, S>;
|
|
8
|
+
get Name(): Name;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=Type.d.ts.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import DefaultType from "#DefaultType";
|
|
2
|
+
import OptionalType from "#OptionalType";
|
|
3
|
+
import Validated from "#Validated";
|
|
4
|
+
export default class Type extends Validated {
|
|
5
|
+
optional() {
|
|
6
|
+
return new OptionalType(this);
|
|
7
|
+
}
|
|
8
|
+
default(value) {
|
|
9
|
+
return new DefaultType(this, value);
|
|
10
|
+
}
|
|
11
|
+
get Name() {
|
|
12
|
+
return undefined;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=Type.js.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type Infer from "#Infer";
|
|
2
|
+
import PrimitiveType from "#PrimitiveType";
|
|
3
|
+
type Name = "UintType";
|
|
4
|
+
export default class UintType extends PrimitiveType<number | bigint, Name> {
|
|
5
|
+
constructor();
|
|
6
|
+
validate(x: unknown, key?: string): Infer<this>;
|
|
7
|
+
}
|
|
8
|
+
export {};
|
|
9
|
+
//# sourceMappingURL=UintType.d.ts.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import PrimitiveType from "#PrimitiveType";
|
|
2
|
+
import error from "#error";
|
|
3
|
+
import expected from "#expected";
|
|
4
|
+
import is_int from "#is-int";
|
|
5
|
+
export default class UintType extends PrimitiveType {
|
|
6
|
+
constructor() {
|
|
7
|
+
super("uint");
|
|
8
|
+
}
|
|
9
|
+
validate(x, key) {
|
|
10
|
+
if (!is_int(x) || x < 0) {
|
|
11
|
+
throw new Error(error(expected("uint", x), key));
|
|
12
|
+
}
|
|
13
|
+
return x;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=UintType.js.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import GenericType from "#GenericType";
|
|
2
|
+
import type Infer from "#Infer";
|
|
3
|
+
import type InferSchema from "#InferSchema";
|
|
4
|
+
import OptionalType from "#OptionalType";
|
|
5
|
+
import type Schema from "#Schema";
|
|
6
|
+
import type TupleToUnion from "@rcompat/type/TupleToUnion";
|
|
7
|
+
type InferUnion<T extends Schema[]> = TupleToUnion<{
|
|
8
|
+
[K in keyof T]: T[K] extends Schema ? InferSchema<T[K]> : "union-never";
|
|
9
|
+
}>;
|
|
10
|
+
export default class UnionType<T extends Schema[]> extends GenericType<T, InferUnion<T>, "UnionType"> {
|
|
11
|
+
#private;
|
|
12
|
+
constructor(types: T);
|
|
13
|
+
optional(): OptionalType<this>;
|
|
14
|
+
get name(): string;
|
|
15
|
+
validate(x: unknown, key?: string): Infer<this>;
|
|
16
|
+
}
|
|
17
|
+
export {};
|
|
18
|
+
//# sourceMappingURL=UnionType.d.ts.map
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import expected from "#expected";
|
|
2
|
+
import GenericType from "#GenericType";
|
|
3
|
+
import schema from "#index";
|
|
4
|
+
import is_validated_type from "#is_validated_type";
|
|
5
|
+
import OptionalType from "#OptionalType";
|
|
6
|
+
import assert from "@rcompat/invariant/assert";
|
|
7
|
+
const error = (message, key) => {
|
|
8
|
+
return key === undefined
|
|
9
|
+
? message
|
|
10
|
+
: `${key}: ${message}`;
|
|
11
|
+
};
|
|
12
|
+
const print = (type) => {
|
|
13
|
+
const validated = is_validated_type(type);
|
|
14
|
+
if (validated) {
|
|
15
|
+
return type.name;
|
|
16
|
+
}
|
|
17
|
+
const type_of = typeof type;
|
|
18
|
+
if (type_of === "string") {
|
|
19
|
+
return `"${type}"`;
|
|
20
|
+
}
|
|
21
|
+
if (type_of === "bigint") {
|
|
22
|
+
return `${type}n`;
|
|
23
|
+
}
|
|
24
|
+
if (type_of === "object") {
|
|
25
|
+
return `{ ${Object.entries(type)
|
|
26
|
+
.map(([name, subtype]) => `${name}: ${print(subtype)}`)
|
|
27
|
+
.join(", ")} }`;
|
|
28
|
+
}
|
|
29
|
+
return type;
|
|
30
|
+
};
|
|
31
|
+
const to_union_string = (types) => `\`${types.map(t => is_validated_type(t) ? t.name : print(t)).join(" | ")}\``;
|
|
32
|
+
export default class UnionType extends GenericType {
|
|
33
|
+
#types;
|
|
34
|
+
constructor(types) {
|
|
35
|
+
assert(types.length > 1, "union type must have at least two members");
|
|
36
|
+
super();
|
|
37
|
+
this.#types = types;
|
|
38
|
+
}
|
|
39
|
+
optional() {
|
|
40
|
+
return new OptionalType(this);
|
|
41
|
+
}
|
|
42
|
+
get name() {
|
|
43
|
+
return "union";
|
|
44
|
+
}
|
|
45
|
+
validate(x, key) {
|
|
46
|
+
// union validates when any of its members validates
|
|
47
|
+
const validated = this.#types.some(type => {
|
|
48
|
+
const validator = is_validated_type(type) ? type : schema(type);
|
|
49
|
+
try {
|
|
50
|
+
validator.validate(x, key);
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
if (!validated) {
|
|
58
|
+
throw new Error(error(expected(to_union_string(this.#types), x), key));
|
|
59
|
+
}
|
|
60
|
+
return x;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=UnionType.js.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import ValidatedKey from "#ValidatedKey";
|
|
2
|
+
export default abstract class Validated<StaticType> {
|
|
3
|
+
get [ValidatedKey](): "ValidatedKey";
|
|
4
|
+
get infer(): StaticType;
|
|
5
|
+
abstract get name(): string;
|
|
6
|
+
abstract validate(x: unknown, key?: string): StaticType;
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=Validated.d.ts.map
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import ConstructorType from "#ConstructorType";
|
|
2
|
+
import type AbstractConstructor from "@rcompat/type/AbstractConstructor";
|
|
3
|
+
declare const _default: <const C extends AbstractConstructor>(constructor: C) => ConstructorType<C>;
|
|
4
|
+
export default _default;
|
|
5
|
+
//# sourceMappingURL=constructor.d.ts.map
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
declare const types: {
|
|
2
|
+
a: string;
|
|
3
|
+
b: string;
|
|
4
|
+
d: string;
|
|
5
|
+
n: string;
|
|
6
|
+
s: string;
|
|
7
|
+
u: string;
|
|
8
|
+
bt: string;
|
|
9
|
+
f: string;
|
|
10
|
+
bb: string;
|
|
11
|
+
o: string;
|
|
12
|
+
nl: string;
|
|
13
|
+
sy: string;
|
|
14
|
+
ur: string;
|
|
15
|
+
i: string;
|
|
16
|
+
ui: string;
|
|
17
|
+
co: string;
|
|
18
|
+
};
|
|
19
|
+
declare const _default: (type: keyof typeof types, got: unknown, at?: string) => string;
|
|
20
|
+
export default _default;
|
|
21
|
+
//# sourceMappingURL=expect.d.ts.map
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
const types = {
|
|
2
|
+
a: "array",
|
|
3
|
+
b: "boolean",
|
|
4
|
+
d: "date",
|
|
5
|
+
n: "number",
|
|
6
|
+
s: "string",
|
|
7
|
+
u: "undefined",
|
|
8
|
+
bt: "bigint",
|
|
9
|
+
f: "file",
|
|
10
|
+
bb: "blob",
|
|
11
|
+
o: "object",
|
|
12
|
+
nl: "null",
|
|
13
|
+
sy: "symbol",
|
|
14
|
+
ur: "url",
|
|
15
|
+
i: "int",
|
|
16
|
+
ui: "uint",
|
|
17
|
+
co: "constructor",
|
|
18
|
+
};
|
|
19
|
+
const prefix = (at) => at ? `${at}: ` : "";
|
|
20
|
+
export default (type, got, at = "") => `${prefix(at)}expected ${types[type]}, got \`${got}\` (${typeof got})`;
|
|
21
|
+
//# sourceMappingURL=expect.js.map
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import array from "#array";
|
|
2
|
+
import constructor from "#constructor";
|
|
3
|
+
import is_validated_type from "#is_validated_type";
|
|
4
|
+
import literal from "#literal";
|
|
5
|
+
import null_type from "#null";
|
|
6
|
+
import SchemaType from "#SchemaType";
|
|
7
|
+
import tuple from "#tuple";
|
|
8
|
+
import undefined_type from "#undefined";
|
|
9
|
+
const is_constructor = (value) => {
|
|
10
|
+
try {
|
|
11
|
+
if (typeof value !== "function")
|
|
12
|
+
return false;
|
|
13
|
+
new value();
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
export default function schema(s) {
|
|
21
|
+
if (s === null) {
|
|
22
|
+
return new SchemaType(null_type);
|
|
23
|
+
}
|
|
24
|
+
if (s === undefined) {
|
|
25
|
+
return new SchemaType(undefined_type);
|
|
26
|
+
}
|
|
27
|
+
if (typeof s === "string") {
|
|
28
|
+
return new SchemaType(literal(s));
|
|
29
|
+
}
|
|
30
|
+
if (is_constructor(s)) {
|
|
31
|
+
return new SchemaType(constructor(s));
|
|
32
|
+
}
|
|
33
|
+
if (Array.isArray(s)) {
|
|
34
|
+
if (s.length === 1 && is_validated_type(s[0])) {
|
|
35
|
+
return new SchemaType(array(s[0]));
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
return new SchemaType(tuple(...s));
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return new SchemaType(s);
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=index.js.map
|