senselogic-gson 0.1.4 → 0.1.6
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 +21 -6
- package/building.js +35 -21
- package/package.json +1 -1
- package/test.js +5 -1
package/README.md
CHANGED
|
@@ -10,8 +10,7 @@ Granular Structured Object Notation.
|
|
|
10
10
|
* File inclusions
|
|
11
11
|
* UUID and TUID generation
|
|
12
12
|
* Customizable commands
|
|
13
|
-
* Ultra fast parsing
|
|
14
|
-
* Based on obscure characters
|
|
13
|
+
* Ultra fast parsing based on obscure Unicode characters
|
|
15
14
|
|
|
16
15
|
## Sample
|
|
17
16
|
|
|
@@ -52,7 +51,7 @@ Granular Structured Object Notation.
|
|
|
52
51
|
"age":
|
|
53
52
|
38
|
|
54
53
|
}
|
|
55
|
-
|
|
54
|
+
},
|
|
56
55
|
"personByIdMap":
|
|
57
56
|
{
|
|
58
57
|
"mike":
|
|
@@ -76,7 +75,7 @@ Granular Structured Object Notation.
|
|
|
76
75
|
"age":
|
|
77
76
|
38
|
|
78
77
|
}
|
|
79
|
-
|
|
78
|
+
],
|
|
80
79
|
"escaped":
|
|
81
80
|
"\u2034",
|
|
82
81
|
"uuid":
|
|
@@ -88,10 +87,26 @@ Granular Structured Object Notation.
|
|
|
88
87
|
}
|
|
89
88
|
```
|
|
90
89
|
|
|
90
|
+
## Syntax
|
|
91
|
+
|
|
92
|
+
Multiline strings are enclosed between `‴` characters, and use the `‗` character to represent a non-trimmable space:
|
|
93
|
+
```
|
|
94
|
+
‴first line
|
|
95
|
+
second line
|
|
96
|
+
third line ‗
|
|
97
|
+
‗ fourth line
|
|
98
|
+
fifth line‴
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
Command strings are also enclosed between `‴` characters, but start with a `‼` character:
|
|
102
|
+
* `‴‼#id‴` generates an MD5-based UUID.
|
|
103
|
+
* `‴‼%id‴` generates an MD5-based TUID.
|
|
104
|
+
* `‴‼@path/to/file.gson‴` includes the contents of another GSON file.
|
|
105
|
+
|
|
91
106
|
## Limitations
|
|
92
107
|
|
|
93
|
-
* `‴` must be escaped in string literals.
|
|
94
|
-
* `‼` and `‗` can't be used in string literals.
|
|
108
|
+
* The `‴` character must be escaped in string literals.
|
|
109
|
+
* The `‼` and `‗` characters can't be used in multiline string literals.
|
|
95
110
|
|
|
96
111
|
## Version
|
|
97
112
|
|
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
|
{
|
|
@@ -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,6 +110,8 @@ 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 = ''
|
|
@@ -115,17 +119,18 @@ function buildGsonString(
|
|
|
115
119
|
{
|
|
116
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;
|
|
128
|
+
let text = '‴' + getEscapedLine( value, primedTextIsEscaped ) + '‴' + lineSuffix;
|
|
124
129
|
context.lineArray.push( indentationText + text );
|
|
125
130
|
}
|
|
126
131
|
else
|
|
127
132
|
{
|
|
128
|
-
let multilineString = getMultilineString( value, indentationText
|
|
133
|
+
let multilineString = getMultilineString( value, primedTextIsEscaped, indentationText );
|
|
129
134
|
let lineArray = multilineString.split( '\n' );
|
|
130
135
|
let lastIndex = lineArray.length - 1;
|
|
131
136
|
|
|
@@ -147,7 +152,8 @@ function buildGsonString(
|
|
|
147
152
|
}
|
|
148
153
|
else
|
|
149
154
|
{
|
|
150
|
-
let text =
|
|
155
|
+
let text = '"' + getEscapedLine( value, primedTextIsEscaped ) + '"' + lineSuffix;
|
|
156
|
+
|
|
151
157
|
context.lineArray.push( indentationText + text );
|
|
152
158
|
}
|
|
153
159
|
}
|
|
@@ -156,6 +162,8 @@ function buildGsonString(
|
|
|
156
162
|
|
|
157
163
|
function buildGsonValue(
|
|
158
164
|
value,
|
|
165
|
+
primedTextIsGenerated = true,
|
|
166
|
+
primedTextIsEscaped = true,
|
|
159
167
|
context,
|
|
160
168
|
level
|
|
161
169
|
)
|
|
@@ -164,7 +172,7 @@ function buildGsonValue(
|
|
|
164
172
|
|
|
165
173
|
if ( typeof value === 'string' )
|
|
166
174
|
{
|
|
167
|
-
buildGsonString( value, context, level, '' );
|
|
175
|
+
buildGsonString( value, primedTextIsGenerated, primedTextIsEscaped, context, level, '' );
|
|
168
176
|
}
|
|
169
177
|
else if ( Array.isArray( value ) )
|
|
170
178
|
{
|
|
@@ -181,6 +189,8 @@ function buildGsonValue(
|
|
|
181
189
|
|
|
182
190
|
buildGsonValue(
|
|
183
191
|
element,
|
|
192
|
+
primedTextIsGenerated,
|
|
193
|
+
primedTextIsEscaped,
|
|
184
194
|
context,
|
|
185
195
|
level + 1
|
|
186
196
|
);
|
|
@@ -215,6 +225,8 @@ function buildGsonValue(
|
|
|
215
225
|
|
|
216
226
|
buildGsonValue(
|
|
217
227
|
value[ key ],
|
|
228
|
+
primedTextIsGenerated,
|
|
229
|
+
primedTextIsEscaped,
|
|
218
230
|
context,
|
|
219
231
|
valueIndentLevel
|
|
220
232
|
);
|
|
@@ -238,9 +250,9 @@ function buildGsonValue(
|
|
|
238
250
|
|
|
239
251
|
export function buildGsonText(
|
|
240
252
|
value,
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
253
|
+
primedTextIsGenerated = true,
|
|
254
|
+
primedTextIsEscaped = true,
|
|
255
|
+
indentationSpaceCount = 4
|
|
244
256
|
)
|
|
245
257
|
{
|
|
246
258
|
let context =
|
|
@@ -251,6 +263,8 @@ export function buildGsonText(
|
|
|
251
263
|
|
|
252
264
|
buildGsonValue(
|
|
253
265
|
value,
|
|
266
|
+
primedTextIsGenerated,
|
|
267
|
+
primedTextIsEscaped,
|
|
254
268
|
context,
|
|
255
269
|
0
|
|
256
270
|
);
|
package/package.json
CHANGED
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 );
|