Socket
Socket
Sign inDemoInstall

fast-json-stringify

Package Overview
Dependencies
11
Maintainers
9
Versions
157
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 5.8.0 to 5.9.0

.gitattributes

2

benchmark/bench-cmp-branch.js
'use strict'
const { spawn } = require('child_process')
const { spawn } = require('node:child_process')

@@ -5,0 +5,0 @@ const cliSelect = require('cli-select')

'use strict'
const { workerData: benchmark, parentPort } = require('worker_threads')
const { workerData: benchmark, parentPort } = require('node:worker_threads')

@@ -5,0 +5,0 @@ const Benchmark = require('benchmark')

'use strict'
const path = require('path')
const { Worker } = require('worker_threads')
const path = require('node:path')
const { Worker } = require('node:worker_threads')

@@ -6,0 +6,0 @@ const BENCH_THREAD_PATH = path.join(__dirname, 'bench-thread.js')

@@ -6,4 +6,4 @@ 'use strict'

const ajvFormats = require('ajv-formats')
const fs = require('fs')
const path = require('path')
const fs = require('node:fs')
const path = require('node:path')

@@ -10,0 +10,0 @@ const ajv = new Ajv({

@@ -0,1 +1,3 @@

'use strict'
const fastJson = require('..')

@@ -2,0 +4,0 @@ const stringify = fastJson({

'use strict'
const http = require('http')
const http = require('node:http')

@@ -5,0 +5,0 @@ const stringify = require('fast-json-stringify')({

@@ -7,3 +7,4 @@ 'use strict'

const clone = require('rfdc')({ proto: true })
const { randomUUID } = require('crypto')
const { randomUUID } = require('node:crypto')
const { RefResolver } = require('json-schema-ref-resolver')

@@ -13,5 +14,6 @@ const validate = require('./lib/schema-validator')

const Validator = require('./lib/validator')
const RefResolver = require('./lib/ref-resolver')
const Location = require('./lib/location')
const SINGLE_TICK = /'/g
let largeArraySize = 2e4

@@ -58,4 +60,3 @@ let largeArrayMechanism = 'default'

const schema = context.refResolver.getSchema(schemaId, jsonPointer)
if (schema === undefined) {
if (schema === null) {
throw new Error(`Cannot find reference "${ref}"`)

@@ -72,2 +73,9 @@ }

function getSchemaId (schema, rootSchemaId) {
if (schema.$id && schema.$id.charAt(0) !== '#') {
return schema.$id
}
return rootSchemaId
}
function build (schema, options) {

@@ -89,8 +97,15 @@ isValidSchema(schema)

context.refResolver.addSchema(schema, context.rootSchemaId)
const schemaId = getSchemaId(schema, context.rootSchemaId)
if (!context.refResolver.hasSchema(schemaId)) {
context.refResolver.addSchema(schema, context.rootSchemaId)
}
if (options.schema) {
for (const key of Object.keys(options.schema)) {
isValidSchema(options.schema[key], key)
context.refResolver.addSchema(options.schema[key], key)
for (const key in options.schema) {
const schema = options.schema[key]
const schemaId = getSchemaId(schema, key)
if (!context.refResolver.hasSchema(schemaId)) {
isValidSchema(schema, key)
context.refResolver.addSchema(schema, key)
}
}

@@ -829,3 +844,3 @@ }

code += `json += '${JSON.stringify(schema.const)}'`
code += `json += '${JSON.stringify(schema.const).replace(SINGLE_TICK, "\\'")}'`

@@ -832,0 +847,0 @@ if (hasNullType) {

{
"name": "fast-json-stringify",
"version": "5.8.0",
"version": "5.9.0",
"description": "Stringify your JSON at max speed",
"main": "index.js",
"type": "commonjs",
"types": "types/index.d.ts",

@@ -37,3 +38,3 @@ "scripts": {

"@fastify/pre-commit": "^2.0.2",
"@sinclair/typebox": "^0.29.1",
"@sinclair/typebox": "^0.31.1",
"benchmark": "^2.1.4",

@@ -46,3 +47,3 @@ "cli-select": "^1.1.2",

"tap": "^16.0.1",
"tsd": "^0.28.0",
"tsd": "^0.29.0",
"webpack": "^5.40.0",

@@ -57,3 +58,4 @@ "fast-json-stringify": "."

"fast-uri": "^2.1.0",
"rfdc": "^1.2.0"
"rfdc": "^1.2.0",
"json-schema-ref-resolver": "^1.0.1"
},

@@ -60,0 +62,0 @@ "standard": {

@@ -695,3 +695,3 @@ # fast-json-stringify

```js
const fs = require('fs')
const fs = require('node:fs')
const code = fastJson({

@@ -698,0 +698,0 @@ title: 'default string',

@@ -85,2 +85,22 @@ 'use strict'

test('schema with const string that contains \'', (t) => {
t.plan(2)
const schema = {
type: 'object',
properties: {
foo: { const: "'bar'" }
}
}
const validate = validator(schema)
const stringify = build(schema)
const output = stringify({
foo: "'bar'"
})
t.equal(output, '{"foo":"\'bar\'"}')
t.ok(validate(JSON.parse(output)), 'valid schema')
})
test('schema with const number', (t) => {

@@ -87,0 +107,0 @@ t.plan(2)

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

} catch (err) {
t.equal(err.message, 'Cannot find reference "extrenal#/definitions/projectId"')
t.equal(
err.message,
'Cannot resolve ref "extrenal#/definitions/projectId". Schema with id "extrenal" is not found.'
)
}

@@ -2080,3 +2083,7 @@ })

t.throws(() => build(schema), new Error('There is already another schema with id inner_schema'))
try {
build(schema)
} catch (err) {
t.equal(err.message, 'There is already another schema with id "inner_schema".')
}
})

@@ -2120,3 +2127,7 @@

t.throws(() => build(schema), Error('There is already another schema with id test##uri'))
try {
build(schema)
} catch (err) {
t.equal(err.message, 'There is already another anchor "#uri" in a schema "test".')
}
})

@@ -5,4 +5,4 @@ 'use strict'

const fjs = require('..')
const fs = require('fs')
const path = require('path')
const fs = require('node:fs')
const path = require('node:path')

@@ -9,0 +9,0 @@ function build (opts, schema) {

@@ -5,3 +5,3 @@ 'use strict'

const webpack = require('webpack')
const path = require('path')
const path = require('node:path')

@@ -8,0 +8,0 @@ test('the library should work with webpack', async (t) => {

Sorry, the diff of this file is not supported yet

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