senselogic-gson 0.1.3 → 0.1.4

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
@@ -53,12 +53,36 @@ Granular Structured Object Notation.
53
53
  38
54
54
  }
55
55
  ],
56
- "escaped":
56
+ "personByIdMap":
57
+ {
58
+ "mike":
59
+ {
60
+ "name":
61
+ "Mike",
62
+ "age":
63
+ 35
64
+ },
65
+ "nina":
66
+ {
67
+ "name":
68
+ "Nina",
69
+ "age":
70
+ 32
71
+ },
72
+ "pete":
73
+ {
74
+ "name":
75
+ "Pete",
76
+ "age":
77
+ 38
78
+ }
79
+ },
80
+ "escaped":
57
81
  "\u2034",
58
82
  "uuid":
59
83
  ‴‼#jack‴,
60
84
  "tuid":
61
- ‴‼%jack‴,
85
+ ‴‼%jack‴,
62
86
  "included":
63
87
  ‴‼@included.gson‴
64
88
  }
package/building.js CHANGED
@@ -45,8 +45,8 @@ function getMultilineString(
45
45
  let lineCount = lineArray.length;
46
46
  let multilineString = indentationText + '‴';
47
47
 
48
- for ( let lineIndex = 0;
49
- lineIndex < lineCount;
48
+ for ( let lineIndex = 0;
49
+ lineIndex < lineCount;
50
50
  ++lineIndex )
51
51
  {
52
52
  let line = lineArray[ lineIndex ];
@@ -113,7 +113,7 @@ function buildGsonString(
113
113
  lineSuffix = ''
114
114
  )
115
115
  {
116
- let indent = getIndentationText( level * context.levelSpaceCount );
116
+ let indentationText = getIndentationText( level * context.levelSpaceCount );
117
117
 
118
118
  if ( value.startsWith( '‼' )
119
119
  || value.includes( '\n' ) )
@@ -121,15 +121,17 @@ function buildGsonString(
121
121
  if ( value.startsWith( '‼' ) )
122
122
  {
123
123
  let text = '‴' + getEscapedLine( value ) + '‴' + lineSuffix;
124
- context.lineArray.push( indent + text );
124
+ context.lineArray.push( indentationText + text );
125
125
  }
126
126
  else
127
127
  {
128
- let multilineString = getMultilineString( value, indent );
128
+ let multilineString = getMultilineString( value, indentationText );
129
129
  let lineArray = multilineString.split( '\n' );
130
130
  let lastIndex = lineArray.length - 1;
131
131
 
132
- for ( let lineIndex = 0; lineIndex < lineArray.length; ++lineIndex )
132
+ for ( let lineIndex = 0;
133
+ lineIndex < lineArray.length;
134
+ ++lineIndex )
133
135
  {
134
136
  let line = lineArray[ lineIndex ];
135
137
 
@@ -146,7 +148,7 @@ function buildGsonString(
146
148
  else
147
149
  {
148
150
  let text = JSON.stringify( value ) + lineSuffix;
149
- context.lineArray.push( indent + text );
151
+ context.lineArray.push( indentationText + text );
150
152
  }
151
153
  }
152
154
 
@@ -158,7 +160,7 @@ function buildGsonValue(
158
160
  level
159
161
  )
160
162
  {
161
- let indent = getIndentationText( level * context.levelSpaceCount );
163
+ let indentationText = getIndentationText( level * context.levelSpaceCount );
162
164
 
163
165
  if ( typeof value === 'string' )
164
166
  {
@@ -166,11 +168,13 @@ function buildGsonValue(
166
168
  }
167
169
  else if ( Array.isArray( value ) )
168
170
  {
169
- context.lineArray.push( indent + '[' );
171
+ context.lineArray.push( indentationText + '[' );
170
172
 
171
173
  let elementCount = value.length;
172
174
 
173
- for ( let elementIndex = 0; elementIndex < elementCount; ++elementIndex )
175
+ for ( let elementIndex = 0;
176
+ elementIndex < elementCount;
177
+ ++elementIndex )
174
178
  {
175
179
  let element = value[ elementIndex ];
176
180
  let lineSuffix = ( elementIndex < elementCount - 1 ) ? ',' : '';
@@ -188,24 +192,26 @@ function buildGsonValue(
188
192
  }
189
193
  }
190
194
 
191
- context.lineArray.push( indent + ']' );
195
+ context.lineArray.push( indentationText + ']' );
192
196
  }
193
197
  else if ( value !== null
194
198
  && typeof value === 'object' )
195
199
  {
196
- context.lineArray.push( indent + '{' );
200
+ context.lineArray.push( indentationText + '{' );
197
201
 
198
- let keys = Object.keys( value );
199
- let keyCount = keys.length;
202
+ let keyArray = Object.keys( value );
203
+ let keyCount = keyArray.length;
200
204
 
201
- for ( let keyIndex = 0; keyIndex < keyCount; ++keyIndex )
205
+ for ( let keyIndex = 0;
206
+ keyIndex < keyCount;
207
+ ++keyIndex )
202
208
  {
203
- let key = keys[ keyIndex ];
204
- let keyIndent = getIndentationText( ( level + 1 ) * context.levelSpaceCount );
209
+ let key = keyArray[ keyIndex ];
210
+ let keyIndentationText = getIndentationText( ( level + 1 ) * context.levelSpaceCount );
205
211
  let valueIndentLevel = level + 2;
206
212
  let lineSuffix = ( keyIndex < keyCount - 1 ) ? ',' : '';
207
213
 
208
- context.lineArray.push( keyIndent + JSON.stringify( key ) + ':' );
214
+ context.lineArray.push( keyIndentationText + JSON.stringify( key ) + ':' );
209
215
 
210
216
  buildGsonValue(
211
217
  value[ key ],
@@ -220,11 +226,11 @@ function buildGsonValue(
220
226
  }
221
227
  }
222
228
 
223
- context.lineArray.push( indent + '}' );
229
+ context.lineArray.push( indentationText + '}' );
224
230
  }
225
231
  else
226
232
  {
227
- context.lineArray.push( indent + JSON.stringify( value ) );
233
+ context.lineArray.push( indentationText + JSON.stringify( value ) );
228
234
  }
229
235
  }
230
236
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "senselogic-gson",
3
3
  "description": "Granular Structured Object Notation.",
4
- "version": "0.1.3",
4
+ "version": "0.1.4",
5
5
  "author": "Eric Pelzer <ecstatic.coder@gmail.com>",
6
6
  "license": "LGPL-3.0-only",
7
7
  "repository": {
package/processing.js CHANGED
@@ -2,11 +2,6 @@
2
2
 
3
3
  import md5 from 'md5';
4
4
 
5
- // -- CONSTANTS
6
-
7
- const
8
- isBrowser = ( typeof window !== 'undefined' && typeof window.document !== 'undefined' );
9
-
10
5
  // -- FUNCTIONS
11
6
 
12
7
  export function getTextHash(
@@ -57,24 +52,18 @@ export function getTextTuid(
57
52
  else
58
53
  {
59
54
  let hash = md5( text );
60
- let tuid = '';
61
-
62
- if ( isBrowser )
63
- {
64
- let buffer = '';
65
55
 
66
- for ( let byteIndex = 0; byteIndex < hash.length; byteIndex += 2 )
67
- {
68
- buffer += String.fromCharCode( parseInt( hash.slice( byteIndex, byteIndex + 2 ), 16 ) );
69
- }
56
+ let byteArray = new Array( 16 );
70
57
 
71
- tuid = btoa( buffer );
72
- }
73
- else
58
+ for ( let characterIndex = 0;
59
+ characterIndex < 32;
60
+ characterIndex += 2 )
74
61
  {
75
- tuid = Buffer.from( hash, 'hex' ).toString( 'base64' );
62
+ byteArray[ characterIndex >> 1 ] = String.fromCharCode( parseInt( hash.slice( characterIndex, characterIndex + 2 ), 16 ) );
76
63
  }
77
64
 
65
+ let tuid = btoa( byteArray.join( '' ) );
66
+
78
67
  return (
79
68
  tuid
80
69
  .replaceAll( '+', '-' )