ig-serialize 1.0.5 → 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.5",
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
 
@@ -413,7 +413,7 @@ module.eJSON = {
413
413
  var mode = 'dec'
414
414
  if(str[j] == '0'
415
415
  && 'xXbBoO'.includes(str[j+1])){
416
- mode = str[j+1]
416
+ mode = str[j+1].toLowerCase()
417
417
  j++ }
418
418
  j++
419
419
  while(j < str.length
@@ -432,6 +432,7 @@ module.eJSON = {
432
432
  // exponent...
433
433
  || str[j] == 'e'
434
434
  || str[j] == 'E')){
435
+ // exponent sign...
435
436
  if('eE'.includes(str[j])
436
437
  && '+-'.includes(str[j+1])){
437
438
  j++ }
@@ -613,15 +614,15 @@ module.eJSON = {
613
614
  // directly reference that -- this would eliminate the need for
614
615
  // stage two... (XXX TEST)
615
616
  // ...need to use serialized paths as keys...
616
- recursive: function(state, path, match, str, i, line){
617
- debug.lex('recursive', str, i, line)
617
+ reference: function(state, path, match, str, i, line){
618
+ debug.lex('reference', str, i, line)
618
619
  return this.sequence(
619
620
  state, path, str, i+match.length, line,
620
621
  '>',
621
622
  function(res, index, str, i, line){
622
623
  var obj
623
624
  ;[obj, i, line] = this.array(state, [...path, index], '[', str, i, line)
624
- var rec = state.recursive ??= []
625
+ var rec = state.reference ??= []
625
626
  rec.push([path, obj])
626
627
  return [{}, i, line] }) },
627
628
 
@@ -694,8 +695,8 @@ module.eJSON = {
694
695
  var state = {functions: options.functions}
695
696
  var res = this.value(state, [], str)[0]
696
697
 
697
- // stage 2: link the recursive structures...
698
- for(var [a, b] of state.recursive ?? []){
698
+ // stage 2: link the reference structures...
699
+ for(var [a, b] of state.reference ?? []){
699
700
  this.setItem(res, a, this.getItem(res, b)) }
700
701
 
701
702
  return res },
package/test.js CHANGED
@@ -49,6 +49,8 @@ var setups = test.Setups({
49
49
  // return ['+123', json] },
50
50
  'number-exp': function(assert){
51
51
  return ['1e+100', json] },
52
+ 'number-exp-neg': function(assert){
53
+ return ['1e-100', json] },
52
54
  'number-zero': function(assert){
53
55
  return ['0', json] },
54
56
  'float-a': function(assert){
@@ -98,19 +100,19 @@ var setups = test.Setups({
98
100
  return ['Map([])'] },
99
101
 
100
102
  'function': function(assert){
101
- return ['<FUNCTION[14,(function(){})]>'] },
103
+ return ['<FUNC[14,(function(){})]>'] },
102
104
 
103
105
  // recursive...
104
106
  'array-recursive': function(assert){
105
- return ['[<RECURSIVE[]>]'] },
107
+ return ['[<REF[]>]'] },
106
108
  'object-recursive': function(assert){
107
- return ['{"r":<RECURSIVE[]>}'] },
109
+ return ['{"r":<REF[]>}'] },
108
110
  'set-recursive': function(assert){
109
- return ['Set([<RECURSIVE[]>])'] },
111
+ return ['Set([<REF[]>])'] },
110
112
  'map-recursive-key': function(assert){
111
- return ['Map([[<RECURSIVE[]>,"value"]])'] },
113
+ return ['Map([[<REF[]>,"value"]])'] },
112
114
  'map-recursive-value': function(assert){
113
- return ['Map([["key",<RECURSIVE[]>]])'] },
115
+ return ['Map([["key",<REF[]>]])'] },
114
116
  })
115
117
 
116
118
  test.Modifiers({
@@ -204,19 +206,33 @@ test.Cases({
204
206
  ['123.', '123'],
205
207
  ['+123', '123'],
206
208
  ['123e100', '123e+100'],
209
+ ['123E100', '123e+100'],
207
210
  ['0xff', '255'],
211
+ ['0Xff', '255'],
212
+ ['0o77', '63'],
213
+ ['0O77', '63'],
214
+ ['0b11', '3'],
215
+ ['0B11', '3'],
216
+ // XXX
217
+ //['010', '8'],
218
+ //['080', '80'],
208
219
 
209
220
  // string quotes...
210
221
  ["'abc'", '"abc"'],
211
222
  ['`abc`', '"abc"'],
223
+ /* XXX test new lines...
224
+ [`\`a
225
+ b
226
+ c\``, '"a\\nb\\nc"'],
227
+ //*/
212
228
 
213
229
  // arrays...
214
230
  ['[1,2,]', '[1,2]'],
215
231
 
216
232
  // sparse arrays...
217
- ['[<empty>]', '[,]'],
218
- ['[1,2,<empty>]', '[1,2,,]'],
219
- ['[1,2,<empty>]', '[1,2,<empty>,]'],
233
+ ['[,]', '[<empty>]'],
234
+ ['[1,2,,]', '[1,2,<empty>]'],
235
+ ['[1,2,<empty>,]', '[1,2,<empty>]'],
220
236
  ],
221
237
  'syntax-simplifications': function(assert){
222
238
  var aa, bb