tweaking the options...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2026-01-14 18:28:56 +03:00
parent 6ba464d3d4
commit 2fb5bc882d
3 changed files with 28 additions and 20 deletions

View File

@ -51,18 +51,6 @@ Thus, care must be taken when serializing structures containing function.
## 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(..)`
### `deserialize(..)` / 'eJSON.parse(..)'
@ -72,6 +60,20 @@ Default: 96
### `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
The output of `.serialize(..)` is a strict superset of [standard JSON](https://www.json.org/json-en.html),

View File

@ -1,6 +1,6 @@
{
"name": "ig-serialize",
"version": "1.1.0",
"version": "1.2.0",
"description": "experimental extended json serializaion...",
"main": "serialize.js",
"scripts": {

View File

@ -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 =
module._serialize =
function(obj, path=[], seen=new Map(), indent, depth=0, options={}){
var string_length_ref =
options.string_length_ref
?? module.STRING_LENGTH_REF
var min_length_ref =
options.min_length_ref
?? module.MIN_LENGTH_REF
min_length_ref =
min_length_ref <= 0 ?
Infinity
: min_length_ref
// reference...
var p = seen.get(obj)
@ -171,12 +175,14 @@ function(obj, path=[], seen=new Map(), indent, depth=0, options={}){
// long strings...
// NOTE: this saves on output size...
if(typeof(obj) == 'string'
&& obj.length > string_length_ref){
&& obj.length > min_length_ref){
seen.set(obj, path) }
// BigInt...
if(typeof(obj) == 'bigint'){
seen.set(obj, path)
return obj.toString() +'n' }
var res = obj.toString() +'n'
if(res.length > min_length_ref){
seen.set(obj, path) }
return res }
// atomics...
// NOTE: these are not stored in seen thus are not re-referenced...