senselogic-gson 0.1.10 → 0.3.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 +1 -1
- package/fetching.js +7 -3
- package/index.js +0 -8
- package/package.json +1 -4
- package/reading.js +0 -107
- package/test.js +0 -31
- package/writing.js +0 -24
package/README.md
CHANGED
package/fetching.js
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
// -- IMPORTS
|
|
2
|
+
|
|
3
|
+
import { processPrimedText } from "./processing.js";
|
|
4
|
+
|
|
1
5
|
// -- FUNCTIONS
|
|
2
6
|
|
|
3
7
|
export async function fetchFileText(
|
|
@@ -25,9 +29,9 @@ async function getUnprimedFetchedText(
|
|
|
25
29
|
&& primedText.startsWith( "‼@" ) )
|
|
26
30
|
{
|
|
27
31
|
let filePath = folderPath + primedText.slice( 2 );
|
|
28
|
-
let fileText = fetchFileTextFunction( filePath );
|
|
32
|
+
let fileText = await fetchFileTextFunction( filePath );
|
|
29
33
|
|
|
30
|
-
return await getFetchedJsonText( fileText, filePath,
|
|
34
|
+
return await getFetchedJsonText( fileText, filePath, fetchFileTextFunction, processPrimedTextFunction, primedTextIsProcessed );
|
|
31
35
|
}
|
|
32
36
|
else if ( primedTextIsProcessed
|
|
33
37
|
&& processPrimedTextFunction !== null
|
|
@@ -89,7 +93,7 @@ export async function fetchGsonFileText(
|
|
|
89
93
|
{
|
|
90
94
|
let gsonText = await fetchFileTextFunction( filePath );
|
|
91
95
|
|
|
92
|
-
return await getFetchedJsonText( gsonText, filePath,
|
|
96
|
+
return await getFetchedJsonText( gsonText, filePath, fetchFileTextFunction, processPrimedTextFunction, primedTextIsProcessed );
|
|
93
97
|
}
|
|
94
98
|
|
|
95
99
|
// ~~
|
package/index.js
CHANGED
|
@@ -3,9 +3,7 @@
|
|
|
3
3
|
import { buildGsonText } from "./building.js";
|
|
4
4
|
import { haveSameValue } from "./equivalence.js";
|
|
5
5
|
import { fetchFileText, getFetchedJsonText, fetchGsonFileText, fetchGsonFileValue } from "./fetching.js";
|
|
6
|
-
import { readFileText, getReadJsonText, readGsonFileText, readGsonFileValue } from "./reading.js";
|
|
7
6
|
import { getTextHash, getTextUuid, getTextTuid, processPrimedText } from "./processing.js";
|
|
8
|
-
import { writeFileText, writeGsonValue } from "./writing.js";
|
|
9
7
|
|
|
10
8
|
// -- EXPORTS
|
|
11
9
|
|
|
@@ -15,15 +13,9 @@ export {
|
|
|
15
13
|
fetchGsonFileValue,
|
|
16
14
|
getFetchedJsonText,
|
|
17
15
|
buildGsonText,
|
|
18
|
-
getReadJsonText,
|
|
19
16
|
getTextHash,
|
|
20
17
|
getTextTuid,
|
|
21
18
|
getTextUuid,
|
|
22
19
|
haveSameValue,
|
|
23
20
|
processPrimedText,
|
|
24
|
-
readFileText,
|
|
25
|
-
readGsonFileText,
|
|
26
|
-
readGsonFileValue,
|
|
27
|
-
writeFileText,
|
|
28
|
-
writeGsonValue
|
|
29
21
|
};
|
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.
|
|
4
|
+
"version": "0.3.0",
|
|
5
5
|
"author": "Eric Pelzer <ecstatic.coder@gmail.com>",
|
|
6
6
|
"license": "LGPL-3.0-only",
|
|
7
7
|
"repository": {
|
|
@@ -21,9 +21,6 @@
|
|
|
21
21
|
"index.js",
|
|
22
22
|
"parsing.js",
|
|
23
23
|
"processing.js",
|
|
24
|
-
"reading.js",
|
|
25
|
-
"writing.js",
|
|
26
|
-
"test.js",
|
|
27
24
|
"README.md"
|
|
28
25
|
],
|
|
29
26
|
"keywords": [
|
package/reading.js
DELETED
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
// -- IMPORTS
|
|
2
|
-
|
|
3
|
-
import { readFileSync } from "node:fs";
|
|
4
|
-
import { processPrimedText } from "./processing.js";
|
|
5
|
-
|
|
6
|
-
// -- FUNCTIONS
|
|
7
|
-
|
|
8
|
-
export function readFileText(
|
|
9
|
-
filePath
|
|
10
|
-
)
|
|
11
|
-
{
|
|
12
|
-
return readFileSync( filePath, "utf8" );
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
// ~~
|
|
16
|
-
|
|
17
|
-
function getUnprimedReadText(
|
|
18
|
-
primedText,
|
|
19
|
-
folderPath,
|
|
20
|
-
primedTextIsProcessed = true,
|
|
21
|
-
readFileTextFunction = readFileText,
|
|
22
|
-
processPrimedTextFunction = processPrimedText
|
|
23
|
-
)
|
|
24
|
-
{
|
|
25
|
-
if ( primedTextIsProcessed
|
|
26
|
-
&& readFileTextFunction !== null
|
|
27
|
-
&& primedText.startsWith( "‼@" ) )
|
|
28
|
-
{
|
|
29
|
-
let filePath = folderPath + primedText.slice( 2 );
|
|
30
|
-
let fileText = readFileTextFunction( filePath );
|
|
31
|
-
|
|
32
|
-
return getReadJsonText( fileText, filePath, primedTextIsProcessed, readFileTextFunction, processPrimedTextFunction );
|
|
33
|
-
}
|
|
34
|
-
else if ( primedTextIsProcessed
|
|
35
|
-
&& processPrimedTextFunction !== null
|
|
36
|
-
&& primedText.startsWith( "‼" ) )
|
|
37
|
-
{
|
|
38
|
-
return '"' + processPrimedTextFunction( primedText ) + '"';
|
|
39
|
-
}
|
|
40
|
-
else
|
|
41
|
-
{
|
|
42
|
-
let lineArray = primedText.split( "\n" );
|
|
43
|
-
|
|
44
|
-
for ( let lineIndex = 0;
|
|
45
|
-
lineIndex < lineArray.length;
|
|
46
|
-
++lineIndex )
|
|
47
|
-
{
|
|
48
|
-
lineArray[ lineIndex ]
|
|
49
|
-
= lineArray[ lineIndex ].trim().replaceAll( "‗", " " );
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
return '"' + lineArray.join( "\\n" ) + '"';
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
// ~~
|
|
57
|
-
|
|
58
|
-
export function getReadJsonText(
|
|
59
|
-
gsonText,
|
|
60
|
-
filePath,
|
|
61
|
-
primedTextIsProcessed = true,
|
|
62
|
-
readFileTextFunction = readFileText,
|
|
63
|
-
processPrimedTextFunction = processPrimedText
|
|
64
|
-
)
|
|
65
|
-
{
|
|
66
|
-
gsonText = gsonText.replaceAll( "\r", "" ).trim();
|
|
67
|
-
filePath = filePath.replaceAll( "\\", "/" );
|
|
68
|
-
|
|
69
|
-
let folderPath = filePath.slice( 0, filePath.lastIndexOf( "/" ) + 1 );
|
|
70
|
-
let primedTextArray = gsonText.split( "‴" );
|
|
71
|
-
|
|
72
|
-
for ( let primedTextIndex = 1;
|
|
73
|
-
primedTextIndex < primedTextArray.length;
|
|
74
|
-
primedTextIndex += 2 )
|
|
75
|
-
{
|
|
76
|
-
primedTextArray[ primedTextIndex ]
|
|
77
|
-
= getUnprimedReadText( primedTextArray[ primedTextIndex ], folderPath, primedTextIsProcessed, readFileTextFunction, processPrimedTextFunction );
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
return primedTextArray.join( "" );
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
// ~~
|
|
84
|
-
|
|
85
|
-
export function readGsonFileText(
|
|
86
|
-
filePath,
|
|
87
|
-
primedTextIsProcessed = true,
|
|
88
|
-
readFileTextFunction = readFileText,
|
|
89
|
-
processPrimedTextFunction = processPrimedText
|
|
90
|
-
)
|
|
91
|
-
{
|
|
92
|
-
let gsonText = readFileTextFunction( filePath );
|
|
93
|
-
|
|
94
|
-
return getReadJsonText( gsonText, filePath, primedTextIsProcessed, readFileTextFunction, processPrimedTextFunction );
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
// ~~
|
|
98
|
-
|
|
99
|
-
export function readGsonFileValue(
|
|
100
|
-
filePath,
|
|
101
|
-
primedTextIsProcessed = true,
|
|
102
|
-
readFileTextFunction = readFileText,
|
|
103
|
-
processPrimedTextFunction = processPrimedText
|
|
104
|
-
)
|
|
105
|
-
{
|
|
106
|
-
return JSON.parse( readGsonFileText( filePath, primedTextIsProcessed, readFileTextFunction, processPrimedTextFunction ) );
|
|
107
|
-
}
|
package/test.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
// -- IMPORTS
|
|
2
|
-
|
|
3
|
-
import { buildGsonText, readGsonFileText, readGsonFileValue, writeFileText } from "./index.js";
|
|
4
|
-
|
|
5
|
-
// -- STATEMENTS
|
|
6
|
-
|
|
7
|
-
let jsonText = readGsonFileText( "../../DATA/test.gson" );
|
|
8
|
-
console.log( jsonText );
|
|
9
|
-
writeFileText( "OUT/processed_test.json", jsonText );
|
|
10
|
-
|
|
11
|
-
let jsonValue = readGsonFileValue( "../../DATA/test.gson" );
|
|
12
|
-
console.log( JSON.stringify( jsonValue ) );
|
|
13
|
-
|
|
14
|
-
let gsonText = buildGsonText( jsonValue );
|
|
15
|
-
console.log( gsonText );
|
|
16
|
-
writeFileText( "OUT/processed_test.gson", gsonText, 4 );
|
|
17
|
-
|
|
18
|
-
jsonText = readGsonFileText( "../../DATA/test.gson", false );
|
|
19
|
-
console.log( jsonText );
|
|
20
|
-
writeFileText( "OUT/unprocessed_test.json", jsonText );
|
|
21
|
-
|
|
22
|
-
gsonText = buildGsonText( jsonValue, false );
|
|
23
|
-
console.log( gsonText );
|
|
24
|
-
writeFileText( "OUT/unprocessed_test.gson", gsonText, 4 );
|
|
25
|
-
|
|
26
|
-
jsonValue = readGsonFileValue( "../../DATA/test.gson", false );
|
|
27
|
-
console.log( JSON.stringify( jsonValue ) );
|
|
28
|
-
|
|
29
|
-
gsonText = buildGsonText( jsonValue, true, false );
|
|
30
|
-
console.log( gsonText );
|
|
31
|
-
writeFileText( "OUT/unprocessed_test.gson", gsonText, 4 );
|
package/writing.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
// -- IMPORTS
|
|
2
|
-
|
|
3
|
-
import { writeFileSync } from "node:fs";
|
|
4
|
-
import { buildGsonText } from "./building.js";
|
|
5
|
-
|
|
6
|
-
// -- FUNCTIONS
|
|
7
|
-
|
|
8
|
-
export function writeFileText(
|
|
9
|
-
filePath,
|
|
10
|
-
fileText
|
|
11
|
-
)
|
|
12
|
-
{
|
|
13
|
-
writeFileSync( filePath, fileText, "utf8" );
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
// ~~
|
|
17
|
-
|
|
18
|
-
export function writeGsonValue(
|
|
19
|
-
filePath,
|
|
20
|
-
value
|
|
21
|
-
)
|
|
22
|
-
{
|
|
23
|
-
writeFileText( filePath, buildGsonText( value ) );
|
|
24
|
-
}
|