fast-json-stringify
Advanced tools
Comparing version 0.4.0 to 0.5.0
@@ -19,3 +19,4 @@ 'use strict' | ||
now: { | ||
type: 'string' | ||
type: 'string', | ||
required: true | ||
}, | ||
@@ -22,0 +23,0 @@ reg: { |
@@ -205,2 +205,8 @@ 'use strict' | ||
var funcName | ||
if (schema.required) { | ||
code += ` | ||
if (!obj.hasOwnProperty('${key.slice(1)}')) { | ||
throw new Error('${key} is required!') | ||
}` | ||
} | ||
const type = schema.type | ||
@@ -207,0 +213,0 @@ switch (type) { |
{ | ||
"name": "fast-json-stringify", | ||
"version": "0.4.0", | ||
"version": "0.5.0", | ||
"description": "Stringify your JSON at max speed", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
38
test.js
@@ -257,1 +257,39 @@ 'use strict' | ||
}) | ||
test('object with required field', (t) => { | ||
t.plan(3) | ||
const schema = { | ||
title: 'object with required field', | ||
type: 'object', | ||
properties: { | ||
str: { | ||
type: 'string', | ||
required: true | ||
}, | ||
num: { | ||
type: 'integer' | ||
} | ||
} | ||
} | ||
const stringify = build(schema) | ||
try { | ||
stringify({ | ||
str: 'string' | ||
}) | ||
t.pass() | ||
} catch (e) { | ||
t.fail() | ||
} | ||
try { | ||
stringify({ | ||
num: 42 | ||
}) | ||
t.fail() | ||
} catch (e) { | ||
t.is(e.message, '.str is required!') | ||
t.pass() | ||
} | ||
}) |
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
16584
623