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 0.10.5 to 0.11.0

test/long.test.js

48

index.js

@@ -5,2 +5,9 @@ 'use strict'

let isLong
try {
isLong = require('long').isLong
} catch (e) {
isLong = null
}
function build (schema, options) {

@@ -24,2 +31,15 @@ options = options || {}

`
// only handle longs if the module is used
if (isLong) {
code += `
const isLong = ${isLong.toString()}
${$asInteger.toString()}
`
} else {
code += `
const $asInteger = $asNumber
`
}
var main

@@ -36,2 +56,4 @@

case 'integer':
main = $asInteger.name
break
case 'number':

@@ -68,2 +90,10 @@ main = $asNumber.name

function $asInteger (i) {
if (isLong && isLong(i)) {
return i.toString()
} else {
return $asNumber(i)
}
}
function $asNumber (i) {

@@ -156,4 +186,8 @@ var num = Number(i)

`
} else if (type === 'number' || type === 'integer') {
} else if (type === 'integer') {
code += `
json += $asString(keys[i]) + ':' + $asInteger(obj[keys[i]]) + ','
`
} else if (type === 'number') {
code += `
json += $asString(keys[i]) + ':' + $asNumber(obj[keys[i]]) + ','

@@ -217,4 +251,8 @@ `

`
} else if (type === 'number' || type === 'integer') {
} else if (type === 'integer') {
code += `
json += $asString(keys[i]) + ':' + $asInteger(obj[keys[i]]) + ','
`
} else if (type === 'number') {
code += `
json += $asString(keys[i]) + ':' + $asNumber(obj[keys[i]]) + ','

@@ -374,5 +412,9 @@ `

break
case 'number':
case 'integer':
code += `
json += $asInteger(obj${key})
`
break
case 'number':
code += `
json += $asNumber(obj${key})

@@ -379,0 +421,0 @@ `

3

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

@@ -29,2 +29,3 @@ "main": "index.js",

"is-my-json-valid": "^2.16.0",
"long": "^3.2.0",
"pre-commit": "^1.1.3",

@@ -31,0 +32,0 @@ "standard": "^10.0.0",

@@ -30,2 +30,3 @@ # 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 href="#ref">`Reuse - $ref`</a>
- <a href="#long">`Long integers`</a>
- <a href="#acknowledgements">`Acknowledgements`</a>

@@ -298,2 +299,26 @@ - <a href="#license">`License`</a>

<a name="long"></a>
#### Long integers
Long integers (64-bit) are supported using the [long](https://github.com/dcodeIO/long.js) module.
Example:
```javascript
const Long = require('long')
const stringify = fastJson({
title: 'Example Schema',
type: 'object',
properties: {
id: {
type: 'integer'
}
}
})
const obj = {
id: Long.fromString('18446744073709551615', true)
}
console.log(stringify(obj)) // '{"id":18446744073709551615}'
```
<a name="acknowledgements"></a>

@@ -300,0 +325,0 @@ ## Acknowledgements

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