safe-stable-stringify
Advanced tools
Changelog
v2.5.0
Array#sort(comparator)
comparator method as deterministic option value to use that comparator for sorting object keys.import { configure } from 'safe-stable-stringify'
const object = {
a: 1,
b: 2,
c: 3,
}
const stringify = configure({
deterministic: (a, b) => b.localeCompare(a)
})
stringify(object)
// '{"c":3,"b":2,"a":1}'
Thanks to @flobernd, @cesco69 and @prisis to contribute to this release!
Changelog
v2.4.3
Changelog
v2.4.1
string
, undefined
or string | undefined
depending on the input.Changelog
v2.4.0
strict
option to verify that the passed in objects are fully compatible with JSON without removing information. If not, an error is thrown.Changelog
v2.3.1
invalid regexp group
error in browsers or environments that do not support the negative lookbehind regular expression assertion.Changelog
v2.3.0
Error
constructor as circularValue
option to throw on circular references as the regular JSON.stringify would:import { configure } from 'safe-stable-stringify'
const object = {}
object.circular = object;
const stringify = configure({ circularValue: TypeError })
stringify(object)
// TypeError: Converting circular structure to JSON
Changelog
v2.2.0
undefined
as circularValue
option to remove circular properties from the serialized output:import { configure } from 'safe-stable-stringify'
const object = { array: [] }
object.circular = object;
object.array.push(object)
configure({ circularValue: undefined })(object)
// '{"array":[null]}'
Changelog
v2.1.0
maximumBreadth
option to limit stringification at a specific object or array "width" (number of properties / values)maximumDepth
option to limit stringification at a specific nesting depthChangelog
v2.0.0
bigint
option and set it to false
.