senselogic-gson 0.1.3 → 0.1.5
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 +60 -40
- package/package.json +1 -1
- package/processing.js +7 -18
- package/test.js +5 -1
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
|
@@ -19,25 +19,27 @@ export function getIndentationText(
|
|
|
19
19
|
// ~~
|
|
20
20
|
|
|
21
21
|
function getEscapedLine(
|
|
22
|
-
|
|
22
|
+
line,
|
|
23
|
+
primedTextIsEscaped = true
|
|
23
24
|
)
|
|
24
25
|
{
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
26
|
+
let escapedLine = JSON.stringify( line ).slice( 1, -1 ).replaceAll( '‴', '\\u2034' );
|
|
27
|
+
|
|
28
|
+
if ( primedTextIsEscaped )
|
|
29
|
+
{
|
|
30
|
+
return escapedLine.replaceAll( '‼', '\\u203C' ).replaceAll( '‗', '\\u2017' );
|
|
31
|
+
}
|
|
32
|
+
else
|
|
33
|
+
{
|
|
34
|
+
return escapedLine;
|
|
35
|
+
}
|
|
35
36
|
}
|
|
36
37
|
|
|
37
38
|
// ~~
|
|
38
39
|
|
|
39
40
|
function getMultilineString(
|
|
40
41
|
value,
|
|
42
|
+
primedTextIsEscaped = true,
|
|
41
43
|
indentationText
|
|
42
44
|
)
|
|
43
45
|
{
|
|
@@ -45,8 +47,8 @@ function getMultilineString(
|
|
|
45
47
|
let lineCount = lineArray.length;
|
|
46
48
|
let multilineString = indentationText + '‴';
|
|
47
49
|
|
|
48
|
-
for ( let lineIndex = 0;
|
|
49
|
-
lineIndex < lineCount;
|
|
50
|
+
for ( let lineIndex = 0;
|
|
51
|
+
lineIndex < lineCount;
|
|
50
52
|
++lineIndex )
|
|
51
53
|
{
|
|
52
54
|
let line = lineArray[ lineIndex ];
|
|
@@ -84,7 +86,7 @@ function getMultilineString(
|
|
|
84
86
|
lineSuffix = '';
|
|
85
87
|
}
|
|
86
88
|
|
|
87
|
-
let multilineStringLine = linePrefix + getEscapedLine( lineContent ) + lineSuffix;
|
|
89
|
+
let multilineStringLine = linePrefix + getEscapedLine( lineContent, primedTextIsEscaped ) + lineSuffix;
|
|
88
90
|
|
|
89
91
|
if ( lineIndex === lineCount - 1 )
|
|
90
92
|
{
|
|
@@ -108,28 +110,33 @@ function getMultilineString(
|
|
|
108
110
|
|
|
109
111
|
function buildGsonString(
|
|
110
112
|
value,
|
|
113
|
+
primedTextIsGenerated = true,
|
|
114
|
+
primedTextIsEscaped = true,
|
|
111
115
|
context,
|
|
112
116
|
level,
|
|
113
117
|
lineSuffix = ''
|
|
114
118
|
)
|
|
115
119
|
{
|
|
116
|
-
let
|
|
120
|
+
let indentationText = getIndentationText( level * context.levelSpaceCount );
|
|
117
121
|
|
|
118
|
-
if (
|
|
119
|
-
|
|
122
|
+
if ( primedTextIsGenerated
|
|
123
|
+
&& ( value.startsWith( '‼' )
|
|
124
|
+
|| value.includes( '\n' ) ) )
|
|
120
125
|
{
|
|
121
126
|
if ( value.startsWith( '‼' ) )
|
|
122
127
|
{
|
|
123
|
-
let text = '‴' + getEscapedLine( value ) + '‴' + lineSuffix;
|
|
124
|
-
context.lineArray.push(
|
|
128
|
+
let text = '‴' + getEscapedLine( value, primedTextIsEscaped ) + '‴' + lineSuffix;
|
|
129
|
+
context.lineArray.push( indentationText + text );
|
|
125
130
|
}
|
|
126
131
|
else
|
|
127
132
|
{
|
|
128
|
-
let multilineString = getMultilineString( value,
|
|
133
|
+
let multilineString = getMultilineString( value, primedTextIsEscaped, indentationText );
|
|
129
134
|
let lineArray = multilineString.split( '\n' );
|
|
130
135
|
let lastIndex = lineArray.length - 1;
|
|
131
136
|
|
|
132
|
-
for ( let lineIndex = 0;
|
|
137
|
+
for ( let lineIndex = 0;
|
|
138
|
+
lineIndex < lineArray.length;
|
|
139
|
+
++lineIndex )
|
|
133
140
|
{
|
|
134
141
|
let line = lineArray[ lineIndex ];
|
|
135
142
|
|
|
@@ -145,8 +152,9 @@ function buildGsonString(
|
|
|
145
152
|
}
|
|
146
153
|
else
|
|
147
154
|
{
|
|
148
|
-
let text =
|
|
149
|
-
|
|
155
|
+
let text = '"' + getEscapedLine( value, primedTextIsEscaped ) + '"' + lineSuffix;
|
|
156
|
+
|
|
157
|
+
context.lineArray.push( indentationText + text );
|
|
150
158
|
}
|
|
151
159
|
}
|
|
152
160
|
|
|
@@ -154,29 +162,35 @@ function buildGsonString(
|
|
|
154
162
|
|
|
155
163
|
function buildGsonValue(
|
|
156
164
|
value,
|
|
165
|
+
primedTextIsGenerated = true,
|
|
166
|
+
primedTextIsEscaped = true,
|
|
157
167
|
context,
|
|
158
168
|
level
|
|
159
169
|
)
|
|
160
170
|
{
|
|
161
|
-
let
|
|
171
|
+
let indentationText = getIndentationText( level * context.levelSpaceCount );
|
|
162
172
|
|
|
163
173
|
if ( typeof value === 'string' )
|
|
164
174
|
{
|
|
165
|
-
buildGsonString( value, context, level, '' );
|
|
175
|
+
buildGsonString( value, primedTextIsGenerated, primedTextIsEscaped, context, level, '' );
|
|
166
176
|
}
|
|
167
177
|
else if ( Array.isArray( value ) )
|
|
168
178
|
{
|
|
169
|
-
context.lineArray.push(
|
|
179
|
+
context.lineArray.push( indentationText + '[' );
|
|
170
180
|
|
|
171
181
|
let elementCount = value.length;
|
|
172
182
|
|
|
173
|
-
for ( let elementIndex = 0;
|
|
183
|
+
for ( let elementIndex = 0;
|
|
184
|
+
elementIndex < elementCount;
|
|
185
|
+
++elementIndex )
|
|
174
186
|
{
|
|
175
187
|
let element = value[ elementIndex ];
|
|
176
188
|
let lineSuffix = ( elementIndex < elementCount - 1 ) ? ',' : '';
|
|
177
189
|
|
|
178
190
|
buildGsonValue(
|
|
179
191
|
element,
|
|
192
|
+
primedTextIsGenerated,
|
|
193
|
+
primedTextIsEscaped,
|
|
180
194
|
context,
|
|
181
195
|
level + 1
|
|
182
196
|
);
|
|
@@ -188,27 +202,31 @@ function buildGsonValue(
|
|
|
188
202
|
}
|
|
189
203
|
}
|
|
190
204
|
|
|
191
|
-
context.lineArray.push(
|
|
205
|
+
context.lineArray.push( indentationText + ']' );
|
|
192
206
|
}
|
|
193
207
|
else if ( value !== null
|
|
194
208
|
&& typeof value === 'object' )
|
|
195
209
|
{
|
|
196
|
-
context.lineArray.push(
|
|
210
|
+
context.lineArray.push( indentationText + '{' );
|
|
197
211
|
|
|
198
|
-
let
|
|
199
|
-
let keyCount =
|
|
212
|
+
let keyArray = Object.keys( value );
|
|
213
|
+
let keyCount = keyArray.length;
|
|
200
214
|
|
|
201
|
-
for ( let keyIndex = 0;
|
|
215
|
+
for ( let keyIndex = 0;
|
|
216
|
+
keyIndex < keyCount;
|
|
217
|
+
++keyIndex )
|
|
202
218
|
{
|
|
203
|
-
let key =
|
|
204
|
-
let
|
|
219
|
+
let key = keyArray[ keyIndex ];
|
|
220
|
+
let keyIndentationText = getIndentationText( ( level + 1 ) * context.levelSpaceCount );
|
|
205
221
|
let valueIndentLevel = level + 2;
|
|
206
222
|
let lineSuffix = ( keyIndex < keyCount - 1 ) ? ',' : '';
|
|
207
223
|
|
|
208
|
-
context.lineArray.push(
|
|
224
|
+
context.lineArray.push( keyIndentationText + JSON.stringify( key ) + ':' );
|
|
209
225
|
|
|
210
226
|
buildGsonValue(
|
|
211
227
|
value[ key ],
|
|
228
|
+
primedTextIsGenerated,
|
|
229
|
+
primedTextIsEscaped,
|
|
212
230
|
context,
|
|
213
231
|
valueIndentLevel
|
|
214
232
|
);
|
|
@@ -220,11 +238,11 @@ function buildGsonValue(
|
|
|
220
238
|
}
|
|
221
239
|
}
|
|
222
240
|
|
|
223
|
-
context.lineArray.push(
|
|
241
|
+
context.lineArray.push( indentationText + '}' );
|
|
224
242
|
}
|
|
225
243
|
else
|
|
226
244
|
{
|
|
227
|
-
context.lineArray.push(
|
|
245
|
+
context.lineArray.push( indentationText + JSON.stringify( value ) );
|
|
228
246
|
}
|
|
229
247
|
}
|
|
230
248
|
|
|
@@ -232,9 +250,9 @@ function buildGsonValue(
|
|
|
232
250
|
|
|
233
251
|
export function buildGsonText(
|
|
234
252
|
value,
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
253
|
+
primedTextIsGenerated = true,
|
|
254
|
+
primedTextIsEscaped = true,
|
|
255
|
+
indentationSpaceCount = 4
|
|
238
256
|
)
|
|
239
257
|
{
|
|
240
258
|
let context =
|
|
@@ -245,6 +263,8 @@ export function buildGsonText(
|
|
|
245
263
|
|
|
246
264
|
buildGsonValue(
|
|
247
265
|
value,
|
|
266
|
+
primedTextIsGenerated,
|
|
267
|
+
primedTextIsEscaped,
|
|
248
268
|
context,
|
|
249
269
|
0
|
|
250
270
|
);
|
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( '+', '-' )
|
package/test.js
CHANGED
|
@@ -19,9 +19,13 @@ jsonText = readGsonFileText( '../../../DATA/test.gson', false );
|
|
|
19
19
|
console.log( jsonText );
|
|
20
20
|
writeFileText( 'OUT/unprocessed_test.json', jsonText );
|
|
21
21
|
|
|
22
|
+
gsonText = buildGsonText( jsonValue, false );
|
|
23
|
+
console.log( gsonText );
|
|
24
|
+
writeFileText( 'OUT/unprocessed_test.gson', gsonText, 4 );
|
|
25
|
+
|
|
22
26
|
jsonValue = readGsonFileValue( '../../../DATA/test.gson', false );
|
|
23
27
|
console.log( JSON.stringify( jsonValue ) );
|
|
24
28
|
|
|
25
|
-
gsonText = buildGsonText( jsonValue );
|
|
29
|
+
gsonText = buildGsonText( jsonValue, true, false );
|
|
26
30
|
console.log( gsonText );
|
|
27
31
|
writeFileText( 'OUT/unprocessed_test.gson', gsonText, 4 );
|