Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

fast-json-stringify

Package Overview
Dependencies
Maintainers
2
Versions
160
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fast-json-stringify - npm Package Compare versions

Comparing version 1.11.2 to 1.11.3

7

index.js

@@ -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 += `

2

package.json
{
"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)

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc