From 2fb5bc882d666caf6d8251a108cf60563aa72a47 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Wed, 14 Jan 2026 18:28:56 +0300 Subject: [PATCH] tweaking the options... Signed-off-by: Alex A. Naanou --- README.md | 26 ++++++++++++++------------ package.json | 2 +- serialize.js | 20 +++++++++++++------- 3 files changed, 28 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 9982b57..568e8e8 100644 --- a/README.md +++ b/README.md @@ -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` / `.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), diff --git a/package.json b/package.json index c011790..d32410f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ig-serialize", - "version": "1.1.0", + "version": "1.2.0", "description": "experimental extended json serializaion...", "main": "serialize.js", "scripts": { diff --git a/serialize.js b/serialize.js index 0b27c36..456357f 100644 --- a/serialize.js +++ b/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 = 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...