fast-json-stringify 3.2.0 → 4.0.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/.github/workflows/ci.yml +3 -33
- package/README.md +6 -8
- package/benchmark/bench-cmp-branch.js +114 -0
- package/{bench.js → benchmark/bench-cmp-lib.js} +4 -4
- package/benchmark/bench-thread.js +21 -0
- package/benchmark/bench.js +251 -0
- package/example.js +0 -3
- package/index.js +476 -596
- package/package.json +10 -4
- package/test/additionalProperties.test.js +23 -19
- package/test/allof.test.js +56 -0
- package/test/anyof.test.js +88 -9
- package/test/array.test.js +81 -23
- package/test/basic.test.js +8 -8
- package/test/date.test.js +62 -35
- package/test/debug-mode.test.js +1 -1
- package/test/nestedObjects.test.js +31 -0
- package/test/nullable.test.js +328 -0
- package/test/oneof.test.js +9 -22
- package/test/patternProperties.test.js +17 -6
- package/test/required.test.js +1 -1
- package/test/sanitize3.test.js +9 -11
- package/test/typesArray.test.js +40 -3
package/test/required.test.js
CHANGED
package/test/sanitize3.test.js
CHANGED
|
@@ -3,15 +3,13 @@
|
|
|
3
3
|
const t = require('tap')
|
|
4
4
|
const build = require('..')
|
|
5
5
|
|
|
6
|
-
const stringify = build({
|
|
7
|
-
$defs: {
|
|
8
|
-
type: 'foooo"bar'
|
|
9
|
-
},
|
|
10
|
-
patternProperties: {
|
|
11
|
-
x: { $ref: '#/$defs' }
|
|
12
|
-
}
|
|
13
|
-
})
|
|
14
|
-
|
|
15
6
|
t.throws(() => {
|
|
16
|
-
|
|
17
|
-
|
|
7
|
+
build({
|
|
8
|
+
$defs: {
|
|
9
|
+
type: 'foooo"bar'
|
|
10
|
+
},
|
|
11
|
+
patternProperties: {
|
|
12
|
+
x: { $ref: '#/$defs' }
|
|
13
|
+
}
|
|
14
|
+
})
|
|
15
|
+
}, 'foooo"bar unsupported')
|
package/test/typesArray.test.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
const test = require('tap').test
|
|
4
|
-
const moment = require('moment')
|
|
5
4
|
const build = require('..')
|
|
6
5
|
|
|
7
6
|
test('possibly nullable integer primitive alternative', (t) => {
|
|
@@ -88,6 +87,27 @@ test('possibly nullable number primitive alternative with null value', (t) => {
|
|
|
88
87
|
t.equal(value, '{"data":0}')
|
|
89
88
|
})
|
|
90
89
|
|
|
90
|
+
test('possibly nullable number primitive alternative with null value', (t) => {
|
|
91
|
+
t.plan(1)
|
|
92
|
+
|
|
93
|
+
const schema = {
|
|
94
|
+
title: 'simple object with multi-type nullable primitive',
|
|
95
|
+
type: 'object',
|
|
96
|
+
properties: {
|
|
97
|
+
data: {
|
|
98
|
+
type: ['boolean']
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const stringify = build(schema)
|
|
104
|
+
|
|
105
|
+
const value = stringify({
|
|
106
|
+
data: null
|
|
107
|
+
})
|
|
108
|
+
t.equal(value, '{"data":false}')
|
|
109
|
+
})
|
|
110
|
+
|
|
91
111
|
test('nullable integer primitive', (t) => {
|
|
92
112
|
t.plan(1)
|
|
93
113
|
|
|
@@ -361,7 +381,7 @@ test('string type array can handle dates', (t) => {
|
|
|
361
381
|
const stringify = build(schema)
|
|
362
382
|
const value = stringify({
|
|
363
383
|
date: new Date('2018-04-20T07:52:31.017Z'),
|
|
364
|
-
dateObject:
|
|
384
|
+
dateObject: new Date('2018-04-21T07:52:31.017Z')
|
|
365
385
|
})
|
|
366
386
|
t.equal(value, '{"date":"2018-04-20T07:52:31.017Z","dateObject":"2018-04-21T07:52:31.017Z"}')
|
|
367
387
|
})
|
|
@@ -433,5 +453,22 @@ test('should throw an error when type is array and object is null', (t) => {
|
|
|
433
453
|
}
|
|
434
454
|
|
|
435
455
|
const stringify = build(schema)
|
|
436
|
-
t.throws(() => stringify({ arr: null }), new TypeError('
|
|
456
|
+
t.throws(() => stringify({ arr: null }), new TypeError('The value \'null\' does not match schema definition.'))
|
|
457
|
+
})
|
|
458
|
+
|
|
459
|
+
test('throw an error if none of types matches', (t) => {
|
|
460
|
+
t.plan(1)
|
|
461
|
+
|
|
462
|
+
const schema = {
|
|
463
|
+
title: 'simple object with multi-type nullable primitive',
|
|
464
|
+
type: 'object',
|
|
465
|
+
properties: {
|
|
466
|
+
data: {
|
|
467
|
+
type: ['number', 'boolean']
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
const stringify = build(schema)
|
|
473
|
+
t.throws(() => stringify({ data: 'string' }), 'The value "string" does not match schema definition.')
|
|
437
474
|
})
|