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 +26 -2
- package/building.js +26 -20
- package/package.json +1 -1
- package/processing.js +7 -18
package/README.md
CHANGED
|
@@ -53,12 +53,36 @@ Granular Structured Object Notation.
|
|
|
53
53
|
38
|
|
54
54
|
}
|
|
55
55
|
],
|
|
56
|
-
"
|
|
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
|
|
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(
|
|
124
|
+
context.lineArray.push( indentationText + text );
|
|
125
125
|
}
|
|
126
126
|
else
|
|
127
127
|
{
|
|
128
|
-
let multilineString = getMultilineString( value,
|
|
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;
|
|
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(
|
|
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
|
|
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(
|
|
171
|
+
context.lineArray.push( indentationText + '[' );
|
|
170
172
|
|
|
171
173
|
let elementCount = value.length;
|
|
172
174
|
|
|
173
|
-
for ( let elementIndex = 0;
|
|
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(
|
|
195
|
+
context.lineArray.push( indentationText + ']' );
|
|
192
196
|
}
|
|
193
197
|
else if ( value !== null
|
|
194
198
|
&& typeof value === 'object' )
|
|
195
199
|
{
|
|
196
|
-
context.lineArray.push(
|
|
200
|
+
context.lineArray.push( indentationText + '{' );
|
|
197
201
|
|
|
198
|
-
let
|
|
199
|
-
let keyCount =
|
|
202
|
+
let keyArray = Object.keys( value );
|
|
203
|
+
let keyCount = keyArray.length;
|
|
200
204
|
|
|
201
|
-
for ( let keyIndex = 0;
|
|
205
|
+
for ( let keyIndex = 0;
|
|
206
|
+
keyIndex < keyCount;
|
|
207
|
+
++keyIndex )
|
|
202
208
|
{
|
|
203
|
-
let key =
|
|
204
|
-
let
|
|
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(
|
|
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(
|
|
229
|
+
context.lineArray.push( indentationText + '}' );
|
|
224
230
|
}
|
|
225
231
|
else
|
|
226
232
|
{
|
|
227
|
-
context.lineArray.push(
|
|
233
|
+
context.lineArray.push( indentationText + JSON.stringify( value ) );
|
|
228
234
|
}
|
|
229
235
|
}
|
|
230
236
|
|
package/package.json
CHANGED
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
|
-
|
|
67
|
-
{
|
|
68
|
-
buffer += String.fromCharCode( parseInt( hash.slice( byteIndex, byteIndex + 2 ), 16 ) );
|
|
69
|
-
}
|
|
56
|
+
let byteArray = new Array( 16 );
|
|
70
57
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
58
|
+
for ( let characterIndex = 0;
|
|
59
|
+
characterIndex < 32;
|
|
60
|
+
characterIndex += 2 )
|
|
74
61
|
{
|
|
75
|
-
|
|
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( '+', '-' )
|