Socket
Socket
Sign inDemoInstall

fast-json-stringify

Package Overview
Dependencies
6
Maintainers
2
Versions
160
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.3.0 to 1.4.0

test/defaults.test.js

9

index.js

@@ -456,5 +456,12 @@ 'use strict'

if (schema.required && schema.required.indexOf(key) !== -1) {
var defaultValue = schema.properties[key].default
if (defaultValue !== undefined) {
code += `
} else {
${addComma}
json += '${$asString(key)}:${JSON.stringify(defaultValue).replace(/'/g, '\'')}'
`
} else if (schema.required && schema.required.indexOf(key) !== -1) {
code += `
} else {
throw new Error('${key} is required!')

@@ -461,0 +468,0 @@ `

2

package.json
{
"name": "fast-json-stringify",
"version": "1.3.0",
"version": "1.4.0",
"description": "Stringify your JSON at max speed",

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

@@ -166,2 +166,24 @@ # fast-json-stringify  [![Build Status](https://travis-ci.org/fastify/fast-json-stringify.svg?branch=master)](https://travis-ci.org/fastify/fast-json-stringify)

<a name="defaults"></a>
#### Defaults
`fast-json-stringify` supports `default` jsonschema key in order to serialize a value
if it is `undefined` or not present.
Example:
```javascript
const stringify = fastJson({
title: 'Example Schema',
type: 'object',
properties: {
nickname: {
type: 'string',
default: 'the default string'
}
}
})
console.log(stringify({})) // '{"nickname":"the default string"}'
console.log(stringify({nickname: 'my-nickname'})) // '{"nickname":"my-nickname"}'
```
<a name="patternProperties"></a>

@@ -168,0 +190,0 @@ #### Pattern properties

SocketSocket SOC 2 Logo

Product

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc