Socket
Socket
Sign inDemoInstall

fast-json-stringify

Package Overview
Dependencies
Maintainers
1
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.3.0 to 0.4.0

6

example.js

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

type: 'string'
},
reg: {
type: 'string'
}

@@ -29,3 +32,4 @@ }

age: 32,
now: new Date()
now: new Date(),
reg: /"([^"]|\\")*"/
}))

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

${$asBoolean.toString()}
${$asRegExp.toString()}
`

@@ -72,2 +73,4 @@ var main

return '"' + str.toISOString() + '"'
} else if (str instanceof RegExp) {
return $asRegExp(str)
} else if (typeof str !== 'string') {

@@ -120,2 +123,15 @@ str = str.toString()

function $asRegExp (reg) {
reg = reg.source
for (var i = 0, len = reg.length; i < len; i++) {
if (reg[i] === '\\' || reg[i] === '"') {
reg = reg.substring(0, i) + '\\' + reg.substring(i++)
len += 2
}
}
return '"' + reg + '"'
}
function buildObject (schema, code, name) {

@@ -122,0 +138,0 @@ code += `

2

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

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

@@ -37,2 +37,5 @@ # fast-json-stringify&nbsp;&nbsp;[![Build Status](https://travis-ci.org/mcollina/fast-json-stringify.svg)](https://travis-ci.org/mcollina/fast-json-stringify)

type: 'integer'
},
reg: {
type: 'string'
}

@@ -45,3 +48,4 @@ }

lastName: 'Collina',
age: 32
age: 32,
reg: /"([^"]|\\")*"/
}))

@@ -66,5 +70,12 @@ ```

And nested ones, too.
`Date` instances are serialized with `toISOString()`.
And nested ones, too.
*Specific use cases:*
| Instance | Serialized as |
| -----------|---------------------------------------------|
| `Date` | `string` <small>via `toISOString()`</small> |
| `RegExp` | `string` |
## Acknowledgements

@@ -71,0 +82,0 @@

@@ -225,1 +225,33 @@ 'use strict'

})
test('object with RexExp', (t) => {
t.plan(3)
const schema = {
title: 'object with RegExp',
type: 'object',
properties: {
reg: {
type: 'string'
}
}
}
const obj = {
reg: /"([^"]|\\")*"/
}
const stringify = build(schema)
const validate = validator(schema)
const output = stringify(obj)
try {
JSON.parse(output)
t.pass()
} catch (e) {
t.fail()
}
t.equal(obj.reg.source, new RegExp(JSON.parse(output).reg).source)
t.ok(validate(JSON.parse(output)), 'valid schema')
})
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