-
Notifications
You must be signed in to change notification settings - Fork 4
/
typology.d.ts
54 lines (40 loc) · 1.1 KB
/
typology.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/**
* Typology types syntax:
*/
export type TypologyType = StringType | ArrayType | ObjectType | CustomValidator;
export type StringType = string;
export type ArrayType = [TypologyType];
export interface ObjectType {
[key: string]: TypologyType;
}
export type CustomValidator = (v: unknown) => boolean;
/**
* Typology reports:
*/
export interface Report {
expected: TypologyType;
type: StringType;
value: unknown;
error?: string;
path?: (string | number)[];
nully?: boolean;
}
/**
* Public API:
*/
export interface Typology<Type = TypologyType> {
// Constructor:
new <T = TypologyType>(types?: Record<string, T>): Typology<T>;
// Class methods / "static" methods:
check(type: Type, value: unknown): boolean;
scan(type: Type, value: unknown): Report;
get(value: any): string;
add(typeId: string, type: Type): this;
add(typeDefinition: { id: string; type: TypologyType; proto?: string[] }): this;
has(typeId: string): boolean;
isValid(type: unknown): boolean;
// Static properties:
version: string;
}
declare const types: Typology<TypologyType>;
export default types;