fast-json-stringify 5.9.0 → 5.9.2
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 +1 -1
- package/benchmark/bench-cmp-branch.js +1 -1
- package/benchmark/bench-thread.js +1 -1
- package/benchmark/bench.js +2 -2
- package/build/build-schema-validator.js +2 -2
- package/examples/server.js +1 -1
- package/index.js +14 -6
- package/package.json +6 -3
- package/test/array.test.js +25 -1
- package/test/standalone-mode.test.js +2 -2
- package/test/webpack.test.js +1 -1
package/README.md
CHANGED
|
@@ -692,7 +692,7 @@ The standalone mode is used to compile the code that can be directly run by `nod
|
|
|
692
692
|
itself. You need to have `fast-json-stringify` installed for the standalone code to work.
|
|
693
693
|
|
|
694
694
|
```js
|
|
695
|
-
const fs = require('
|
|
695
|
+
const fs = require('fs')
|
|
696
696
|
const code = fastJson({
|
|
697
697
|
title: 'default string',
|
|
698
698
|
type: 'object',
|
package/benchmark/bench.js
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
const Ajv = require('ajv')
|
|
4
4
|
const standaloneCode = require('ajv/dist/standalone').default
|
|
5
5
|
const ajvFormats = require('ajv-formats')
|
|
6
|
-
const fs = require('
|
|
7
|
-
const path = require('
|
|
6
|
+
const fs = require('fs')
|
|
7
|
+
const path = require('path')
|
|
8
8
|
|
|
9
9
|
const ajv = new Ajv({
|
|
10
10
|
addUsedSchema: false,
|
package/examples/server.js
CHANGED
package/index.js
CHANGED
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
|
|
5
5
|
const merge = require('@fastify/deepmerge')()
|
|
6
6
|
const clone = require('rfdc')({ proto: true })
|
|
7
|
-
const { randomUUID } = require('node:crypto')
|
|
8
7
|
const { RefResolver } = require('json-schema-ref-resolver')
|
|
9
8
|
|
|
10
9
|
const validate = require('./lib/schema-validator')
|
|
@@ -31,6 +30,8 @@ const validLargeArrayMechanisms = [
|
|
|
31
30
|
|
|
32
31
|
const addComma = '!addComma && (addComma = true) || (json += \',\')'
|
|
33
32
|
|
|
33
|
+
let schemaIdCounter = 0
|
|
34
|
+
|
|
34
35
|
function isValidSchema (schema, name) {
|
|
35
36
|
if (!validate(schema)) {
|
|
36
37
|
if (name) {
|
|
@@ -86,7 +87,7 @@ function build (schema, options) {
|
|
|
86
87
|
options,
|
|
87
88
|
wrapObjects: true,
|
|
88
89
|
refResolver: new RefResolver(),
|
|
89
|
-
rootSchemaId: schema.$id ||
|
|
90
|
+
rootSchemaId: schema.$id || `__fjs_root_${schemaIdCounter++}`,
|
|
90
91
|
validatorSchemasIds: new Set()
|
|
91
92
|
}
|
|
92
93
|
|
|
@@ -500,7 +501,7 @@ function mergeAllOfSchema (context, location, schema, mergedSchema) {
|
|
|
500
501
|
}
|
|
501
502
|
delete mergedSchema.allOf
|
|
502
503
|
|
|
503
|
-
mergedSchema.$id = `
|
|
504
|
+
mergedSchema.$id = `__fjs_merged_${schemaIdCounter++}`
|
|
504
505
|
context.refResolver.addSchema(mergedSchema)
|
|
505
506
|
location.addMergedSchema(mergedSchema, mergedSchema.$id)
|
|
506
507
|
}
|
|
@@ -680,7 +681,15 @@ function buildArrayTypeCondition (type, accessor) {
|
|
|
680
681
|
condition = `obj${accessor} === null`
|
|
681
682
|
break
|
|
682
683
|
case 'string':
|
|
683
|
-
condition = `typeof obj${accessor} === 'string'
|
|
684
|
+
condition = `typeof obj${accessor} === 'string' ||
|
|
685
|
+
obj${accessor} === null ||
|
|
686
|
+
obj${accessor} instanceof Date ||
|
|
687
|
+
obj${accessor} instanceof RegExp ||
|
|
688
|
+
(
|
|
689
|
+
typeof obj${accessor} === "object" &&
|
|
690
|
+
typeof obj${accessor}.toString === "function" &&
|
|
691
|
+
obj${accessor}.toString !== Object.prototype.toString
|
|
692
|
+
)`
|
|
684
693
|
break
|
|
685
694
|
case 'integer':
|
|
686
695
|
condition = `Number.isInteger(obj${accessor})`
|
|
@@ -740,8 +749,7 @@ function buildMultiTypeSerializer (context, location, input) {
|
|
|
740
749
|
(
|
|
741
750
|
typeof ${input} === "object" &&
|
|
742
751
|
typeof ${input}.toString === "function" &&
|
|
743
|
-
${input}.toString !== Object.prototype.toString
|
|
744
|
-
!(${input} instanceof Date)
|
|
752
|
+
${input}.toString !== Object.prototype.toString
|
|
745
753
|
)
|
|
746
754
|
)
|
|
747
755
|
${nestedResult}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fast-json-stringify",
|
|
3
|
-
"version": "5.9.
|
|
3
|
+
"version": "5.9.2",
|
|
4
4
|
"description": "Stringify your JSON at max speed",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "commonjs",
|
|
@@ -16,7 +16,10 @@
|
|
|
16
16
|
"test:unit": "tap",
|
|
17
17
|
"test": "npm run test:unit && npm run test:typescript"
|
|
18
18
|
},
|
|
19
|
-
"precommit": [
|
|
19
|
+
"precommit": [
|
|
20
|
+
"lint",
|
|
21
|
+
"test"
|
|
22
|
+
],
|
|
20
23
|
"repository": {
|
|
21
24
|
"type": "git",
|
|
22
25
|
"url": "git+https://github.com/fastify/fast-json-stringify.git"
|
|
@@ -35,7 +38,7 @@
|
|
|
35
38
|
"homepage": "https://github.com/fastify/fast-json-stringify#readme",
|
|
36
39
|
"devDependencies": {
|
|
37
40
|
"@fastify/pre-commit": "^2.0.2",
|
|
38
|
-
"@sinclair/typebox": "^0.
|
|
41
|
+
"@sinclair/typebox": "^0.32.3",
|
|
39
42
|
"benchmark": "^2.1.4",
|
|
40
43
|
"cli-select": "^1.1.2",
|
|
41
44
|
"compile-json-stringify": "^0.1.2",
|
package/test/array.test.js
CHANGED
|
@@ -31,12 +31,36 @@ function buildTest (schema, toStringify, options) {
|
|
|
31
31
|
const stringify = build(schema, options)
|
|
32
32
|
const output = stringify(toStringify)
|
|
33
33
|
|
|
34
|
-
t.same(JSON.parse(output), toStringify)
|
|
34
|
+
t.same(JSON.parse(output), JSON.parse(JSON.stringify(toStringify)))
|
|
35
35
|
t.equal(output, JSON.stringify(toStringify))
|
|
36
36
|
t.ok(validate(JSON.parse(output)), 'valid schema')
|
|
37
37
|
})
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
+
buildTest({
|
|
41
|
+
title: 'dates tuple',
|
|
42
|
+
type: 'object',
|
|
43
|
+
properties: {
|
|
44
|
+
dates: {
|
|
45
|
+
type: 'array',
|
|
46
|
+
minItems: 2,
|
|
47
|
+
maxItems: 2,
|
|
48
|
+
items: [
|
|
49
|
+
{
|
|
50
|
+
type: 'string',
|
|
51
|
+
format: 'date-time'
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
type: 'string',
|
|
55
|
+
format: 'date-time'
|
|
56
|
+
}
|
|
57
|
+
]
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}, {
|
|
61
|
+
dates: [new Date(1), new Date(2)]
|
|
62
|
+
})
|
|
63
|
+
|
|
40
64
|
buildTest({
|
|
41
65
|
title: 'string array',
|
|
42
66
|
type: 'object',
|