fast-json-stringify
Advanced tools
Comparing version 1.11.2 to 1.11.3
@@ -882,5 +882,10 @@ 'use strict' | ||
code += ` | ||
${index === 0 ? 'if' : 'else if'}(Number.isInteger(obj${accessor})) | ||
${index === 0 ? 'if' : 'else if'}(Number.isInteger(obj${accessor}) || obj${accessor} === null) | ||
${nestedResult.code} | ||
` | ||
} else if (type === 'number') { | ||
code += ` | ||
${index === 0 ? 'if' : 'else if'}(isNaN(obj${accessor}) === false) | ||
${nestedResult.code} | ||
` | ||
} else { | ||
@@ -887,0 +892,0 @@ code += ` |
{ | ||
"name": "fast-json-stringify", | ||
"version": "1.11.2", | ||
"version": "1.11.3", | ||
"description": "Stringify your JSON at max speed", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -484,2 +484,9 @@ # fast-json-stringify | ||
Otherwise, instead of raising an error, null values will be coerced as follows: | ||
- `integer` -> `0` | ||
- `number` -> `0` | ||
- `string` -> `""` | ||
- `boolean` -> `false` | ||
<a name="acknowledgements"></a> | ||
@@ -486,0 +493,0 @@ ## Acknowledgements |
@@ -44,1 +44,46 @@ 'use strict' | ||
}) | ||
test('handle null when value should be integer', (t) => { | ||
t.plan(1) | ||
const stringify = build({ | ||
type: 'object', | ||
properties: { | ||
int: { | ||
type: 'integer' | ||
} | ||
} | ||
}) | ||
t.equal('{"int":0}', stringify({ int: null })) | ||
}) | ||
test('handle null when value should be number', (t) => { | ||
t.plan(1) | ||
const stringify = build({ | ||
type: 'object', | ||
properties: { | ||
num: { | ||
type: 'number' | ||
} | ||
} | ||
}) | ||
t.equal('{"num":0}', stringify({ num: null })) | ||
}) | ||
test('handle null when value should be boolean', (t) => { | ||
t.plan(1) | ||
const stringify = build({ | ||
type: 'object', | ||
properties: { | ||
bool: { | ||
type: 'boolean' | ||
} | ||
} | ||
}) | ||
t.equal('{"bool":false}', stringify({ bool: null })) | ||
}) |
@@ -6,3 +6,3 @@ 'use strict' | ||
test('possibly nullable primitive alternative', (t) => { | ||
test('possibly nullable integer primitive alternative', (t) => { | ||
t.plan(1) | ||
@@ -32,6 +32,81 @@ | ||
test('nullable primitive', (t) => { | ||
test('possibly nullable number primitive alternative', (t) => { | ||
t.plan(1) | ||
const schema = { | ||
title: 'simple object with multi-type nullable primitive', | ||
type: 'object', | ||
properties: { | ||
data: { | ||
type: ['number'] | ||
} | ||
} | ||
} | ||
const stringify = build(schema) | ||
try { | ||
const value = stringify({ | ||
data: 4 | ||
}) | ||
t.is(value, '{"data":4}') | ||
} catch (e) { | ||
t.fail() | ||
} | ||
}) | ||
test('possibly nullable integer primitive alternative with null value', (t) => { | ||
t.plan(1) | ||
const schema = { | ||
title: 'simple object with multi-type nullable primitive', | ||
type: 'object', | ||
properties: { | ||
data: { | ||
type: ['integer'] | ||
} | ||
} | ||
} | ||
const stringify = build(schema) | ||
try { | ||
const value = stringify({ | ||
data: null | ||
}) | ||
t.is(value, '{"data":0}') | ||
} catch (e) { | ||
t.fail() | ||
} | ||
}) | ||
test('possibly nullable number primitive alternative with null value', (t) => { | ||
t.plan(1) | ||
const schema = { | ||
title: 'simple object with multi-type nullable primitive', | ||
type: 'object', | ||
properties: { | ||
data: { | ||
type: ['number'] | ||
} | ||
} | ||
} | ||
const stringify = build(schema) | ||
try { | ||
const value = stringify({ | ||
data: null | ||
}) | ||
t.is(value, '{"data":0}') | ||
} catch (e) { | ||
t.fail() | ||
} | ||
}) | ||
test('nullable integer primitive', (t) => { | ||
t.plan(1) | ||
const schema = { | ||
title: 'simple object with nullable primitive', | ||
@@ -58,2 +133,77 @@ type: 'object', | ||
test('nullable number primitive', (t) => { | ||
t.plan(1) | ||
const schema = { | ||
title: 'simple object with nullable primitive', | ||
type: 'object', | ||
properties: { | ||
data: { | ||
type: ['number', 'null'] | ||
} | ||
} | ||
} | ||
const stringify = build(schema) | ||
try { | ||
const value = stringify({ | ||
data: 4 | ||
}) | ||
t.is(value, '{"data":4}') | ||
} catch (e) { | ||
t.fail() | ||
} | ||
}) | ||
test('nullable primitive with null value', (t) => { | ||
t.plan(1) | ||
const schema = { | ||
title: 'simple object with nullable primitive', | ||
type: 'object', | ||
properties: { | ||
data: { | ||
type: ['integer', 'null'] | ||
} | ||
} | ||
} | ||
const stringify = build(schema) | ||
try { | ||
const value = stringify({ | ||
data: null | ||
}) | ||
t.is(value, '{"data":null}') | ||
} catch (e) { | ||
t.fail() | ||
} | ||
}) | ||
test('nullable number primitive with null value', (t) => { | ||
t.plan(1) | ||
const schema = { | ||
title: 'simple object with nullable primitive', | ||
type: 'object', | ||
properties: { | ||
data: { | ||
type: ['number', 'null'] | ||
} | ||
} | ||
} | ||
const stringify = build(schema) | ||
try { | ||
const value = stringify({ | ||
data: null | ||
}) | ||
t.is(value, '{"data":null}') | ||
} catch (e) { | ||
t.fail() | ||
} | ||
}) | ||
test('possibly null object with multi-type property', (t) => { | ||
@@ -60,0 +210,0 @@ t.plan(3) |
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
120060
4602
500