-
Notifications
You must be signed in to change notification settings - Fork 17
/
index.d.ts
78 lines (68 loc) · 1.63 KB
/
index.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
export as namespace SlowJsonStringify;
export type JSONPrimitive =
string
| number
| boolean
| null;
export type AttrType =
'string'
| 'number'
| 'boolean'
| 'array'
| 'null';
/**
* SjsSchema
*
* Schema that describe the structure of your data.
*
* Usage: https://github.com/lucagez/slow-json-stringify#usage
*/
export type SjsSchema = { [prop: string]: AttrExecutable | SjsSchema };
/**
* SjsSerializer
*
* Serialize any object enforcing the provided schema.
*/
export type SjsSerializer = (obj: unknown) => string;
/**
* SjsEscaper
*
* Escape any string against the previously provided regex.
*/
export type SjsEscaper = (str: string) => string;
/**
* AttrExecutable
*
* Object that should be used only inside sjs schemas.
*/
export type AttrExecutable = object;
/**
* Mapping between AttrType and JSONPrimitive??
*
* The resulting JSONPrimitive should be of the same
* type of AttrType. As the created template has a spot
* to host the requested type.
*/
export type Serializer = (raw: any) => JSONPrimitive;
/**
* attr
*
* Utility used to define how sjs should handle the
* provided raw data.
*/
export function attr(type: 'array', serializer?: SjsSerializer): AttrExecutable;
export function attr(type: AttrType, serializer?: Serializer): AttrExecutable;
/**
* escape
*
* Provides basic escaping facilities.
* @default regex - \\n|\\r|\\t|\\"|\\\\
*/
export function escape(regex?: RegExp): (str: string) => string;
/**
* sjs
*
* compile the provided schema and exports a function
* that serialize objects enforcing the schema.
*/
export function sjs(schema: SjsSchema): SjsSerializer;