Socket
Socket
Sign inDemoInstall

fast-json-stringify

Package Overview
Dependencies
Maintainers
10
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 5.15.1 to 5.16.0

11

lib/standalone.js

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

if (context.validatorSchemasIds.size > 0) {
ajvDependencyCode += 'const Validator = require(\'fast-json-stringify/lib/validator\')\n'
ajvDependencyCode += `const validatorState = ${JSON.stringify(validator.getState())}\n`

@@ -13,9 +14,11 @@ ajvDependencyCode += 'const validator = Validator.restoreFromState(validatorState)\n'

// Don't need to keep external schemas once compiled
// validatorState will hold external schemas if it needs them
const { schema, ...serializerState } = serializer.getState()
return `
'use strict'
const { dependencies } = require('fast-json-stringify/lib/standalone')
const { Serializer, Validator } = dependencies
const serializerState = ${JSON.stringify(serializer.getState())}
const Serializer = require('fast-json-stringify/lib/serializer')
const serializerState = ${JSON.stringify(serializerState)}
const serializer = Serializer.restoreFromState(serializerState)

@@ -22,0 +25,0 @@

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

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

@@ -29,10 +29,10 @@ 'use strict'

const destionation = path.resolve(tmpDir, 'standalone.js')
const destination = path.resolve(tmpDir, 'standalone.js')
t.teardown(async () => {
await fs.promises.rm(destionation, { force: true })
await fs.promises.rm(destination, { force: true })
})
await fs.promises.writeFile(destionation, code)
const standalone = require(destionation)
await fs.promises.writeFile(destination, code)
const standalone = require(destination)
t.same(standalone({ firstName: 'Foo', surname: 'bar' }), JSON.stringify({ firstName: 'Foo' }), 'surname evicted')

@@ -93,10 +93,10 @@ })

const destionation = path.resolve(tmpDir, 'standalone2.js')
const destination = path.resolve(tmpDir, 'standalone2.js')
t.teardown(async () => {
await fs.promises.rm(destionation, { force: true })
await fs.promises.rm(destination, { force: true })
})
await fs.promises.writeFile(destionation, code)
const standalone = require(destionation)
await fs.promises.writeFile(destination, code)
const standalone = require(destination)
t.same(standalone({

@@ -124,1 +124,96 @@ kind: 'foobar',

})
test('no need to keep external schemas once compiled', async (t) => {
t.plan(1)
const externalSchema = {
first: {
definitions: {
id1: {
type: 'object',
properties: {
id1: {
type: 'integer'
}
}
}
}
}
}
const code = fjs({
$ref: 'first#/definitions/id1'
}, {
mode: 'standalone',
schema: externalSchema
})
const destination = path.resolve(tmpDir, 'standalone3.js')
t.teardown(async () => {
await fs.promises.rm(destination, { force: true })
})
await fs.promises.writeFile(destination, code)
const standalone = require(destination)
t.same(standalone({ id1: 5 }), JSON.stringify({ id1: 5 }), 'serialization works with external schemas')
})
test('no need to keep external schemas once compiled - with oneOf validator', async (t) => {
t.plan(2)
const externalSchema = {
ext: {
definitions: {
oBaz: {
type: 'object',
properties: {
baz: { type: 'number' }
},
required: ['baz']
},
oBar: {
type: 'object',
properties: {
bar: { type: 'string' }
},
required: ['bar']
},
other: {
type: 'string',
const: 'other'
}
}
}
}
const schema = {
title: 'object with oneOf property value containing refs to external schema',
type: 'object',
properties: {
oneOfSchema: {
oneOf: [
{ $ref: 'ext#/definitions/oBaz' },
{ $ref: 'ext#/definitions/oBar' }
]
}
},
required: ['oneOfSchema']
}
const code = fjs(schema, {
mode: 'standalone',
schema: externalSchema
})
const destination = path.resolve(tmpDir, 'standalone-oneOf-ref.js')
t.teardown(async () => {
await fs.promises.rm(destination, { force: true })
})
await fs.promises.writeFile(destination, code)
const stringify = require(destination)
t.equal(stringify({ oneOfSchema: { baz: 5 } }), '{"oneOfSchema":{"baz":5}}')
t.equal(stringify({ oneOfSchema: { bar: 'foo' } }), '{"oneOfSchema":{"bar":"foo"}}')
})
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