diff --git a/README.md b/README.md index b52aa5e..96498a4 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,8 @@ Extensions to JSON: ### Recursion +If an object is encountered + ### null types ### BigInt diff --git a/package.json b/package.json index c964371..27469cc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ig-serialize", - "version": "1.0.6", + "version": "1.1.0", "description": "experimental extended json serializaion...", "main": "serialize.js", "scripts": { diff --git a/serialize.js b/serialize.js index 7c8c524..192b967 100644 --- a/serialize.js +++ b/serialize.js @@ -51,9 +51,9 @@ var NAN = 'NaN' var INFINITY = 'Infinity' var NEG_INFINITY = '-Infinity' -var RECURSIVE = '' +var REFERENCE = '' -var FUNCTION = '' +var FUNCTION = '' @@ -77,7 +77,7 @@ var debug = { //--------------------------------------------------------------------- -module.STRING_LENGTH_REF = RECURSIVE.length * 8 +module.STRING_LENGTH_REF = REFERENCE.length * 8 // @@ -148,11 +148,11 @@ function(obj, path=[], seen=new Map(), indent, depth=0, options={}){ options.string_length_ref ?? module.STRING_LENGTH_REF - // recursive... + // reference... var p = seen.get(obj) if(p != null){ // NOTE: _serialize(..) is always printed flat here, regardless of indent/depth... - return RECURSIVE.replace('%', _serialize(p)) } + return REFERENCE.replace('%', _serialize(p)) } // functions... // NOTE: we are storing function length to avoid parsing the function... @@ -260,7 +260,7 @@ function(obj, indent, depth=0, options){ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // XXX better error handling... -// XXX try and make this single stage (see notes for : .recursive(..)) +// XXX try and make this single stage (see notes for : .reference(..)) var eJSON = module.eJSON = { chars: { @@ -287,9 +287,9 @@ module.eJSON = { NaN: NaN, '': 'empty', - '', function(res, index, str, i, line){ var obj ;[obj, i, line] = this.array(state, [...path, index], '[', str, i, line) - var rec = state.recursive ??= [] + var rec = state.reference ??= [] rec.push([path, obj]) return [{}, i, line] }) }, @@ -695,8 +695,8 @@ module.eJSON = { var state = {functions: options.functions} var res = this.value(state, [], str)[0] - // stage 2: link the recursive structures... - for(var [a, b] of state.recursive ?? []){ + // stage 2: link the reference structures... + for(var [a, b] of state.reference ?? []){ this.setItem(res, a, this.getItem(res, b)) } return res }, diff --git a/test.js b/test.js index 7b7025f..f4ceab6 100755 --- a/test.js +++ b/test.js @@ -100,19 +100,19 @@ var setups = test.Setups({ return ['Map([])'] }, 'function': function(assert){ - return [''] }, + return [''] }, // recursive... 'array-recursive': function(assert){ - return ['[]'] }, + return ['[]'] }, 'object-recursive': function(assert){ - return ['{"r":}'] }, + return ['{"r":}'] }, 'set-recursive': function(assert){ - return ['Set([])'] }, + return ['Set([])'] }, 'map-recursive-key': function(assert){ - return ['Map([[,"value"]])'] }, + return ['Map([[,"value"]])'] }, 'map-recursive-value': function(assert){ - return ['Map([["key",]])'] }, + return ['Map([["key",]])'] }, }) test.Modifiers({