fast-json-stringify
Advanced tools
Comparing version 0.10.2 to 0.10.3
32
index.js
@@ -18,2 +18,3 @@ 'use strict' | ||
${$asString.toString()} | ||
${$asStringSmall.toString()} | ||
${$asNumber.toString()} | ||
@@ -87,5 +88,34 @@ ${$asNull.toString()} | ||
return JSON.stringify(str) | ||
if (str.length < 42) { | ||
return $asStringSmall(str) | ||
} else { | ||
return JSON.stringify(str) | ||
} | ||
} | ||
// magically escape strings for json | ||
// relying on their charCodeAt | ||
// everything below 32 needs JSON.stringify() | ||
// 34 and 92 happens all the time, so we | ||
// have a fast case for them | ||
function $asStringSmall (str) { | ||
var result = '' | ||
var last = 0 | ||
var l = str.length | ||
var point = 255 | ||
for (var i = 0; i < l && point >= 32; i++) { | ||
point = str.charCodeAt(i) | ||
if (point === 34 || point === 92) { | ||
result += str.slice(last, i) + '\\' + str[i] | ||
last = i + 1 | ||
} | ||
} | ||
if (last === 0) { | ||
result = str | ||
} else { | ||
result += str.slice(last) | ||
} | ||
return point < 32 ? JSON.stringify(str) : '"' + result + '"' | ||
} | ||
function addPatternProperties (schema, externalSchema) { | ||
@@ -92,0 +122,0 @@ var pp = schema.patternProperties |
{ | ||
"name": "fast-json-stringify", | ||
"version": "0.10.2", | ||
"version": "0.10.3", | ||
"description": "Stringify your JSON at max speed", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -1,2 +0,2 @@ | ||
# fast-json-stringify [![Build Status](https://travis-ci.org/mcollina/fast-json-stringify.svg)](https://travis-ci.org/mcollina/fast-json-stringify) | ||
# fast-json-stringify [![Build Status](https://travis-ci.org/fastify/fast-json-stringify.svg?branch=master)](https://travis-ci.org/fastify/fast-json-stringify) | ||
@@ -3,0 +3,0 @@ __fast-json-stringify__ is x1-4 times faster than `JSON.stringify()`. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
41579
1407