fast-json-stringify 1.15.0 → 1.15.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bench.js +82 -11
- package/build-schema-validator.js +1 -1
- package/example.js +1 -1
- package/index.js +60 -22
- package/package.json +12 -5
- package/test/additionalProperties.test.js +5 -5
- package/test/anyof.test.js +18 -1
- package/test/array.test.js +58 -58
- package/test/basic.test.js +87 -87
- package/test/defaults.test.js +142 -142
- package/test/if-then-else.test.js +93 -93
- package/test/inferType.test.js +27 -27
- package/test/json-schema-test-suite/util.js +1 -1
- package/test/nullable.test.js +19 -19
- package/test/patternProperties.test.js +2 -2
- package/test/ref.test.js +282 -0
- package/test/sanitize.test.js +142 -0
package/test/basic.test.js
CHANGED
|
@@ -23,25 +23,25 @@ function buildTest (schema, toStringify) {
|
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
buildTest({
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
26
|
+
title: 'basic',
|
|
27
|
+
type: 'object',
|
|
28
|
+
properties: {
|
|
29
|
+
firstName: {
|
|
30
|
+
type: 'string'
|
|
31
31
|
},
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
lastName: {
|
|
33
|
+
type: 'string'
|
|
34
34
|
},
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
35
|
+
age: {
|
|
36
|
+
description: 'Age in years',
|
|
37
|
+
type: 'integer',
|
|
38
|
+
minimum: 0
|
|
39
39
|
},
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
magic: {
|
|
41
|
+
type: 'number'
|
|
42
42
|
}
|
|
43
43
|
},
|
|
44
|
-
|
|
44
|
+
required: ['firstName', 'lastName']
|
|
45
45
|
}, {
|
|
46
46
|
firstName: 'Matteo',
|
|
47
47
|
lastName: 'Collina',
|
|
@@ -85,21 +85,21 @@ buildTest({
|
|
|
85
85
|
}, 42.42)
|
|
86
86
|
|
|
87
87
|
buildTest({
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
88
|
+
title: 'deep',
|
|
89
|
+
type: 'object',
|
|
90
|
+
properties: {
|
|
91
|
+
firstName: {
|
|
92
|
+
type: 'string'
|
|
93
93
|
},
|
|
94
|
-
|
|
95
|
-
|
|
94
|
+
lastName: {
|
|
95
|
+
type: 'string'
|
|
96
96
|
},
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
97
|
+
more: {
|
|
98
|
+
description: 'more properties',
|
|
99
|
+
type: 'object',
|
|
100
|
+
properties: {
|
|
101
|
+
something: {
|
|
102
|
+
type: 'string'
|
|
103
103
|
}
|
|
104
104
|
}
|
|
105
105
|
}
|
|
@@ -113,16 +113,16 @@ buildTest({
|
|
|
113
113
|
})
|
|
114
114
|
|
|
115
115
|
buildTest({
|
|
116
|
-
|
|
117
|
-
|
|
116
|
+
title: 'null',
|
|
117
|
+
type: 'null'
|
|
118
118
|
}, null)
|
|
119
119
|
|
|
120
120
|
buildTest({
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
121
|
+
title: 'deep object with weird keys',
|
|
122
|
+
type: 'object',
|
|
123
|
+
properties: {
|
|
124
124
|
'@version': {
|
|
125
|
-
|
|
125
|
+
type: 'integer'
|
|
126
126
|
}
|
|
127
127
|
}
|
|
128
128
|
}, {
|
|
@@ -130,30 +130,30 @@ buildTest({
|
|
|
130
130
|
})
|
|
131
131
|
|
|
132
132
|
buildTest({
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
133
|
+
title: 'deep object with spaces in key',
|
|
134
|
+
type: 'object',
|
|
135
|
+
properties: {
|
|
136
136
|
'spaces in key': {
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
137
|
+
type: 'object',
|
|
138
|
+
properties: {
|
|
139
|
+
something: {
|
|
140
|
+
type: 'integer'
|
|
141
141
|
}
|
|
142
142
|
}
|
|
143
143
|
}
|
|
144
144
|
}
|
|
145
145
|
}, {
|
|
146
146
|
'spaces in key': {
|
|
147
|
-
|
|
147
|
+
something: 1
|
|
148
148
|
}
|
|
149
149
|
})
|
|
150
150
|
|
|
151
151
|
buildTest({
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
152
|
+
title: 'with null',
|
|
153
|
+
type: 'object',
|
|
154
|
+
properties: {
|
|
155
|
+
firstName: {
|
|
156
|
+
type: 'null'
|
|
157
157
|
}
|
|
158
158
|
}
|
|
159
159
|
}, {
|
|
@@ -161,13 +161,13 @@ buildTest({
|
|
|
161
161
|
})
|
|
162
162
|
|
|
163
163
|
buildTest({
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
164
|
+
title: 'array with objects',
|
|
165
|
+
type: 'array',
|
|
166
|
+
items: {
|
|
167
|
+
type: 'object',
|
|
168
|
+
properties: {
|
|
169
|
+
name: {
|
|
170
|
+
type: 'string'
|
|
171
171
|
}
|
|
172
172
|
}
|
|
173
173
|
}
|
|
@@ -178,10 +178,10 @@ buildTest({
|
|
|
178
178
|
}])
|
|
179
179
|
|
|
180
180
|
buildTest({
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
181
|
+
title: 'array with strings',
|
|
182
|
+
type: 'array',
|
|
183
|
+
items: {
|
|
184
|
+
type: 'string'
|
|
185
185
|
}
|
|
186
186
|
}, [
|
|
187
187
|
'Matteo',
|
|
@@ -189,10 +189,10 @@ buildTest({
|
|
|
189
189
|
])
|
|
190
190
|
|
|
191
191
|
buildTest({
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
192
|
+
title: 'array with numbers',
|
|
193
|
+
type: 'array',
|
|
194
|
+
items: {
|
|
195
|
+
type: 'number'
|
|
196
196
|
}
|
|
197
197
|
}, [
|
|
198
198
|
42.42,
|
|
@@ -200,10 +200,10 @@ buildTest({
|
|
|
200
200
|
])
|
|
201
201
|
|
|
202
202
|
buildTest({
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
203
|
+
title: 'array with integers',
|
|
204
|
+
type: 'array',
|
|
205
|
+
items: {
|
|
206
|
+
type: 'number'
|
|
207
207
|
}
|
|
208
208
|
}, [
|
|
209
209
|
42,
|
|
@@ -211,16 +211,16 @@ buildTest({
|
|
|
211
211
|
])
|
|
212
212
|
|
|
213
213
|
buildTest({
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
214
|
+
title: 'nested array with objects',
|
|
215
|
+
type: 'object',
|
|
216
|
+
properties: {
|
|
217
|
+
data: {
|
|
218
|
+
type: 'array',
|
|
219
|
+
items: {
|
|
220
|
+
type: 'object',
|
|
221
|
+
properties: {
|
|
222
|
+
name: {
|
|
223
|
+
type: 'string'
|
|
224
224
|
}
|
|
225
225
|
}
|
|
226
226
|
}
|
|
@@ -235,11 +235,11 @@ buildTest({
|
|
|
235
235
|
})
|
|
236
236
|
|
|
237
237
|
buildTest({
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
238
|
+
title: 'object with boolean',
|
|
239
|
+
type: 'object',
|
|
240
|
+
properties: {
|
|
241
|
+
readonly: {
|
|
242
|
+
type: 'boolean'
|
|
243
243
|
}
|
|
244
244
|
}
|
|
245
245
|
}, {
|
|
@@ -248,14 +248,14 @@ buildTest({
|
|
|
248
248
|
|
|
249
249
|
test('skip or coerce numbers and integers that are not numbers', (t) => {
|
|
250
250
|
const stringify = build({
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
251
|
+
title: 'basic',
|
|
252
|
+
type: 'object',
|
|
253
|
+
properties: {
|
|
254
|
+
age: {
|
|
255
|
+
type: 'number'
|
|
256
256
|
},
|
|
257
|
-
|
|
258
|
-
|
|
257
|
+
distance: {
|
|
258
|
+
type: 'integer'
|
|
259
259
|
}
|
|
260
260
|
}
|
|
261
261
|
})
|
package/test/defaults.test.js
CHANGED
|
@@ -19,26 +19,26 @@ function buildTest (schema, toStringify, expected) {
|
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
buildTest({
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
22
|
+
title: 'default string',
|
|
23
|
+
type: 'object',
|
|
24
|
+
properties: {
|
|
25
|
+
firstName: {
|
|
26
|
+
type: 'string'
|
|
27
27
|
},
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
lastName: {
|
|
29
|
+
type: 'string',
|
|
30
30
|
default: 'Collina'
|
|
31
31
|
},
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
32
|
+
age: {
|
|
33
|
+
description: 'Age in years',
|
|
34
|
+
type: 'integer',
|
|
35
|
+
minimum: 0
|
|
36
36
|
},
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
magic: {
|
|
38
|
+
type: 'number'
|
|
39
39
|
}
|
|
40
40
|
},
|
|
41
|
-
|
|
41
|
+
required: ['firstName', 'lastName']
|
|
42
42
|
}, {
|
|
43
43
|
firstName: 'Matteo',
|
|
44
44
|
magic: 42,
|
|
@@ -51,26 +51,26 @@ buildTest({
|
|
|
51
51
|
})
|
|
52
52
|
|
|
53
53
|
buildTest({
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
54
|
+
title: 'default string with value',
|
|
55
|
+
type: 'object',
|
|
56
|
+
properties: {
|
|
57
|
+
firstName: {
|
|
58
|
+
type: 'string'
|
|
59
59
|
},
|
|
60
|
-
|
|
61
|
-
|
|
60
|
+
lastName: {
|
|
61
|
+
type: 'string',
|
|
62
62
|
default: 'Collina'
|
|
63
63
|
},
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
64
|
+
age: {
|
|
65
|
+
description: 'Age in years',
|
|
66
|
+
type: 'integer',
|
|
67
|
+
minimum: 0
|
|
68
68
|
},
|
|
69
|
-
|
|
70
|
-
|
|
69
|
+
magic: {
|
|
70
|
+
type: 'number'
|
|
71
71
|
}
|
|
72
72
|
},
|
|
73
|
-
|
|
73
|
+
required: ['firstName', 'lastName']
|
|
74
74
|
}, {
|
|
75
75
|
firstName: 'Matteo',
|
|
76
76
|
lastName: 'collina',
|
|
@@ -84,26 +84,26 @@ buildTest({
|
|
|
84
84
|
})
|
|
85
85
|
|
|
86
86
|
buildTest({
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
87
|
+
title: 'default number',
|
|
88
|
+
type: 'object',
|
|
89
|
+
properties: {
|
|
90
|
+
firstName: {
|
|
91
|
+
type: 'string'
|
|
92
92
|
},
|
|
93
|
-
|
|
94
|
-
|
|
93
|
+
lastName: {
|
|
94
|
+
type: 'string'
|
|
95
95
|
},
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
96
|
+
age: {
|
|
97
|
+
description: 'Age in years',
|
|
98
|
+
type: 'integer',
|
|
99
|
+
minimum: 0
|
|
100
100
|
},
|
|
101
|
-
|
|
102
|
-
|
|
101
|
+
magic: {
|
|
102
|
+
type: 'number',
|
|
103
103
|
default: 42
|
|
104
104
|
}
|
|
105
105
|
},
|
|
106
|
-
|
|
106
|
+
required: ['firstName', 'lastName']
|
|
107
107
|
}, {
|
|
108
108
|
firstName: 'Matteo',
|
|
109
109
|
lastName: 'Collina',
|
|
@@ -116,26 +116,26 @@ buildTest({
|
|
|
116
116
|
})
|
|
117
117
|
|
|
118
118
|
buildTest({
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
119
|
+
title: 'default number with value',
|
|
120
|
+
type: 'object',
|
|
121
|
+
properties: {
|
|
122
|
+
firstName: {
|
|
123
|
+
type: 'string'
|
|
124
124
|
},
|
|
125
|
-
|
|
126
|
-
|
|
125
|
+
lastName: {
|
|
126
|
+
type: 'string'
|
|
127
127
|
},
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
128
|
+
age: {
|
|
129
|
+
description: 'Age in years',
|
|
130
|
+
type: 'integer',
|
|
131
|
+
minimum: 0
|
|
132
132
|
},
|
|
133
|
-
|
|
134
|
-
|
|
133
|
+
magic: {
|
|
134
|
+
type: 'number',
|
|
135
135
|
default: 42
|
|
136
136
|
}
|
|
137
137
|
},
|
|
138
|
-
|
|
138
|
+
required: ['firstName', 'lastName']
|
|
139
139
|
}, {
|
|
140
140
|
firstName: 'Matteo',
|
|
141
141
|
lastName: 'Collina',
|
|
@@ -149,26 +149,26 @@ buildTest({
|
|
|
149
149
|
})
|
|
150
150
|
|
|
151
151
|
buildTest({
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
152
|
+
title: 'default object',
|
|
153
|
+
type: 'object',
|
|
154
|
+
properties: {
|
|
155
|
+
firstName: {
|
|
156
|
+
type: 'string'
|
|
157
157
|
},
|
|
158
|
-
|
|
159
|
-
|
|
158
|
+
lastName: {
|
|
159
|
+
type: 'string'
|
|
160
160
|
},
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
161
|
+
age: {
|
|
162
|
+
description: 'Age in years',
|
|
163
|
+
type: 'integer',
|
|
164
|
+
minimum: 0
|
|
165
165
|
},
|
|
166
|
-
|
|
167
|
-
|
|
166
|
+
otherProps: {
|
|
167
|
+
type: 'object',
|
|
168
168
|
default: { foo: 'bar' }
|
|
169
169
|
}
|
|
170
170
|
},
|
|
171
|
-
|
|
171
|
+
required: ['firstName', 'lastName']
|
|
172
172
|
}, {
|
|
173
173
|
firstName: 'Matteo',
|
|
174
174
|
lastName: 'Collina',
|
|
@@ -181,27 +181,27 @@ buildTest({
|
|
|
181
181
|
})
|
|
182
182
|
|
|
183
183
|
buildTest({
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
184
|
+
title: 'default object with value',
|
|
185
|
+
type: 'object',
|
|
186
|
+
properties: {
|
|
187
|
+
firstName: {
|
|
188
|
+
type: 'string'
|
|
189
189
|
},
|
|
190
|
-
|
|
191
|
-
|
|
190
|
+
lastName: {
|
|
191
|
+
type: 'string'
|
|
192
192
|
},
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
193
|
+
age: {
|
|
194
|
+
description: 'Age in years',
|
|
195
|
+
type: 'integer',
|
|
196
|
+
minimum: 0
|
|
197
197
|
},
|
|
198
|
-
|
|
199
|
-
|
|
198
|
+
otherProps: {
|
|
199
|
+
type: 'object',
|
|
200
200
|
additionalProperties: true,
|
|
201
201
|
default: { foo: 'bar' }
|
|
202
202
|
}
|
|
203
203
|
},
|
|
204
|
-
|
|
204
|
+
required: ['firstName', 'lastName']
|
|
205
205
|
}, {
|
|
206
206
|
firstName: 'Matteo',
|
|
207
207
|
lastName: 'Collina',
|
|
@@ -215,27 +215,27 @@ buildTest({
|
|
|
215
215
|
})
|
|
216
216
|
|
|
217
217
|
buildTest({
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
218
|
+
title: 'default array',
|
|
219
|
+
type: 'object',
|
|
220
|
+
properties: {
|
|
221
|
+
firstName: {
|
|
222
|
+
type: 'string'
|
|
223
223
|
},
|
|
224
|
-
|
|
225
|
-
|
|
224
|
+
lastName: {
|
|
225
|
+
type: 'string'
|
|
226
226
|
},
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
227
|
+
age: {
|
|
228
|
+
description: 'Age in years',
|
|
229
|
+
type: 'integer',
|
|
230
|
+
minimum: 0
|
|
231
231
|
},
|
|
232
|
-
|
|
233
|
-
|
|
232
|
+
otherProps: {
|
|
233
|
+
type: 'array',
|
|
234
234
|
items: { type: 'string' },
|
|
235
235
|
default: ['FOO']
|
|
236
236
|
}
|
|
237
237
|
},
|
|
238
|
-
|
|
238
|
+
required: ['firstName', 'lastName']
|
|
239
239
|
}, {
|
|
240
240
|
firstName: 'Matteo',
|
|
241
241
|
lastName: 'Collina',
|
|
@@ -248,27 +248,27 @@ buildTest({
|
|
|
248
248
|
})
|
|
249
249
|
|
|
250
250
|
buildTest({
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
251
|
+
title: 'default array with value',
|
|
252
|
+
type: 'object',
|
|
253
|
+
properties: {
|
|
254
|
+
firstName: {
|
|
255
|
+
type: 'string'
|
|
256
256
|
},
|
|
257
|
-
|
|
258
|
-
|
|
257
|
+
lastName: {
|
|
258
|
+
type: 'string'
|
|
259
259
|
},
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
260
|
+
age: {
|
|
261
|
+
description: 'Age in years',
|
|
262
|
+
type: 'integer',
|
|
263
|
+
minimum: 0
|
|
264
264
|
},
|
|
265
|
-
|
|
266
|
-
|
|
265
|
+
otherProps: {
|
|
266
|
+
type: 'array',
|
|
267
267
|
items: { type: 'string' },
|
|
268
268
|
default: ['FOO']
|
|
269
269
|
}
|
|
270
270
|
},
|
|
271
|
-
|
|
271
|
+
required: ['firstName', 'lastName']
|
|
272
272
|
}, {
|
|
273
273
|
firstName: 'Matteo',
|
|
274
274
|
lastName: 'Collina',
|
|
@@ -282,21 +282,21 @@ buildTest({
|
|
|
282
282
|
})
|
|
283
283
|
|
|
284
284
|
buildTest({
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
285
|
+
title: 'default deeper value',
|
|
286
|
+
type: 'object',
|
|
287
|
+
properties: {
|
|
288
|
+
level1: {
|
|
289
|
+
type: 'object',
|
|
290
|
+
properties: {
|
|
291
|
+
level2: {
|
|
292
|
+
type: 'object',
|
|
293
|
+
properties: {
|
|
294
|
+
level3: {
|
|
295
|
+
type: 'object',
|
|
296
|
+
properties: {
|
|
297
|
+
level4: {
|
|
298
|
+
type: 'object',
|
|
299
|
+
default: { foo: 'bar' }
|
|
300
300
|
}
|
|
301
301
|
}
|
|
302
302
|
}
|
|
@@ -312,21 +312,21 @@ buildTest({
|
|
|
312
312
|
})
|
|
313
313
|
|
|
314
314
|
buildTest({
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
315
|
+
title: 'default deeper value with value',
|
|
316
|
+
type: 'object',
|
|
317
|
+
properties: {
|
|
318
|
+
level1: {
|
|
319
|
+
type: 'object',
|
|
320
|
+
properties: {
|
|
321
|
+
level2: {
|
|
322
|
+
type: 'object',
|
|
323
|
+
properties: {
|
|
324
|
+
level3: {
|
|
325
|
+
type: 'object',
|
|
326
|
+
properties: {
|
|
327
|
+
level4: {
|
|
328
|
+
type: 'object',
|
|
329
|
+
default: { foo: 'bar' }
|
|
330
330
|
}
|
|
331
331
|
}
|
|
332
332
|
}
|