-
Notifications
You must be signed in to change notification settings - Fork 0
/
parse.d.ts
78 lines (63 loc) · 1.43 KB
/
parse.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import {
Schema
} from './schema.d.js';
import {
DateFormat,
Types
} from './index.d.js';
export type Structure = 'flat';
export type ParseErrorType =
'ambiguous' |
'unsupported' |
'invalid' |
'unknown';
export interface SchemaParseError {
message: string;
errors: string[];
type?: ParseErrorType;
path?: string;
value: any;
}
interface CreateParseErrorArgs {
message: string;
errors: string[];
type?: ParseErrorType;
path?: string;
value: any;
}
export type CreateParseError = (CreateParseErrorArgs) => SchemaParseError;
interface ParsePropertyValueArgs {
path: string;
type: string;
value: string;
};
type ParsePropertyValue = (ParsePropertyValueArgs) => any;
interface ParsePropertyArgs {
path: string;
type: string;
value: string;
parsePropertyValue: ParsePropertyValue;
createParseError: CreateParseError;
// context?: object;
}
export type ParseProperty = (ParsePropertyArgs) => any;
type Schemas = {
[name: string]: Schema;
}
export interface SchemaParseOptions {
schemas?: Schemas;
inPlace?: boolean;
dateFormat?: DateFormat;
parseDatesOnly?: boolean;
structure?: Structure;
parseProperty?: ParseProperty;
createParseError?: CreateParseError;
customTypes?: Types;
// context?: object;
}
export type ParseFunction = (data: object) => object;
declare function schemaParser(
schema: Schema,
options?: SchemaParseOptions
): ParseFunction;
export default schemaParser;