Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

json-stringify-extended

Package Overview
Dependencies
Maintainers
1
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json-stringify-extended - npm Package Compare versions

Comparing version
2.1.0
to
2.2.0
+1
-1
package.json
{
"name": "json-stringify-extended",
"version": "2.1.0",
"version": "2.2.0",
"dependencies": {

@@ -5,0 +5,0 @@ "uglify-es": "^3.3.9"

+86
-62

@@ -14,2 +14,3 @@ # json-stringify-extended

- stringify primitive js types properly without limitation
- manipulate objects while serializing
- get control on circular reference

@@ -31,16 +32,19 @@ - use custom types not yet defined (e.g. enums)

const data = {
a: 'basic set, default options',
b: 1,
c: true,
d: function (a, b) { console.log(a + b) },
e: {a: 0, b: 0.1, c: -2},
f: ['a', 'b', 'c'],
g: new Date('2017-01-01'),
h: /a|b/,
i: null,
j: Infinity,
k: NaN,
l: undefined,
m: stringify.deferred('my.enum.VALUE'),
n: Buffer.from('7468697320697320612074c3a97374', 'hex')
a: 'basic set, default options',
b: 1,
c: true,
d: function (a, b) { console.log(a + b) },
e: {a: 0, b: 0.1, c: -2},
f: ['a', 'b', 'c'],
g: new Date('2017-01-01'),
h: /a|b/,
i: null,
j: Infinity,
k: NaN,
l: undefined,
m: stringify.deferred('my.enum.VALUE'),
n: Buffer.from('7468697320697320612074c3a97374', 'hex'),
o: Symbol('cross'),
p: new Map([[1, 'Rico'], [2, 'Mimi']]),
q: new Set(['cuori', 'quadri', 'picche', 'fiori'])
}

@@ -52,24 +56,41 @@

{
a:"basic set, default options",
b:1,
c:true,
d:function (a, b) { console.log(a + b) },
e:{
a:0,
b:0.1,
c:-2
},
f:[
"a",
"b",
"c"
],
g:new Date("2017-01-01T00:00:00.000Z"),
h:/a|b/,
i:null,
j:Infinity,
k:NaN,
l:undefined,
m:my.enum.VALUE,
n:Buffer.from("dGhpcyBpcyBhIHTDqXN0")
a:"basic set, default options",
b:1,
c:true,
d:function (a, b) { console.log(a + b) },
e:{
a:0,
b:0.1,
c:-2
},
f:[
"a",
"b",
"c"
],
g:new Date("2017-01-01T00:00:00.000Z"),
h:/a|b/,
i:null,
j:Infinity,
k:NaN,
l:undefined,
m:my.enum.VALUE,
n:Buffer.from("dGhpcyBpcyBhIHTDqXN0"),
o:Symbol("cross"),
p:new Map([
[
1,
"Rico"
],
[
2,
"Mimi"
]
]),
q:new Set([
"cuori",
"quadri",
"picche",
"fiori"
])
}

@@ -128,27 +149,2 @@

##### options.safe
Type: `boolean`
Default: `false`
Works in safe mode, so it will not throws exception for circularity.
##### options.endline
Type: `string`
Default: `\n`
Endline string should contain spacing chars as `\n` or `\r\n`. Set to empty string `''` for one line output.
##### options.spacing
Type: `string`
Default: ` ` (two spaces)
Indentation string should contains only spacing chars as `\t` or spaces ` `.
##### options.compress
Type: `boolean`
Default: `false`
Compress data for ``function`` and ``Date``.
Note: in version < `2.0.0` also discard ``null`` and ``undefined`` values.
##### options.filter

@@ -235,2 +231,27 @@ Type: `function(key:string, value:string) return boolean`

##### options.safe
Type: `boolean`
Default: `false`
Works in safe mode, so it will not throws exception for circularity.
##### options.endline
Type: `string`
Default: `\n`
Endline string should contain spacing chars as `\n` or `\r\n`. Set to empty string `''` for one line output.
##### options.spacing
Type: `string`
Default: ` ` (two spaces)
Indentation string should contains only spacing chars as `\t` or spaces ` `.
##### options.compress
Type: `boolean`
Default: `false`
Compress data for ``function`` and ``Date``.
Note: in version < `2.0.0` also discard ``null`` and ``undefined`` values.
##### options.keyQuote

@@ -264,4 +285,7 @@ Type: `string`

#### v. 2.2.0
- support `Map` and `Set` types
#### v. 2.1.0
- support `Symbol` types
- support `Symbol` type
- **100%** code coverage

@@ -268,0 +292,0 @@ - drop `node` < `10`

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

const IRREGULAR_KEY = /^[^a-zA-Z]/
const SQUARED_IN_KEY = /^\w[\d\w_]*$/
const SQUARED_IN_KEY = /^\w[\d\w_]*$/
const STRIP_TRAILING_SEMICOLON = /;+$/

@@ -146,5 +146,2 @@

},
symbol: function (symbol) {
return 'Symbol(' + options.valueQuote + symbol.toString().match(SYMBOL_STRIP)[1] + options.valueQuote + ')'
},
regexp: function (obj) {

@@ -156,7 +153,27 @@ return obj.toString()

},
object: function (obj, deep, path) {
symbol: function (symbol) {
return 'Symbol(' + options.valueQuote + symbol.toString().match(SYMBOL_STRIP)[1] + options.valueQuote + ')'
},
map: function (map) {
const entries = []
for (const entry of map) {
entries.push(entry)
}
if (entries.length < 1) {
return 'new Map()'
}
return `new Map(${_serialize.array(entries, 2)})`
},
set: function (set) {
const entries = []
for (const entry of set) {
entries.push(entry)
}
if (entries.length < 1) {
return 'new Set()'
}
return `new Set(${_serialize.array(entries, 2)})`
},
object: function (obj, deep, path = '{}') {
_counter.object++
if (!path) {
path = '{}'
}

@@ -188,8 +205,4 @@ const _spacing0 = spacing(deep)

},
array: function (array, deep, path) {
array: function (array, deep, path = '[]') {
_counter.array++
if (!path) {
path = '[]'
}
if (circularity(array, path)) {

@@ -226,5 +239,3 @@ return '[Circularity]'

function item (key, value, deep, path) {
if (!deep) deep = 1
function item (key, value, deep = 1, path) {
if ((options.discard) && (value === undefined || value === null)) {

@@ -252,2 +263,6 @@ return null

_type = 'buffer'
} else if (value instanceof Map) {
_type = 'map'
} else if (value instanceof Set) {
_type = 'set'
} else if (value instanceof stringify._deferred) {

@@ -254,0 +269,0 @@ _type = 'deferred'