fast-json-stringify
Advanced tools
Comparing version 2.2.10 to 2.3.0
30
index.js
@@ -105,4 +105,2 @@ 'use strict' | ||
var hasSchemaSomeIf = hasIf(schema) | ||
var main | ||
@@ -145,3 +143,3 @@ | ||
var dependenciesName = [] | ||
if (hasOf(schema) || hasSchemaSomeIf) { | ||
if (dependsOnAjv(schema)) { | ||
dependencies.push(new Ajv(options.ajv)) | ||
@@ -217,20 +215,5 @@ dependenciesName.push('ajv') | ||
function hasOf (schema) { | ||
if (!schema) { return false } | ||
if ('anyOf' in schema || 'oneOf' in schema) { return true } | ||
var objectKeys = Object.keys(schema) | ||
for (var i = 0; i < objectKeys.length; i++) { | ||
var value = schema[objectKeys[i]] | ||
if (typeof value === 'object') { | ||
if (hasOf(value)) { return true } | ||
} | ||
} | ||
return false | ||
} | ||
function hasIf (schema) { | ||
function dependsOnAjv (schema) { | ||
const str = JSON.stringify(schema) | ||
return /"if":{/.test(str) && /"then":{/.test(str) | ||
return (/"if":{.*"then":{|"(anyOf|oneOf)":\[|"const":/.test(str)) | ||
} | ||
@@ -1193,2 +1176,9 @@ | ||
` | ||
} else if ('const' in schema) { | ||
code += ` | ||
if(ajv.validate(${require('util').inspect(schema, { depth: null })}, obj${accessor})) | ||
json += '${JSON.stringify(schema.const)}' | ||
else | ||
throw new Error(\`Item $\{JSON.stringify(obj${accessor})} does not match schema definition.\`) | ||
` | ||
} else { | ||
@@ -1195,0 +1185,0 @@ throw new Error(`${schema.type} unsupported`) |
{ | ||
"name": "fast-json-stringify", | ||
"version": "2.2.10", | ||
"version": "2.3.0", | ||
"description": "Stringify your JSON at max speed", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
312855
60
9381