Skip to content

Commit 36b8e39

Browse files
authored
Removed fast-safe-stringify, use plain JSON.stringify. (#71)
1 parent aba0c8d commit 36b8e39

File tree

3 files changed

+3
-23
lines changed

3 files changed

+3
-23
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ console.log(stringify(obj)) // '{"matchfoo":"42","otherfoo":"str","matchnum":3,"
203203
*additionalProperties* will work only for the properties that are not explicitly listed in the *properties* and *patternProperties* objects.
204204

205205
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>.
206-
If *additionalProperties* is set to `true`, it will be used by `fast-safe-stringify` to stringify the additional properties. If you want to achieve maximum performance, we strongly encourage you to use a fixed schema where possible.
206+
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.
207207
Example:
208208
```javascript
209209
const stringify = fastJson({

index.js

+1-20
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
'use strict'
22

3-
var fastSafeStringify = require('fast-safe-stringify')
43
var Ajv = require('ajv')
54

65
var uglify = null
@@ -91,10 +90,6 @@ function build (schema, options) {
9190

9291
var dependencies = []
9392
var dependenciesName = []
94-
if (hasAdditionalPropertiesTrue(schema)) {
95-
dependencies.push(fastSafeStringify)
96-
dependenciesName.push('fastSafeStringify')
97-
}
9893
if (hasAnyOf(schema)) {
9994
dependencies.push(new Ajv())
10095
dependenciesName.push('ajv')
@@ -104,20 +99,6 @@ function build (schema, options) {
10499
return (Function.apply(null, dependenciesName).apply(null, dependencies))
105100
}
106101

107-
function hasAdditionalPropertiesTrue (schema) {
108-
if (schema.additionalProperties === true) { return true }
109-
110-
var objectKeys = Object.keys(schema)
111-
for (var i = 0; i < objectKeys.length; i++) {
112-
var value = schema[objectKeys[i]]
113-
if (typeof value === 'object') {
114-
if (hasAdditionalPropertiesTrue(value)) { return true }
115-
}
116-
}
117-
118-
return false
119-
}
120-
121102
function hasAnyOf (schema) {
122103
if ('anyOf' in schema) { return true }
123104

@@ -280,7 +261,7 @@ function additionalProperty (schema, externalSchema, fullSchema) {
280261
return `
281262
if (obj[keys[i]] !== undefined) {
282263
${addComma}
283-
json += $asString(keys[i]) + ':' + fastSafeStringify(obj[keys[i]])
264+
json += $asString(keys[i]) + ':' + JSON.stringify(obj[keys[i]])
284265
}
285266
`
286267
}

package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
"uglify-es": "^3.2.2"
3535
},
3636
"dependencies": {
37-
"ajv": "^6.0.0",
38-
"fast-safe-stringify": "^1.2.1"
37+
"ajv": "^6.0.0"
3938
}
4039
}

0 commit comments

Comments
 (0)