-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypes.ts
74 lines (56 loc) · 1.69 KB
/
types.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
export type StringifyType =
| 'bigint'
| 'boolean'
| 'Date'
| 'Error'
| 'function'
| 'Map'
| 'null'
| 'number'
| 'Set'
| 'string'
| 'symbol'
| 'undefined';
export type DateFormat = 'iso' | 'number';
export interface TypedValue<T extends string> {
t: T;
v?: string;
}
// Start stringify
export interface BaseStringifyOptions {
bigintRadix: number;
currentDepth: number;
dateFormat: DateFormat;
ignoreFunctions: boolean;
maxDepth: number;
skipNull: boolean;
skipUndefined: boolean;
}
export interface CustomStringifyOptions<T extends string> extends BaseStringifyOptions {
customStringify: CustomStringify<T>;
}
export type CustomStringifyResult<T extends string> = { useResult: boolean; result?: TypedValue<T> };
export type CustomStringify<T extends string> = (
obj: unknown,
options: CustomStringifyOptions<T>,
) => CustomStringifyResult<T>;
export interface DefaultedStringifyOptions<T extends string> extends BaseStringifyOptions {
customStringify?: CustomStringify<T>;
}
export type StringifyOptions<T extends string> = Partial<DefaultedStringifyOptions<T>>;
// End stringify
// Start parse
export interface BaseParseOptions {
currentDepth: number;
maxDepth: number;
}
export interface CustomParseOptions<T extends string> extends BaseParseOptions {
customParse: CustomParse<T>;
}
export type CustomParseResult = { useResult: boolean; result?: unknown };
export type CustomParse<T extends string> = (obj: TypedValue<T>, options: CustomParseOptions<T>) => CustomParseResult;
export interface DefaultedParseOptions<T extends string> extends BaseParseOptions {
customParse?: CustomParse<T>;
}
export type ParseOptions<T extends string> = Partial<DefaultedParseOptions<T>>;
// End parse