mirror of
https://github.com/flynx/serialize.js.git
synced 2026-07-10 11:10:57 +00:00
tweaking the options...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
6ba464d3d4
commit
2fb5bc882d
26
README.md
26
README.md
@ -51,18 +51,6 @@ Thus, care must be taken when serializing structures containing function.
|
|||||||
|
|
||||||
## API
|
## API
|
||||||
|
|
||||||
### `STRING_LENGTH_REF` / `settings.string_length_ref`
|
|
||||||
|
|
||||||
Defines the default maximum string to include in the output as-is before
|
|
||||||
referencing.
|
|
||||||
|
|
||||||
If set to `0`, referencing will be disabled.
|
|
||||||
|
|
||||||
Default: 96
|
|
||||||
(Dynamic: `.REFERENCE.length * 16`)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
### `serialize(..)` / `eJSON.stringify(..)`
|
### `serialize(..)` / `eJSON.stringify(..)`
|
||||||
|
|
||||||
### `deserialize(..)` / 'eJSON.parse(..)'
|
### `deserialize(..)` / 'eJSON.parse(..)'
|
||||||
@ -72,6 +60,20 @@ Default: 96
|
|||||||
### `partialDeepCopy(..)`
|
### `partialDeepCopy(..)`
|
||||||
|
|
||||||
|
|
||||||
|
### `MIN_LENGTH_REF` / `<options>.min_length_ref`
|
||||||
|
|
||||||
|
Defines the default minimum length of repeating string or bin-int to
|
||||||
|
include as a reference in the output.
|
||||||
|
|
||||||
|
If set to `0`, referencing will be disabled.
|
||||||
|
|
||||||
|
Default: 96
|
||||||
|
|
||||||
|
|
||||||
|
### `DEBUG`
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Format
|
## Format
|
||||||
|
|
||||||
The output of `.serialize(..)` is a strict superset of [standard JSON](https://www.json.org/json-en.html),
|
The output of `.serialize(..)` is a strict superset of [standard JSON](https://www.json.org/json-en.html),
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "ig-serialize",
|
"name": "ig-serialize",
|
||||||
"version": "1.1.0",
|
"version": "1.2.0",
|
||||||
"description": "experimental extended json serializaion...",
|
"description": "experimental extended json serializaion...",
|
||||||
"main": "serialize.js",
|
"main": "serialize.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
20
serialize.js
20
serialize.js
@ -77,7 +77,7 @@ var debug = {
|
|||||||
|
|
||||||
//---------------------------------------------------------------------
|
//---------------------------------------------------------------------
|
||||||
|
|
||||||
module.STRING_LENGTH_REF = REFERENCE.length * 16
|
module.MIN_LENGTH_REF = REFERENCE.length * 16
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
@ -144,9 +144,13 @@ module.STRING_LENGTH_REF = REFERENCE.length * 16
|
|||||||
var _serialize =
|
var _serialize =
|
||||||
module._serialize =
|
module._serialize =
|
||||||
function(obj, path=[], seen=new Map(), indent, depth=0, options={}){
|
function(obj, path=[], seen=new Map(), indent, depth=0, options={}){
|
||||||
var string_length_ref =
|
var min_length_ref =
|
||||||
options.string_length_ref
|
options.min_length_ref
|
||||||
?? module.STRING_LENGTH_REF
|
?? module.MIN_LENGTH_REF
|
||||||
|
min_length_ref =
|
||||||
|
min_length_ref <= 0 ?
|
||||||
|
Infinity
|
||||||
|
: min_length_ref
|
||||||
|
|
||||||
// reference...
|
// reference...
|
||||||
var p = seen.get(obj)
|
var p = seen.get(obj)
|
||||||
@ -171,12 +175,14 @@ function(obj, path=[], seen=new Map(), indent, depth=0, options={}){
|
|||||||
// long strings...
|
// long strings...
|
||||||
// NOTE: this saves on output size...
|
// NOTE: this saves on output size...
|
||||||
if(typeof(obj) == 'string'
|
if(typeof(obj) == 'string'
|
||||||
&& obj.length > string_length_ref){
|
&& obj.length > min_length_ref){
|
||||||
seen.set(obj, path) }
|
seen.set(obj, path) }
|
||||||
// BigInt...
|
// BigInt...
|
||||||
if(typeof(obj) == 'bigint'){
|
if(typeof(obj) == 'bigint'){
|
||||||
seen.set(obj, path)
|
var res = obj.toString() +'n'
|
||||||
return obj.toString() +'n' }
|
if(res.length > min_length_ref){
|
||||||
|
seen.set(obj, path) }
|
||||||
|
return res }
|
||||||
|
|
||||||
// atomics...
|
// atomics...
|
||||||
// NOTE: these are not stored in seen thus are not re-referenced...
|
// NOTE: these are not stored in seen thus are not re-referenced...
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user