File tree Expand file tree Collapse file tree 2 files changed +10
-10
lines changed Expand file tree Collapse file tree 2 files changed +10
-10
lines changed Original file line number Diff line number Diff line change @@ -69,13 +69,13 @@ And nested ones, too.
69
69
70
70
#### Specific use cases
71
71
72
- | Instance | Serialized as |
73
- | -----------| --------------------------------------------- |
72
+ | Instance | Serialized as |
73
+ | -----------| ------------------------------|
74
74
| ` Date ` | ` string ` via ` toISOString() ` |
75
- | ` RegExp ` | ` string ` |
75
+ | ` RegExp ` | ` string ` |
76
76
77
77
#### Required
78
- You can set specific fields of an object as ` required ` in your schema, by adding ` required: true ` inside the key properties .
78
+ You can set specific fields of an object as required in your schema, by adding the field name inside the ` required ` array in your schema .
79
79
Example:
80
80
``` javascript
81
81
const schema = {
@@ -86,10 +86,10 @@ const schema = {
86
86
type: ' string'
87
87
},
88
88
mail: {
89
- type: ' string' ,
90
- required: true
89
+ type: ' string'
91
90
}
92
- }
91
+ },
92
+ required: [' mail' ]
93
93
}
94
94
```
95
95
If the object to stringify has not the required field(s), ` fast-json-stringify ` will throw an error.
Original file line number Diff line number Diff line change @@ -16,13 +16,13 @@ const stringify = fastJson({
16
16
type : 'integer'
17
17
} ,
18
18
now : {
19
- type : 'string' ,
20
- required : true
19
+ type : 'string'
21
20
} ,
22
21
reg : {
23
22
type : 'string'
24
23
}
25
- }
24
+ } ,
25
+ required : [ 'now' ]
26
26
} )
27
27
28
28
console . log ( stringify ( {
You can’t perform that action at this time.
0 commit comments