ig-serialize 1.0.6 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -65,6 +65,8 @@ Extensions to JSON:
65
65
 
66
66
  ### Recursion
67
67
 
68
+ If an object is encountered
69
+
68
70
  ### null types
69
71
 
70
72
  ### BigInt
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ig-serialize",
3
- "version": "1.0.6",
3
+ "version": "1.1.0",
4
4
  "description": "experimental extended json serializaion...",
5
5
  "main": "serialize.js",
6
6
  "scripts": {
package/serialize.js CHANGED
@@ -51,9 +51,9 @@ var NAN = 'NaN'
51
51
  var INFINITY = 'Infinity'
52
52
  var NEG_INFINITY = '-Infinity'
53
53
 
54
- var RECURSIVE = '<RECURSIVE%>'
54
+ var REFERENCE = '<REF%>'
55
55
 
56
- var FUNCTION = '<FUNCTION[%]>'
56
+ var FUNCTION = '<FUNC[%]>'
57
57
 
58
58
 
59
59
 
@@ -77,7 +77,7 @@ var debug = {
77
77
 
78
78
  //---------------------------------------------------------------------
79
79
 
80
- module.STRING_LENGTH_REF = RECURSIVE.length * 8
80
+ module.STRING_LENGTH_REF = REFERENCE.length * 8
81
81
 
82
82
 
83
83
  //
@@ -148,11 +148,11 @@ function(obj, path=[], seen=new Map(), indent, depth=0, options={}){
148
148
  options.string_length_ref
149
149
  ?? module.STRING_LENGTH_REF
150
150
 
151
- // recursive...
151
+ // reference...
152
152
  var p = seen.get(obj)
153
153
  if(p != null){
154
154
  // NOTE: _serialize(..) is always printed flat here, regardless of indent/depth...
155
- return RECURSIVE.replace('%', _serialize(p)) }
155
+ return REFERENCE.replace('%', _serialize(p)) }
156
156
 
157
157
  // functions...
158
158
  // NOTE: we are storing function length to avoid parsing the function...
@@ -260,7 +260,7 @@ function(obj, indent, depth=0, options){
260
260
  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
261
261
 
262
262
  // XXX better error handling...
263
- // XXX try and make this single stage (see notes for : .recursive(..))
263
+ // XXX try and make this single stage (see notes for : .reference(..))
264
264
  var eJSON =
265
265
  module.eJSON = {
266
266
  chars: {
@@ -287,9 +287,9 @@ module.eJSON = {
287
287
  NaN: NaN,
288
288
 
289
289
  '<empty>': 'empty',
290
- '<RECURSIVE': 'recursive',
290
+ '<REF': 'reference',
291
291
 
292
- '<FUNCTION[': 'func',
292
+ '<FUNC[': 'func',
293
293
  },
294
294
 
295
295
 
@@ -614,15 +614,15 @@ module.eJSON = {
614
614
  // directly reference that -- this would eliminate the need for
615
615
  // stage two... (XXX TEST)
616
616
  // ...need to use serialized paths as keys...
617
- recursive: function(state, path, match, str, i, line){
618
- debug.lex('recursive', str, i, line)
617
+ reference: function(state, path, match, str, i, line){
618
+ debug.lex('reference', str, i, line)
619
619
  return this.sequence(
620
620
  state, path, str, i+match.length, line,
621
621
  '>',
622
622
  function(res, index, str, i, line){
623
623
  var obj
624
624
  ;[obj, i, line] = this.array(state, [...path, index], '[', str, i, line)
625
- var rec = state.recursive ??= []
625
+ var rec = state.reference ??= []
626
626
  rec.push([path, obj])
627
627
  return [{}, i, line] }) },
628
628
 
@@ -695,8 +695,8 @@ module.eJSON = {
695
695
  var state = {functions: options.functions}
696
696
  var res = this.value(state, [], str)[0]
697
697
 
698
- // stage 2: link the recursive structures...
699
- for(var [a, b] of state.recursive ?? []){
698
+ // stage 2: link the reference structures...
699
+ for(var [a, b] of state.reference ?? []){
700
700
  this.setItem(res, a, this.getItem(res, b)) }
701
701
 
702
702
  return res },
package/test.js CHANGED
@@ -100,19 +100,19 @@ var setups = test.Setups({
100
100
  return ['Map([])'] },
101
101
 
102
102
  'function': function(assert){
103
- return ['<FUNCTION[14,(function(){})]>'] },
103
+ return ['<FUNC[14,(function(){})]>'] },
104
104
 
105
105
  // recursive...
106
106
  'array-recursive': function(assert){
107
- return ['[<RECURSIVE[]>]'] },
107
+ return ['[<REF[]>]'] },
108
108
  'object-recursive': function(assert){
109
- return ['{"r":<RECURSIVE[]>}'] },
109
+ return ['{"r":<REF[]>}'] },
110
110
  'set-recursive': function(assert){
111
- return ['Set([<RECURSIVE[]>])'] },
111
+ return ['Set([<REF[]>])'] },
112
112
  'map-recursive-key': function(assert){
113
- return ['Map([[<RECURSIVE[]>,"value"]])'] },
113
+ return ['Map([[<REF[]>,"value"]])'] },
114
114
  'map-recursive-value': function(assert){
115
- return ['Map([["key",<RECURSIVE[]>]])'] },
115
+ return ['Map([["key",<REF[]>]])'] },
116
116
  })
117
117
 
118
118
  test.Modifiers({
@@ -213,19 +213,26 @@ test.Cases({
213
213
  ['0O77', '63'],
214
214
  ['0b11', '3'],
215
215
  ['0B11', '3'],
216
+ // XXX
217
+ //['010', '8'],
218
+ //['080', '80'],
216
219
 
217
220
  // string quotes...
218
- // XXX test new lines...
219
221
  ["'abc'", '"abc"'],
220
222
  ['`abc`', '"abc"'],
223
+ /* XXX test new lines...
224
+ [`\`a
225
+ b
226
+ c\``, '"a\\nb\\nc"'],
227
+ //*/
221
228
 
222
229
  // arrays...
223
230
  ['[1,2,]', '[1,2]'],
224
231
 
225
232
  // sparse arrays...
226
- ['[<empty>]', '[,]'],
227
- ['[1,2,<empty>]', '[1,2,,]'],
228
- ['[1,2,<empty>]', '[1,2,<empty>,]'],
233
+ ['[,]', '[<empty>]'],
234
+ ['[1,2,,]', '[1,2,<empty>]'],
235
+ ['[1,2,<empty>,]', '[1,2,<empty>]'],
229
236
  ],
230
237
  'syntax-simplifications': function(assert){
231
238
  var aa, bb