Socket
Socket
Sign inDemoInstall

fast-json-stringify

Package Overview
Dependencies
9
Maintainers
2
Versions
158
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.7.9 to 2.7.10

28

bench.js

@@ -53,2 +53,14 @@ 'use strict'

const dateFormatSchema = {
description: 'Date of birth',
type: 'string',
format: 'date'
}
const dateFormatSchemaCJS = {
description: 'Date of birth',
type: 'string',
format: 'date'
}
const obj = {

@@ -60,2 +72,4 @@ firstName: 'Matteo',

const date = new Date()
const multiArray = []

@@ -66,2 +80,3 @@

const CJSStringifyArray = CJS(arraySchemaCJS)
const CJSStringifyDate = CJS(dateFormatSchemaCJS)
const CJSStringifyString = CJS({ type: 'string' })

@@ -72,2 +87,3 @@

const stringifyArray = FJS(arraySchema)
const stringifyDate = FJS(dateFormatSchema)
const stringifyString = FJS({ type: 'string' })

@@ -145,2 +161,14 @@ let str = ''

suite.add('JSON stringify date', function () {
JSON.stringify(date)
})
suite.add('fast-json-stringify date format', function () {
stringifyDate(date)
})
suite.add('compile-json-stringify date format', function () {
CJSStringifyDate(date)
})
suite.on('cycle', cycle)

@@ -147,0 +175,0 @@

22

index.js

@@ -288,6 +288,3 @@ 'use strict'

if (date instanceof Date) {
const year = new Intl.DateTimeFormat('en', { year: 'numeric' }).format(date)
const month = new Intl.DateTimeFormat('en', { month: '2-digit' }).format(date)
const day = new Intl.DateTimeFormat('en', { day: '2-digit' }).format(date)
return quotes + year + '-' + month + '-' + day + quotes
return quotes + new Date(date.getTime() - (date.getTimezoneOffset() * 60000 )).toISOString().slice(0, 10) + quotes
} else if (date && typeof date.format === 'function') {

@@ -963,5 +960,2 @@ return quotes + date.format('YYYY-MM-DD') + quotes

}
code += `
var json = '['
`
const laterCode = ''

@@ -1028,13 +1022,13 @@

var l = obj.length
var jsonOutput= ''
for (var i = 0; i < l; i++) {
var jsonLastChar = json[json.length - 1]
var json = ''
${result.code}
jsonOutput += json
if (i > 0 && jsonLastChar !== '[' && jsonLastChar !== ',') {
json += ','
if (json.length > 0 && i < l - 1) {
jsonOutput += ','
}
${result.code}
}
json += ']'
return json
return \`[\${jsonOutput}]\`
}

@@ -1041,0 +1035,0 @@ ${result.laterCode}

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

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

@@ -15,18 +15,21 @@ # fast-json-stringify

- Machine: `EX41S-SSD, Intel Core i7, 4Ghz, 64GB RAM, 4C/8T, SSD`.
- Node.js `v12.16.2`
- Node.js `v16.9.1`
```
FJS creation x 59,805 ops/sec ±0.23% (91 runs sampled)
FJS creation x 6,040 ops/sec ±1.17% (91 runs sampled)
JSON.stringify array x 5,330 ops/sec ±0.54% (97 runs sampled)
fast-json-stringify array x 6,995 ops/sec ±0.24% (94 runs sampled)
JSON.stringify array x 5,519 ops/sec ±0.08% (99 runs sampled)
fast-json-stringify array x 7,143 ops/sec ±0.14% (97 runs sampled)
JSON.stringify long string x 15,108 ops/sec ±0.13% (100 runs sampled)
fast-json-stringify long string x 15,089 ops/sec ±0.15% (98 runs sampled)
JSON.stringify long string x 16,438 ops/sec ±0.32% (98 runs sampled)
fast-json-stringify long string x 16,457 ops/sec ±0.09% (97 runs sampled)
JSON.stringify short string x 13,214,696 ops/sec ±0.19% (97 runs sampled)
fast-json-stringify short string x 33,378,500 ops/sec ±0.27% (95 runs sampled)
JSON.stringify short string x 12,061,258 ops/sec ±0.32% (97 runs sampled)
fast-json-stringify short string x 35,531,071 ops/sec ±0.17% (94 runs sampled)
JSON.stringify obj x 3,172,653 ops/sec ±0.15% (98 runs sampled)
fast-json-stringify obj x 13,537,123 ops/sec ±0.19% (95 runs sampled)
JSON.stringify obj x 3,079,746 ops/sec ±0.09% (95 runs sampled)
fast-json-stringify obj x 7,721,569 ops/sec ±0.12% (98 runs sampled)
JSON stringify date x 1,149,786 ops/sec ±0.10% (99 runs sampled)
fast-json-stringify date format x 1,674,498 ops/sec ±0.12% (99 runs sampled)
```

@@ -33,0 +36,0 @@

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc