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.
6969
7070#### Specific use cases
7171
72- | Instance | Serialized as |
73- | -----------| --------------------------------------------- |
72+ | Instance | Serialized as |
73+ | -----------| ------------------------------|
7474| ` Date ` | ` string ` via ` toISOString() ` |
75- | ` RegExp ` | ` string ` |
75+ | ` RegExp ` | ` string ` |
7676
7777#### 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 .
7979Example:
8080``` javascript
8181const schema = {
@@ -86,10 +86,10 @@ const schema = {
8686 type: ' string'
8787 },
8888 mail: {
89- type: ' string' ,
90- required: true
89+ type: ' string'
9190 }
92- }
91+ },
92+ required: [' mail' ]
9393}
9494```
9595If 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({
1616 type : 'integer'
1717 } ,
1818 now : {
19- type : 'string' ,
20- required : true
19+ type : 'string'
2120 } ,
2221 reg : {
2322 type : 'string'
2423 }
25- }
24+ } ,
25+ required : [ 'now' ]
2626} )
2727
2828console . log ( stringify ( {
You can’t perform that action at this time.
0 commit comments