fast-json-stringify 5.16.1 → 6.0.1
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/dependabot.yml +1 -1
- package/.github/workflows/benchmark.yml +3 -3
- package/.github/workflows/ci.yml +1 -1
- package/README.md +15 -15
- package/benchmark/bench-cmp-lib.js +0 -1
- package/eslint.config.js +9 -0
- package/index.js +4 -8
- package/lib/serializer.js +1 -2
- package/lib/validator.js +1 -1
- package/package.json +47 -23
- package/test/additionalProperties.test.js +20 -20
- package/test/allof.test.js +36 -40
- package/test/any.test.js +28 -28
- package/test/anyof.test.js +44 -46
- package/test/array.test.js +19 -19
- package/test/asNumber.test.js +2 -2
- package/test/basic.test.js +20 -32
- package/test/bigint.test.js +6 -6
- package/test/clean-cache.test.js +9 -7
- package/test/const.test.js +35 -35
- package/test/date.test.js +77 -77
- package/test/debug-mode.test.js +27 -27
- package/test/defaults.test.js +2 -2
- package/test/enum.test.js +3 -3
- package/test/fix-604.test.js +18 -17
- package/test/if-then-else.test.js +22 -24
- package/test/inferType.test.js +4 -4
- package/test/infinity.test.js +4 -4
- package/test/integer.test.js +21 -21
- package/test/invalidSchema.test.js +4 -8
- package/test/issue-479.test.js +2 -2
- package/test/json-schema-test-suite/draft4.test.js +3 -3
- package/test/json-schema-test-suite/draft6.test.js +3 -3
- package/test/json-schema-test-suite/draft7.test.js +3 -3
- package/test/json-schema-test-suite/util.js +6 -9
- package/test/missing-values.test.js +8 -8
- package/test/multi-type-serializer.test.js +2 -2
- package/test/nestedObjects.test.js +3 -3
- package/test/nullable.test.js +35 -35
- package/test/oneof.test.js +27 -29
- package/test/patternProperties.test.js +11 -11
- package/test/recursion.test.js +6 -6
- package/test/ref.test.js +102 -186
- package/test/regex.test.js +4 -5
- package/test/required.test.js +42 -77
- package/test/requiresAjv.test.js +34 -32
- package/test/sanitize.test.js +40 -41
- package/test/sanitize2.test.js +11 -11
- package/test/sanitize3.test.js +13 -11
- package/test/sanitize4.test.js +10 -8
- package/test/sanitize5.test.js +11 -11
- package/test/sanitize6.test.js +14 -14
- package/test/sanitize7.test.js +5 -5
- package/test/side-effect.test.js +12 -12
- package/test/standalone-mode.test.js +29 -26
- package/test/string.test.js +12 -12
- package/test/surrogate.test.js +9 -9
- package/test/toJSON.test.js +9 -9
- package/test/typebox.test.js +2 -2
- package/test/typesArray.test.js +34 -34
- package/test/unknownFormats.test.js +5 -5
- package/test/webpack.test.js +2 -2
- package/types/index.d.ts +29 -29
- package/types/index.test-d.ts +75 -74
- package/.taprc +0 -14
package/.github/dependabot.yml
CHANGED
|
@@ -65,9 +65,9 @@ jobs:
|
|
|
65
65
|
pull-requests: write
|
|
66
66
|
steps:
|
|
67
67
|
- name: Comment PR
|
|
68
|
-
uses: thollander/actions-comment-pull-request@
|
|
68
|
+
uses: thollander/actions-comment-pull-request@v3
|
|
69
69
|
with:
|
|
70
|
-
|
|
70
|
+
github-token: ${{ secrets.GITHUB_TOKEN }}
|
|
71
71
|
message: |
|
|
72
72
|
**PR**:
|
|
73
73
|
```
|
|
@@ -77,7 +77,7 @@ jobs:
|
|
|
77
77
|
```
|
|
78
78
|
${{ needs.benchmark.outputs.MASTER-BENCH }}
|
|
79
79
|
```
|
|
80
|
-
|
|
80
|
+
|
|
81
81
|
- uses: actions-ecosystem/action-remove-labels@v1
|
|
82
82
|
with:
|
|
83
83
|
labels: |
|
package/.github/workflows/ci.yml
CHANGED
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# fast-json-stringify
|
|
2
2
|
|
|
3
|
-
](https://github.com/fastify/fast-json-stringify/actions/workflows/ci.yml)
|
|
4
4
|
[](https://www.npmjs.com/package/fast-json-stringify)
|
|
5
|
-
[](https://github.com/neostandard/neostandard)
|
|
6
6
|
[](https://www.npmjs.com/package/fast-json-stringify)
|
|
7
7
|
|
|
8
8
|
|
|
@@ -70,7 +70,7 @@ compile-json-stringify date format x 1,125,735 ops/sec ±0.19% (98 runs sampled)
|
|
|
70
70
|
- <a href="#security">`Security Notice`</a>
|
|
71
71
|
- <a href="#debug">`Debug Mode`</a>
|
|
72
72
|
- <a href="#standalone">`Standalone Mode`</a>
|
|
73
|
-
- <a href="#
|
|
73
|
+
- <a href="#acknowledgments">`Acknowledgments`</a>
|
|
74
74
|
- <a href="#license">`License`</a>
|
|
75
75
|
|
|
76
76
|
|
|
@@ -111,7 +111,7 @@ console.log(stringify({
|
|
|
111
111
|
<a name="options"></a>
|
|
112
112
|
## Options
|
|
113
113
|
|
|
114
|
-
Optionally, you may provide to `fast-json-stringify` an option object as second parameter:
|
|
114
|
+
Optionally, you may provide to `fast-json-stringify` an option object as the second parameter:
|
|
115
115
|
|
|
116
116
|
```js
|
|
117
117
|
const fastJson = require('fast-json-stringify')
|
|
@@ -165,7 +165,7 @@ And nested ones, too.
|
|
|
165
165
|
| `date` | `2020-04-03` |
|
|
166
166
|
| `time` | `09:11:08` |
|
|
167
167
|
|
|
168
|
-
**Note**: In the case of string formatted Date and not Date Object, there will be no manipulation on it. It should be properly formatted.
|
|
168
|
+
**Note**: In the case of a string formatted Date and not Date Object, there will be no manipulation on it. It should be properly formatted.
|
|
169
169
|
|
|
170
170
|
Example with a Date object:
|
|
171
171
|
|
|
@@ -290,7 +290,7 @@ console.log(stringify(obj)) // '{"matchfoo":"42","otherfoo":"str","matchnum":3,"
|
|
|
290
290
|
*additionalProperties* must be an object or a boolean, declared in this way: `{ type: 'type' }`.
|
|
291
291
|
*additionalProperties* will work only for the properties that are not explicitly listed in the *properties* and *patternProperties* objects.
|
|
292
292
|
|
|
293
|
-
If *additionalProperties* is not present or is set to `false`, every property that is not explicitly listed in the *properties* and *patternProperties* objects
|
|
293
|
+
If *additionalProperties* is not present or is set to `false`, every property that is not explicitly listed in the *properties* and *patternProperties* objects will be ignored, as described in <a href="#missingFields">Missing fields</a>.
|
|
294
294
|
Missing fields are ignored to avoid having to rewrite objects before serializing. However, other schema rules would throw in similar situations.
|
|
295
295
|
If *additionalProperties* is set to `true`, it will be used by `JSON.stringify` to stringify the additional properties. If you want to achieve maximum performance, we strongly encourage you to use a fixed schema where possible.
|
|
296
296
|
The additional properties will always be serialized at the end of the object.
|
|
@@ -543,12 +543,12 @@ const stringify = fastJson(schema, { schema: externalSchema })
|
|
|
543
543
|
|
|
544
544
|
<a name="long"></a>
|
|
545
545
|
#### Long integers
|
|
546
|
-
By default the library will handle automatically [BigInt](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt).
|
|
546
|
+
By default, the library will handle automatically [BigInt](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt).
|
|
547
547
|
|
|
548
548
|
<a name="integer"></a>
|
|
549
549
|
#### Integers
|
|
550
550
|
The `type: integer` property will be truncated if a floating point is provided.
|
|
551
|
-
You can customize this
|
|
551
|
+
You can customize this behavior with the `rounding` option that will accept [`round`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/round), [`ceil`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/ceil), [`floor`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/floor), or [`trunc`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/trunc). Default is `trunc`:
|
|
552
552
|
|
|
553
553
|
```js
|
|
554
554
|
const stringify = fastJson(schema, { rounding: 'ceil' })
|
|
@@ -650,8 +650,8 @@ const stringify = fastJson({
|
|
|
650
650
|
|
|
651
651
|
##### Benchmarks
|
|
652
652
|
|
|
653
|
-
For reference, here
|
|
654
|
-
mechanisms. Benchmarks conducted on an old machine.
|
|
653
|
+
For reference, here are some benchmarks for comparison over the three
|
|
654
|
+
mechanisms. Benchmarks were conducted on an old machine.
|
|
655
655
|
|
|
656
656
|
- Machine: `ST1000LM024 HN-M 1TB HDD, Intel Core i7-3610QM @ 2.3GHz, 12GB RAM, 4C/8T`.
|
|
657
657
|
- Node.js `v16.13.1`
|
|
@@ -678,7 +678,7 @@ expose your application to remote attacks.
|
|
|
678
678
|
|
|
679
679
|
Users are responsible for sending trusted data. `fast-json-stringify` guarantees that you will get
|
|
680
680
|
a valid output only if your input matches the schema or can be coerced to the schema. If your input
|
|
681
|
-
doesn't match the schema, you will get undefined behavior.
|
|
681
|
+
doesn't match the schema, you will get undefined behavior.
|
|
682
682
|
|
|
683
683
|
<a name="debug"></a>
|
|
684
684
|
### Debug Mode
|
|
@@ -699,7 +699,7 @@ const debugCompiled = fastJson({
|
|
|
699
699
|
|
|
700
700
|
console.log(debugCompiled) // it is a object contain code, ajv instance
|
|
701
701
|
const rawString = debugCompiled.code // it is the generated code
|
|
702
|
-
console.log(rawString)
|
|
702
|
+
console.log(rawString)
|
|
703
703
|
|
|
704
704
|
const stringify = fastJson.restore(debugCompiled) // use the generated string to get back the `stringify` function
|
|
705
705
|
console.log(stringify({ firstName: 'Foo', surname: 'bar' })) // '{"firstName":"Foo"}'
|
|
@@ -728,12 +728,12 @@ const stringify = require('stringify.js')
|
|
|
728
728
|
console.log(stringify({ firstName: 'Foo', surname: 'bar' })) // '{"firstName":"Foo"}'
|
|
729
729
|
```
|
|
730
730
|
|
|
731
|
-
<a name="
|
|
732
|
-
##
|
|
731
|
+
<a name="acknowledgments"></a>
|
|
732
|
+
## Acknowledgments
|
|
733
733
|
|
|
734
734
|
This project was kindly sponsored by [nearForm](https://nearform.com).
|
|
735
735
|
|
|
736
736
|
<a name="license"></a>
|
|
737
737
|
## License
|
|
738
738
|
|
|
739
|
-
MIT
|
|
739
|
+
Licensed under [MIT](./LICENSE).
|
package/eslint.config.js
ADDED
package/index.js
CHANGED
|
@@ -252,20 +252,16 @@ const numberKeywords = [
|
|
|
252
252
|
* https://datatracker.ietf.org/doc/html/draft-handrews-json-schema-validation-01#section-6
|
|
253
253
|
*/
|
|
254
254
|
function inferTypeByKeyword (schema) {
|
|
255
|
-
|
|
256
|
-
for (var keyword of objectKeywords) {
|
|
255
|
+
for (const keyword of objectKeywords) {
|
|
257
256
|
if (keyword in schema) return 'object'
|
|
258
257
|
}
|
|
259
|
-
|
|
260
|
-
for (var keyword of arrayKeywords) {
|
|
258
|
+
for (const keyword of arrayKeywords) {
|
|
261
259
|
if (keyword in schema) return 'array'
|
|
262
260
|
}
|
|
263
|
-
|
|
264
|
-
for (var keyword of stringKeywords) {
|
|
261
|
+
for (const keyword of stringKeywords) {
|
|
265
262
|
if (keyword in schema) return 'string'
|
|
266
263
|
}
|
|
267
|
-
|
|
268
|
-
for (var keyword of numberKeywords) {
|
|
264
|
+
for (const keyword of numberKeywords) {
|
|
269
265
|
if (keyword in schema) return 'number'
|
|
270
266
|
}
|
|
271
267
|
return schema.type
|
package/lib/serializer.js
CHANGED
|
@@ -102,8 +102,7 @@ module.exports = class Serializer {
|
|
|
102
102
|
let result = ''
|
|
103
103
|
let last = -1
|
|
104
104
|
let point = 255
|
|
105
|
-
|
|
106
|
-
for (var i = 0; i < len; i++) {
|
|
105
|
+
for (let i = 0; i < len; i++) {
|
|
107
106
|
point = str.charCodeAt(i)
|
|
108
107
|
if (
|
|
109
108
|
point === 0x22 || // '"'
|
package/lib/validator.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fast-json-stringify",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "6.0.1",
|
|
4
4
|
"description": "Stringify your JSON at max speed",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "commonjs",
|
|
@@ -10,10 +10,10 @@
|
|
|
10
10
|
"bench:cmp": "node ./benchmark/bench-cmp-branch.js",
|
|
11
11
|
"bench:cmp:ci": "node ./benchmark/bench-cmp-branch.js --ci",
|
|
12
12
|
"benchmark": "node ./benchmark/bench-cmp-lib.js",
|
|
13
|
-
"lint": "
|
|
14
|
-
"lint:fix": "
|
|
13
|
+
"lint": "eslint",
|
|
14
|
+
"lint:fix": "eslint --fix",
|
|
15
15
|
"test:typescript": "tsd",
|
|
16
|
-
"test:unit": "
|
|
16
|
+
"test:unit": "c8 node --test",
|
|
17
17
|
"test": "npm run test:unit && npm run test:typescript"
|
|
18
18
|
},
|
|
19
19
|
"precommit": [
|
|
@@ -31,38 +31,62 @@
|
|
|
31
31
|
"fast"
|
|
32
32
|
],
|
|
33
33
|
"author": "Matteo Collina <hello@matteocollina.com>",
|
|
34
|
+
"contributors": [
|
|
35
|
+
{
|
|
36
|
+
"name": "Tomas Della Vedova",
|
|
37
|
+
"url": "http://delved.org"
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
"name": "Aras Abbasi",
|
|
41
|
+
"email": "aras.abbasi@gmail.com"
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
"name": "Manuel Spigolon",
|
|
45
|
+
"email": "behemoth89@gmail.com"
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
"name": "Frazer Smith",
|
|
49
|
+
"email": "frazer.dev@icloud.com",
|
|
50
|
+
"url": "https://github.com/fdawgs"
|
|
51
|
+
}
|
|
52
|
+
],
|
|
34
53
|
"license": "MIT",
|
|
35
54
|
"bugs": {
|
|
36
55
|
"url": "https://github.com/fastify/fast-json-stringify/issues"
|
|
37
56
|
},
|
|
38
57
|
"homepage": "https://github.com/fastify/fast-json-stringify#readme",
|
|
58
|
+
"funding": [
|
|
59
|
+
{
|
|
60
|
+
"type": "github",
|
|
61
|
+
"url": "https://github.com/sponsors/fastify"
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
"type": "opencollective",
|
|
65
|
+
"url": "https://opencollective.com/fastify"
|
|
66
|
+
}
|
|
67
|
+
],
|
|
39
68
|
"devDependencies": {
|
|
40
|
-
"@fastify/pre-commit": "^2.0
|
|
41
|
-
"@sinclair/typebox": "^0.
|
|
69
|
+
"@fastify/pre-commit": "^2.1.0",
|
|
70
|
+
"@sinclair/typebox": "^0.34.3",
|
|
42
71
|
"benchmark": "^2.1.4",
|
|
72
|
+
"c8": "^10.1.2",
|
|
43
73
|
"cli-select": "^1.1.2",
|
|
44
74
|
"compile-json-stringify": "^0.1.2",
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"
|
|
75
|
+
"eslint": "^9.17.0",
|
|
76
|
+
"fast-json-stringify": ".",
|
|
77
|
+
"is-my-json-valid": "^2.20.6",
|
|
78
|
+
"neostandard": "^0.12.0",
|
|
79
|
+
"simple-git": "^3.23.0",
|
|
49
80
|
"tsd": "^0.31.0",
|
|
50
|
-
"webpack": "^5.
|
|
51
|
-
"fast-json-stringify": "."
|
|
81
|
+
"webpack": "^5.90.3"
|
|
52
82
|
},
|
|
53
83
|
"dependencies": {
|
|
54
|
-
"
|
|
84
|
+
"@fastify/merge-json-schemas": "^0.2.0",
|
|
85
|
+
"ajv": "^8.12.0",
|
|
55
86
|
"ajv-formats": "^3.0.1",
|
|
56
|
-
"fast-
|
|
57
|
-
"
|
|
58
|
-
"rfdc": "^1.2.0"
|
|
59
|
-
"json-schema-ref-resolver": "^1.0.1",
|
|
60
|
-
"@fastify/merge-json-schemas": "^0.1.0"
|
|
61
|
-
},
|
|
62
|
-
"standard": {
|
|
63
|
-
"ignore": [
|
|
64
|
-
"schema-validator.js"
|
|
65
|
-
]
|
|
87
|
+
"fast-uri": "^3.0.0",
|
|
88
|
+
"json-schema-ref-resolver": "^2.0.0",
|
|
89
|
+
"rfdc": "^1.2.0"
|
|
66
90
|
},
|
|
67
91
|
"runkitExampleFilename": "./examples/example.js"
|
|
68
92
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const test = require('
|
|
3
|
+
const { test } = require('node:test')
|
|
4
4
|
const build = require('..')
|
|
5
5
|
|
|
6
6
|
test('additionalProperties', (t) => {
|
|
@@ -19,7 +19,7 @@ test('additionalProperties', (t) => {
|
|
|
19
19
|
})
|
|
20
20
|
|
|
21
21
|
const obj = { str: 'test', foo: 42, ofoo: true, foof: 'string', objfoo: { a: true } }
|
|
22
|
-
t.equal(stringify(obj), '{"str":"test","foo":"42","ofoo":"true","foof":"string","objfoo":"[object Object]"}')
|
|
22
|
+
t.assert.equal(stringify(obj), '{"str":"test","foo":"42","ofoo":"true","foof":"string","objfoo":"[object Object]"}')
|
|
23
23
|
})
|
|
24
24
|
|
|
25
25
|
test('additionalProperties should not change properties', (t) => {
|
|
@@ -38,7 +38,7 @@ test('additionalProperties should not change properties', (t) => {
|
|
|
38
38
|
})
|
|
39
39
|
|
|
40
40
|
const obj = { foo: '42', ofoo: 42 }
|
|
41
|
-
t.equal(stringify(obj), '{"foo":"42","ofoo":42}')
|
|
41
|
+
t.assert.equal(stringify(obj), '{"foo":"42","ofoo":42}')
|
|
42
42
|
})
|
|
43
43
|
|
|
44
44
|
test('additionalProperties should not change properties and patternProperties', (t) => {
|
|
@@ -62,7 +62,7 @@ test('additionalProperties should not change properties and patternProperties',
|
|
|
62
62
|
})
|
|
63
63
|
|
|
64
64
|
const obj = { foo: '42', ofoo: 42, test: '42' }
|
|
65
|
-
t.equal(stringify(obj), '{"foo":"42","ofoo":"42","test":42}')
|
|
65
|
+
t.assert.equal(stringify(obj), '{"foo":"42","ofoo":"42","test":42}')
|
|
66
66
|
})
|
|
67
67
|
|
|
68
68
|
test('additionalProperties set to true, use of fast-safe-stringify', (t) => {
|
|
@@ -75,7 +75,7 @@ test('additionalProperties set to true, use of fast-safe-stringify', (t) => {
|
|
|
75
75
|
})
|
|
76
76
|
|
|
77
77
|
const obj = { foo: true, ofoo: 42, arrfoo: ['array', 'test'], objfoo: { a: 'world' } }
|
|
78
|
-
t.equal(stringify(obj), '{"foo":true,"ofoo":42,"arrfoo":["array","test"],"objfoo":{"a":"world"}}')
|
|
78
|
+
t.assert.equal(stringify(obj), '{"foo":true,"ofoo":42,"arrfoo":["array","test"],"objfoo":{"a":"world"}}')
|
|
79
79
|
})
|
|
80
80
|
|
|
81
81
|
test('additionalProperties - string coerce', (t) => {
|
|
@@ -90,7 +90,7 @@ test('additionalProperties - string coerce', (t) => {
|
|
|
90
90
|
})
|
|
91
91
|
|
|
92
92
|
const obj = { foo: true, ofoo: 42, arrfoo: ['array', 'test'], objfoo: { a: 'world' } }
|
|
93
|
-
t.equal(stringify(obj), '{"foo":"true","ofoo":"42","arrfoo":"array,test","objfoo":"[object Object]"}')
|
|
93
|
+
t.assert.equal(stringify(obj), '{"foo":"true","ofoo":"42","arrfoo":"array,test","objfoo":"[object Object]"}')
|
|
94
94
|
})
|
|
95
95
|
|
|
96
96
|
test('additionalProperties - number skip', (t) => {
|
|
@@ -106,7 +106,7 @@ test('additionalProperties - number skip', (t) => {
|
|
|
106
106
|
|
|
107
107
|
// const obj = { foo: true, ofoo: '42', xfoo: 'string', arrfoo: [1, 2], objfoo: { num: 42 } }
|
|
108
108
|
const obj = { foo: true, ofoo: '42' }
|
|
109
|
-
t.equal(stringify(obj), '{"foo":1,"ofoo":42}')
|
|
109
|
+
t.assert.equal(stringify(obj), '{"foo":1,"ofoo":42}')
|
|
110
110
|
})
|
|
111
111
|
|
|
112
112
|
test('additionalProperties - boolean coerce', (t) => {
|
|
@@ -121,7 +121,7 @@ test('additionalProperties - boolean coerce', (t) => {
|
|
|
121
121
|
})
|
|
122
122
|
|
|
123
123
|
const obj = { foo: 'true', ofoo: 0, arrfoo: [1, 2], objfoo: { a: true } }
|
|
124
|
-
t.equal(stringify(obj), '{"foo":true,"ofoo":false,"arrfoo":true,"objfoo":true}')
|
|
124
|
+
t.assert.equal(stringify(obj), '{"foo":true,"ofoo":false,"arrfoo":true,"objfoo":true}')
|
|
125
125
|
})
|
|
126
126
|
|
|
127
127
|
test('additionalProperties - object coerce', (t) => {
|
|
@@ -141,7 +141,7 @@ test('additionalProperties - object coerce', (t) => {
|
|
|
141
141
|
})
|
|
142
142
|
|
|
143
143
|
const obj = { objfoo: { answer: 42 } }
|
|
144
|
-
t.equal(stringify(obj), '{"objfoo":{"answer":42}}')
|
|
144
|
+
t.assert.equal(stringify(obj), '{"objfoo":{"answer":42}}')
|
|
145
145
|
})
|
|
146
146
|
|
|
147
147
|
test('additionalProperties - array coerce', (t) => {
|
|
@@ -159,10 +159,10 @@ test('additionalProperties - array coerce', (t) => {
|
|
|
159
159
|
})
|
|
160
160
|
|
|
161
161
|
const coercibleValues = { arrfoo: [1, 2] }
|
|
162
|
-
t.equal(stringify(coercibleValues), '{"arrfoo":["1","2"]}')
|
|
162
|
+
t.assert.equal(stringify(coercibleValues), '{"arrfoo":["1","2"]}')
|
|
163
163
|
|
|
164
164
|
const incoercibleValues = { foo: 'true', ofoo: 0, objfoo: { tyrion: 'lannister' } }
|
|
165
|
-
t.throws(() => stringify(incoercibleValues))
|
|
165
|
+
t.assert.throws(() => stringify(incoercibleValues))
|
|
166
166
|
})
|
|
167
167
|
|
|
168
168
|
test('additionalProperties with empty schema', (t) => {
|
|
@@ -173,7 +173,7 @@ test('additionalProperties with empty schema', (t) => {
|
|
|
173
173
|
})
|
|
174
174
|
|
|
175
175
|
const obj = { a: 1, b: true, c: null }
|
|
176
|
-
t.equal(stringify(obj), '{"a":1,"b":true,"c":null}')
|
|
176
|
+
t.assert.equal(stringify(obj), '{"a":1,"b":true,"c":null}')
|
|
177
177
|
})
|
|
178
178
|
|
|
179
179
|
test('additionalProperties with nested empty schema', (t) => {
|
|
@@ -187,7 +187,7 @@ test('additionalProperties with nested empty schema', (t) => {
|
|
|
187
187
|
})
|
|
188
188
|
|
|
189
189
|
const obj = { data: { a: 1, b: true, c: null } }
|
|
190
|
-
t.equal(stringify(obj), '{"data":{"a":1,"b":true,"c":null}}')
|
|
190
|
+
t.assert.equal(stringify(obj), '{"data":{"a":1,"b":true,"c":null}}')
|
|
191
191
|
})
|
|
192
192
|
|
|
193
193
|
test('nested additionalProperties', (t) => {
|
|
@@ -207,7 +207,7 @@ test('nested additionalProperties', (t) => {
|
|
|
207
207
|
})
|
|
208
208
|
|
|
209
209
|
const obj = [{ ap: { value: 'string' } }]
|
|
210
|
-
t.equal(stringify(obj), '[{"ap":{"value":"string"}}]')
|
|
210
|
+
t.assert.equal(stringify(obj), '[{"ap":{"value":"string"}}]')
|
|
211
211
|
})
|
|
212
212
|
|
|
213
213
|
test('very nested additionalProperties', (t) => {
|
|
@@ -244,7 +244,7 @@ test('very nested additionalProperties', (t) => {
|
|
|
244
244
|
})
|
|
245
245
|
|
|
246
246
|
const obj = [{ ap: { nested: { moarNested: { finally: { value: 'str' } } } } }]
|
|
247
|
-
t.equal(stringify(obj), '[{"ap":{"nested":{"moarNested":{"finally":{"value":"str"}}}}}]')
|
|
247
|
+
t.assert.equal(stringify(obj), '[{"ap":{"nested":{"moarNested":{"finally":{"value":"str"}}}}}]')
|
|
248
248
|
})
|
|
249
249
|
|
|
250
250
|
test('nested additionalProperties set to true', (t) => {
|
|
@@ -261,7 +261,7 @@ test('nested additionalProperties set to true', (t) => {
|
|
|
261
261
|
})
|
|
262
262
|
|
|
263
263
|
const obj = { ap: { value: 'string', someNumber: 42 } }
|
|
264
|
-
t.equal(stringify(obj), '{"ap":{"value":"string","someNumber":42}}')
|
|
264
|
+
t.assert.equal(stringify(obj), '{"ap":{"value":"string","someNumber":42}}')
|
|
265
265
|
})
|
|
266
266
|
|
|
267
267
|
test('field passed to fastSafeStringify as undefined should be removed', (t) => {
|
|
@@ -278,7 +278,7 @@ test('field passed to fastSafeStringify as undefined should be removed', (t) =>
|
|
|
278
278
|
})
|
|
279
279
|
|
|
280
280
|
const obj = { ap: { value: 'string', someNumber: undefined } }
|
|
281
|
-
t.equal(stringify(obj), '{"ap":{"value":"string"}}')
|
|
281
|
+
t.assert.equal(stringify(obj), '{"ap":{"value":"string"}}')
|
|
282
282
|
})
|
|
283
283
|
|
|
284
284
|
test('property without type but with enum, will acts as additionalProperties', (t) => {
|
|
@@ -294,7 +294,7 @@ test('property without type but with enum, will acts as additionalProperties', (
|
|
|
294
294
|
})
|
|
295
295
|
|
|
296
296
|
const obj = { ap: { additional: 'field' } }
|
|
297
|
-
t.equal(stringify(obj), '{"ap":{"additional":"field"}}')
|
|
297
|
+
t.assert.equal(stringify(obj), '{"ap":{"additional":"field"}}')
|
|
298
298
|
})
|
|
299
299
|
|
|
300
300
|
test('property without type but with enum, will acts as additionalProperties without overwriting', (t) => {
|
|
@@ -311,7 +311,7 @@ test('property without type but with enum, will acts as additionalProperties wit
|
|
|
311
311
|
})
|
|
312
312
|
|
|
313
313
|
const obj = { ap: { additional: 'field' } }
|
|
314
|
-
t.equal(stringify(obj), '{"ap":{}}')
|
|
314
|
+
t.assert.equal(stringify(obj), '{"ap":{}}')
|
|
315
315
|
})
|
|
316
316
|
|
|
317
317
|
test('function and symbol references are not serialized as undefined', (t) => {
|
|
@@ -328,5 +328,5 @@ test('function and symbol references are not serialized as undefined', (t) => {
|
|
|
328
328
|
})
|
|
329
329
|
|
|
330
330
|
const obj = { str: 'x', test: 'test', meth: () => 'x', sym: Symbol('x') }
|
|
331
|
-
t.equal(stringify(obj), '{"str":"x","test":"test"}')
|
|
331
|
+
t.assert.equal(stringify(obj), '{"str":"x","test":"test"}')
|
|
332
332
|
})
|