fast-json-stringify 5.11.1 → 5.13.0
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/README.md +18 -0
- package/benchmark/bench.js +24 -0
- package/index.js +284 -239
- package/lib/location.js +1 -30
- package/lib/merge-schemas.js +9 -0
- package/lib/serializer.js +8 -20
- package/package.json +3 -3
- package/test/allof.test.js +134 -17
- package/test/anyof.test.js +148 -0
- package/test/basic.test.js +6 -0
- package/test/if-then-else.test.js +58 -9
- package/test/required.test.js +4 -3
- package/test/string.test.js +34 -0
- package/types/index.d.ts +5 -2
- package/types/index.test-d.ts +79 -57
package/types/index.test-d.ts
CHANGED
|
@@ -3,61 +3,62 @@ import build, { restore, Schema, validLargeArrayMechanisms } from '..'
|
|
|
3
3
|
import { expectError, expectType } from 'tsd'
|
|
4
4
|
|
|
5
5
|
// Number schemas
|
|
6
|
-
|
|
6
|
+
build({
|
|
7
7
|
type: 'number'
|
|
8
|
-
}
|
|
9
|
-
|
|
8
|
+
})(25)
|
|
9
|
+
build({
|
|
10
10
|
type: 'integer'
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
})(-5)
|
|
12
|
+
build({
|
|
13
|
+
type: 'integer'
|
|
14
|
+
})(5n)
|
|
15
15
|
|
|
16
|
-
build(
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
build(
|
|
20
|
-
|
|
16
|
+
build({
|
|
17
|
+
type: 'number'
|
|
18
|
+
}, { rounding: 'ceil' })
|
|
19
|
+
build({
|
|
20
|
+
type: 'number'
|
|
21
|
+
}, { rounding: 'floor' })
|
|
22
|
+
build({
|
|
23
|
+
type: 'number'
|
|
24
|
+
}, { rounding: 'round' })
|
|
25
|
+
build({
|
|
26
|
+
type: 'number'
|
|
27
|
+
}, { rounding: 'trunc' })
|
|
28
|
+
expectError(build({
|
|
29
|
+
type: 'number'
|
|
30
|
+
}, { rounding: 'invalid' }))
|
|
21
31
|
|
|
22
32
|
// String schema
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
build(schema3)('foobar')
|
|
33
|
+
build({
|
|
34
|
+
type: 'string'
|
|
35
|
+
})('foobar')
|
|
28
36
|
|
|
29
37
|
// Boolean schema
|
|
30
|
-
|
|
38
|
+
build({
|
|
31
39
|
type: 'boolean'
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
build(schema4)(true)
|
|
40
|
+
})(true)
|
|
35
41
|
|
|
36
42
|
// Null schema
|
|
37
|
-
|
|
43
|
+
build({
|
|
38
44
|
type: 'null'
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
build(schema5)(null)
|
|
45
|
+
})(null)
|
|
42
46
|
|
|
43
47
|
// Array schemas
|
|
44
|
-
|
|
48
|
+
build({
|
|
45
49
|
type: 'array',
|
|
46
50
|
items: { type: 'number' }
|
|
47
|
-
}
|
|
48
|
-
|
|
51
|
+
})([25])
|
|
52
|
+
build({
|
|
49
53
|
type: 'array',
|
|
50
54
|
items: [{ type: 'string'}, {type: 'integer'}]
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
build(schema6)([25])
|
|
54
|
-
build(schema7)(['hello', 42])
|
|
55
|
+
})(['hello', 42])
|
|
55
56
|
|
|
56
57
|
// Object schemas
|
|
57
|
-
|
|
58
|
+
build({
|
|
58
59
|
type: 'object'
|
|
59
|
-
}
|
|
60
|
-
|
|
60
|
+
})({})
|
|
61
|
+
build({
|
|
61
62
|
type: 'object',
|
|
62
63
|
properties: {
|
|
63
64
|
foo: { type: 'string' },
|
|
@@ -70,14 +71,24 @@ const schema9: Schema = {
|
|
|
70
71
|
additionalProperties: {
|
|
71
72
|
type: 'boolean'
|
|
72
73
|
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
74
|
+
})({ foo: 'bar' })
|
|
75
|
+
build({
|
|
76
|
+
type: 'object',
|
|
77
|
+
properties: {
|
|
78
|
+
foo: { type: 'string' },
|
|
79
|
+
bar: { type: 'integer' }
|
|
80
|
+
},
|
|
81
|
+
required: ['foo'],
|
|
82
|
+
patternProperties: {
|
|
83
|
+
'baz*': { type: 'null' }
|
|
84
|
+
},
|
|
85
|
+
additionalProperties: {
|
|
86
|
+
type: 'boolean'
|
|
87
|
+
}
|
|
88
|
+
}, { rounding: 'floor' })({ foo: 'bar' })
|
|
78
89
|
|
|
79
90
|
// Reference schemas
|
|
80
|
-
|
|
91
|
+
build({
|
|
81
92
|
title: 'Example Schema',
|
|
82
93
|
definitions: {
|
|
83
94
|
num: {
|
|
@@ -109,12 +120,10 @@ const schema10: Schema = {
|
|
|
109
120
|
additionalProperties: {
|
|
110
121
|
$ref: '#/definitions/def'
|
|
111
122
|
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
build(schema10)({ nickname: '', num: { int: 5 }, other: null })
|
|
123
|
+
})({ nickname: '', num: { int: 5 }, other: null })
|
|
115
124
|
|
|
116
125
|
// Conditional/Combined schemas
|
|
117
|
-
|
|
126
|
+
build({
|
|
118
127
|
title: 'Conditional/Combined Schema',
|
|
119
128
|
type: 'object',
|
|
120
129
|
properties: {
|
|
@@ -140,24 +149,37 @@ const schema11: Schema = {
|
|
|
140
149
|
somethingElse: { type: 'null' }
|
|
141
150
|
}
|
|
142
151
|
}
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
build(schema11)({ something: 'a string', somethingElse: 42 })
|
|
152
|
+
})({ something: 'a string', somethingElse: 42 })
|
|
146
153
|
|
|
147
154
|
// String schema with format
|
|
148
|
-
|
|
155
|
+
|
|
156
|
+
build({
|
|
149
157
|
type: 'string',
|
|
150
158
|
format: 'date-time'
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
build(schema12)(new Date())
|
|
159
|
+
})(new Date())
|
|
154
160
|
|
|
161
|
+
/*
|
|
162
|
+
This overload doesn't work yet -
|
|
163
|
+
TypeScript chooses the generic for the schema
|
|
164
|
+
before it chooses the overload for the options
|
|
165
|
+
parameter.
|
|
155
166
|
let str: string, ajv: Ajv
|
|
156
|
-
str = build(
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
ajv = build(
|
|
160
|
-
|
|
167
|
+
str = build({
|
|
168
|
+
type: 'number'
|
|
169
|
+
}, { debugMode: true }).code
|
|
170
|
+
ajv = build({
|
|
171
|
+
type: 'number'
|
|
172
|
+
}, { debugMode: true }).ajv
|
|
173
|
+
str = build({
|
|
174
|
+
type: 'number'
|
|
175
|
+
}, { mode: 'debug' }).code
|
|
176
|
+
ajv = build({
|
|
177
|
+
type: 'number'
|
|
178
|
+
}, { mode: 'debug' }).ajv
|
|
179
|
+
str = build({
|
|
180
|
+
type: 'number'
|
|
181
|
+
}, { mode: 'standalone' })
|
|
182
|
+
*/
|
|
161
183
|
|
|
162
184
|
const debugCompiled = build({
|
|
163
185
|
title: 'default string',
|