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.12.0 to 1.13.0

test/nullable.test.js

76

index.js

@@ -47,6 +47,10 @@ 'use strict'

${$asString.toString()}
${$asStringNullable.toString()}
${$asStringSmall.toString()}
${$asNumber.toString()}
${$asNumberNullable.toString()}
${$asIntegerNullable.toString()}
${$asNull.toString()}
${$asBoolean.toString()}
${$asBooleanNullable.toString()}
`

@@ -80,12 +84,12 @@

case 'string':
main = $asString.name
main = schema.nullable ? $asStringNullable.name : $asString.name
break
case 'integer':
main = $asInteger.name
main = schema.nullable ? $asIntegerNullable.name : $asInteger.name
break
case 'number':
main = $asNumber.name
main = schema.nullable ? $asNumberNullable.name : $asNumber.name
break
case 'boolean':
main = $asBoolean.name
main = schema.nullable ? $asBooleanNullable.name : $asBoolean.name
break

@@ -105,3 +109,3 @@ case 'null':

;
return ${main}
return ${main}
`

@@ -208,2 +212,6 @@

function $asIntegerNullable (i) {
return i === null ? null : $asInteger(i)
}
function $asNumber (i) {

@@ -218,2 +226,6 @@ var num = Number(i)

function $asNumberNullable (i) {
return i === null ? null : $asNumber(i)
}
function $asBoolean (bool) {

@@ -223,2 +235,6 @@ return bool && 'true' || 'false' // eslint-disable-line

function $asBooleanNullable (bool) {
return bool === null ? null : $asBoolean(bool)
}
function $asString (str) {

@@ -242,2 +258,6 @@ if (str instanceof Date) {

function $asStringNullable (str) {
return str === null ? null : $asString(str)
}
// magically escape strings for json

@@ -491,2 +511,14 @@ // relying on their charCodeAt

var type = schema.properties[key].type
var nullable = schema.properties[key].nullable
if (nullable) {
code += `
if (obj['${key}'] === null) {
${addComma}
json += '${$asString(key)}:null'
var rendered = true
} else {
`
}
if (type === 'number') {

@@ -560,4 +592,9 @@ code += `

`
if (nullable) {
code += `
}
`
}
})
return { code: code, laterCode: laterCode }

@@ -704,5 +741,13 @@ }

function ${name} (obj) {
`
if (schema.nullable) {
code += `
if(obj === null) {
return '${$asNull()}';
}
`
}
code += `
var json = '['
`
var laterCode = ''

@@ -811,2 +856,3 @@

var type = schema.type
var nullable = schema.nullable === true

@@ -821,20 +867,12 @@ var accessor = key.indexOf('[') === 0 ? key : `['${key}']`

case 'string':
code += `
json += $asString(obj${accessor})
`
code += nullable ? `json += obj${accessor} === null ? null : $asString(obj${accessor})` : `json += $asString(obj${accessor})`
break
case 'integer':
code += `
json += $asInteger(obj${accessor})
`
code += nullable ? `json += obj${accessor} === null ? null : $asInteger(obj${accessor})` : `json += $asInteger(obj${accessor})`
break
case 'number':
code += `
json += $asNumber(obj${accessor})
`
code += nullable ? `json += obj${accessor} === null ? null : $asNumber(obj${accessor})` : `json += $asNumber(obj${accessor})`
break
case 'boolean':
code += `
json += $asBoolean(obj${accessor})
`
code += nullable ? `json += obj${accessor} === null ? null : $asBoolean(obj${accessor})` : `json += $asBoolean(obj${accessor})`
break

@@ -841,0 +879,0 @@ case 'object':

{
"name": "fast-json-stringify",
"version": "1.12.0",
"version": "1.13.0",
"description": "Stringify your JSON at max speed",

@@ -5,0 +5,0 @@ "main": "index.js",

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