extwee 2.0.6 → 2.2.1
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/.eslintrc.json +25 -25
- package/.github/FUNDING.yml +3 -0
- package/.github/dependabot.yml +11 -0
- package/.github/workflows/nodejs.yml +25 -24
- package/.travis.yml +13 -13
- package/CODE_OF_CONDUCT.md +82 -82
- package/LICENSE +21 -21
- package/README.md +173 -36
- package/SECURITY.md +12 -12
- package/babel.config.json +18 -22
- package/build/extwee +0 -0
- package/build/extwee.exe +0 -0
- package/build/extwee.web.min.js +2 -0
- package/build/extwee.web.min.js.LICENSE.txt +1 -0
- package/docs/.nojekyll +0 -0
- package/docs/README.md +167 -0
- package/docs/_sidebar.md +20 -0
- package/docs/examples/dynamicPassages.md +28 -0
- package/docs/examples/jsonToTwee.md +23 -0
- package/docs/examples/twsToTwee.md +25 -0
- package/docs/formats/json.md +17 -0
- package/docs/formats/twee.md +13 -0
- package/docs/formats/twine1HTML.md +13 -0
- package/docs/formats/twine2ArchiveHTML.md +13 -0
- package/docs/formats/twine2HTML.md +13 -0
- package/docs/formats/tws.md +9 -0
- package/docs/index.html +26 -0
- package/docs/install/binaries.md +9 -0
- package/docs/install/npm.md +20 -0
- package/docs/install/npx.md +9 -0
- package/docs/objects/passage.md +47 -0
- package/docs/objects/story.md +70 -0
- package/docs/objects/storyformat.md +27 -0
- package/index.html +22 -0
- package/index.js +29 -31
- package/package.json +68 -58
- package/src/JSON/parse.js +128 -0
- package/src/Passage.js +279 -202
- package/src/Story.js +653 -523
- package/src/StoryFormat/parse.js +134 -0
- package/src/StoryFormat.js +259 -300
- package/src/TWS/parse.js +86 -0
- package/src/Twee/parse.js +157 -0
- package/src/Twine1HTML/compile.js +58 -0
- package/src/Twine1HTML/parse.js +134 -0
- package/src/Twine2ArchiveHTML/compile.js +36 -0
- package/src/Twine2ArchiveHTML/parse.js +49 -0
- package/src/Twine2HTML/compile.js +35 -0
- package/src/Twine2HTML/parse.js +349 -0
- package/src/extwee.js +206 -0
- package/test/CLI/CLI.test.js +49 -0
- package/test/CLI/files/example.json +1 -0
- package/test/CLI/files/example6.twee +22 -0
- package/test/{Roundtrip → CLI/files}/harlowe.js +2 -2
- package/test/CLI/{input.html → files/input.html} +47 -47
- package/test/CLI/files/output/test.twee +0 -0
- package/test/CLI/{tweeExample.twee → files/tweeExample.twee} +17 -17
- package/test/CLI/files/twine1/LICENSE.txt +32 -0
- package/test/CLI/files/twine1/code.js +5 -0
- package/test/CLI/files/twine1/engine.js +43 -0
- package/test/CLI/files/twine1/header.html +325 -0
- package/test/CLI/files/twine1Test.html +371 -0
- package/test/CLI/{twineExample.html → files/twineExample.html} +16 -15
- package/test/JSON/JSON.Parse.test.js +316 -0
- package/test/Passage.test.js +244 -104
- package/test/Roundtrip/{Example1.html → Files/Example1.html} +63 -63
- package/test/Roundtrip/Files/LICENSE +19 -0
- package/test/Roundtrip/Files/example1.twee +10 -0
- package/test/Roundtrip/{example2.twee → Files/example2.twee} +27 -18
- package/test/Roundtrip/{example4.twee → Files/example4.twee} +27 -27
- package/test/{StoryFormatParser → Roundtrip/Files}/harlowe.js +2 -2
- package/test/Roundtrip/{round.html → Files/round.html} +6 -4
- package/test/Roundtrip/Roundtrip.test.js +54 -0
- package/test/Story.test.js +677 -423
- package/test/StoryFormat/StoryFormat.Parse.test.js +91 -0
- package/test/{StoryFormatParser → StoryFormat/StoryFormatParser}/example.js +3 -3
- package/test/{StoryFormatParser → StoryFormat/StoryFormatParser}/example2.js +3 -3
- package/test/{CLI → StoryFormat/StoryFormatParser}/harlowe.js +2 -2
- package/test/StoryFormat.test.js +152 -152
- package/test/TWS/Parse.test.js +78 -0
- package/test/TWS/TWSParser/Example1.tws +150 -0
- package/test/TWS/TWSParser/Example5.tws +414 -0
- package/test/TWS/TWSParser/noscale.tws +0 -0
- package/test/TWS/TWSParser/nostory.tws +0 -0
- package/test/Twee/Twee.Parse.test.js +76 -0
- package/test/{TweeParser → Twee/TweeParser}/emptytags.twee +2 -2
- package/test/{TweeParser → Twee/TweeParser}/example.twee +32 -32
- package/test/{TweeParser → Twee/TweeParser}/missing.twee +19 -19
- package/test/{TweeParser → Twee/TweeParser}/multipleScriptPassages.twee +19 -19
- package/test/{TweeParser → Twee/TweeParser}/multipleStyleTag.twee +19 -19
- package/test/{TweeParser → Twee/TweeParser}/multipletags.twee +10 -10
- package/test/{TweeParser → Twee/TweeParser}/noTitle.twee +2 -2
- package/test/{TweeParser → Twee/TweeParser}/notes.twee +16 -16
- package/test/{TweeParser → Twee/TweeParser}/pasagemetadataerror.twee +2 -2
- package/test/{TweeParser → Twee/TweeParser}/scriptPassage.twee +16 -16
- package/test/{TweeParser → Twee/TweeParser}/singletag.twee +13 -13
- package/test/{TweeParser → Twee/TweeParser}/startMetadata.twee +14 -14
- package/test/{TweeParser → Twee/TweeParser}/storydataerror.twee +25 -25
- package/test/{TweeParser → Twee/TweeParser}/stylePassage.twee +16 -16
- package/test/{Story → Twee/TweeParser}/test.twee +25 -25
- package/test/Twine1HTML/Twine1HTML.Compile.test.js +180 -0
- package/test/Twine1HTML/Twine1HTML.Parse.test.js +183 -0
- package/test/Twine1HTML/Twine1HTMLCompiler/Twine1/LICENSE +674 -0
- package/test/Twine1HTML/Twine1HTMLCompiler/Twine1/engine.js +43 -0
- package/test/Twine1HTML/Twine1HTMLCompiler/Twine1/jquery.js +4 -0
- package/test/Twine1HTML/Twine1HTMLCompiler/Twine1/modernizr.js +4 -0
- package/test/Twine1HTML/Twine1HTMLCompiler/engineTest.html +1 -0
- package/test/Twine1HTML/Twine1HTMLCompiler/jonah-1.4.2/LICENSE +32 -0
- package/test/Twine1HTML/Twine1HTMLCompiler/jonah-1.4.2/code.js +4 -0
- package/test/Twine1HTML/Twine1HTMLCompiler/jonah-1.4.2/header.html +327 -0
- package/test/Twine1HTML/Twine1HTMLCompiler/test.html +0 -0
- package/test/Twine1HTML/Twine1HTMLCompiler/test1.html +6 -0
- package/test/Twine1HTML/Twine1HTMLCompiler/test2.html +6 -0
- package/test/Twine1HTML/Twine1HTMLCompiler/test3.html +43 -0
- package/test/Twine1HTML/Twine1HTMLCompiler/test4.html +372 -0
- package/test/Twine1HTML/Twine1HTMLCompiler/test5.html +372 -0
- package/test/Twine2ArchiveHTML/Twine2ArchiveHTML.Compile.test.js +35 -0
- package/test/Twine2ArchiveHTML/Twine2ArchiveHTML.Parse.test.js +25 -0
- package/test/Twine2ArchiveHTML/Twine2ArchiveHTMLCompiler/test1.html +6 -0
- package/test/Twine2ArchiveHTML/Twine2ArchiveHTMLParser/test1.html +3 -0
- package/test/Twine2HTML/Twine2HTML.Compile.test.js +224 -0
- package/test/Twine2HTML/Twine2HTML.Parse.test.js +173 -0
- package/test/{HTMLWriter → Twine2HTML/Twine2HTMLCompiler}/creator.html +4 -4
- package/test/{CLI → Twine2HTML/Twine2HTMLCompiler}/example6.twee +15 -15
- package/test/{HTMLWriter → Twine2HTML/Twine2HTMLCompiler}/missingStoryTitle.twee +29 -29
- package/test/{HTMLWriter → Twine2HTML/Twine2HTMLCompiler}/test2.html +10 -8
- package/test/{HTMLWriter → Twine2HTML/Twine2HTMLCompiler}/test3.html +1 -1
- package/test/{HTMLWriter → Twine2HTML/Twine2HTMLCompiler}/test4.html +4 -4
- package/test/{HTMLParser → Twine2HTML/Twine2HTMLParser}/Example1.html +52 -52
- package/test/{HTMLParser → Twine2HTML/Twine2HTMLParser}/Tags.html +15 -15
- package/test/{HTMLParser → Twine2HTML/Twine2HTMLParser}/lyingStartnode.html +15 -15
- package/test/{HTMLParser → Twine2HTML/Twine2HTMLParser}/lyingTagColors.html +48 -48
- package/test/{HTMLParser → Twine2HTML/Twine2HTMLParser}/missingCreator.html +11 -11
- package/test/{HTMLParser → Twine2HTML/Twine2HTMLParser}/missingCreatorVersion.html +11 -11
- package/test/{HTMLParser → Twine2HTML/Twine2HTMLParser}/missingFormat.html +11 -11
- package/test/{HTMLParser → Twine2HTML/Twine2HTMLParser}/missingFormatVersion.html +11 -11
- package/test/{HTMLParser → Twine2HTML/Twine2HTMLParser}/missingIFID.html +11 -11
- package/test/{HTMLParser → Twine2HTML/Twine2HTMLParser}/missingName.html +33 -33
- package/test/{HTMLParser → Twine2HTML/Twine2HTMLParser}/missingPID.html +15 -15
- package/test/{HTMLParser → Twine2HTML/Twine2HTMLParser}/missingPassageName.html +15 -15
- package/test/{HTMLParser → Twine2HTML/Twine2HTMLParser}/missingPassageTags.html +15 -15
- package/test/{HTMLParser → Twine2HTML/Twine2HTMLParser}/missingPosition.html +15 -15
- package/test/{HTMLParser → Twine2HTML/Twine2HTMLParser}/missingScript.html +14 -14
- package/test/{HTMLParser → Twine2HTML/Twine2HTMLParser}/missingSize.html +35 -35
- package/test/{HTMLParser → Twine2HTML/Twine2HTMLParser}/missingStartnode.html +11 -11
- package/test/{HTMLParser → Twine2HTML/Twine2HTMLParser}/missingStyle.html +14 -14
- package/test/{HTMLParser → Twine2HTML/Twine2HTMLParser}/missingZoom.html +11 -11
- package/test/{HTMLParser → Twine2HTML/Twine2HTMLParser}/twineExample.html +23 -23
- package/test/{HTMLParser → Twine2HTML/Twine2HTMLParser}/twineExample2.html +15 -15
- package/test/{HTMLParser → Twine2HTML/Twine2HTMLParser}/twineExample3.html +15 -15
- package/test/Twine2HTML/Twine2HTMLParser/unescaping.html +33 -0
- package/tsconfig.json +21 -0
- package/types/index.d.ts +14 -0
- package/types/src/JSON/parse.d.ts +8 -0
- package/types/src/Passage.d.ts +72 -0
- package/types/src/Story.d.ts +161 -0
- package/types/src/StoryFormat/parse.d.ts +7 -0
- package/types/src/StoryFormat.d.ts +97 -0
- package/types/src/TWS/parse.d.ts +10 -0
- package/types/src/Twee/parse.d.ts +10 -0
- package/types/src/Twine1HTML/compile.d.ts +17 -0
- package/types/src/Twine1HTML/parse.d.ts +10 -0
- package/types/src/Twine2ArchiveHTML/compile.d.ts +6 -0
- package/types/src/Twine2ArchiveHTML/parse.d.ts +6 -0
- package/types/src/Twine2HTML/compile.d.ts +9 -0
- package/types/src/Twine2HTML/parse.d.ts +17 -0
- package/types/src/extwee.d.ts +2 -0
- package/web-index.js +29 -0
- package/webpack.config.js +12 -0
- package/bin/extwee.js +0 -47
- package/src/FileReader.js +0 -33
- package/src/HTMLParser.js +0 -345
- package/src/HTMLWriter.js +0 -231
- package/src/StoryFormatParser.js +0 -142
- package/src/TweeParser.js +0 -161
- package/src/TweeWriter.js +0 -121
- package/story-formats/chapbook-1.2.0/format.js +0 -1
- package/story-formats/chapbook-1.2.0/logo.svg +0 -1
- package/story-formats/harlowe-1.2.4/format.js +0 -1
- package/story-formats/harlowe-1.2.4/icon.svg +0 -78
- package/story-formats/harlowe-2.1.0/format.js +0 -2
- package/story-formats/harlowe-2.1.0/icon.svg +0 -78
- package/story-formats/harlowe-3.1.0/format.js +0 -3
- package/story-formats/harlowe-3.1.0/icon.svg +0 -78
- package/story-formats/paperthin-1.0.0/format.js +0 -1
- package/story-formats/paperthin-1.0.0/icon.svg +0 -5
- package/story-formats/snowman-1.4.0/format.js +0 -1
- package/story-formats/snowman-1.4.0/icon.svg +0 -436
- package/story-formats/snowman-2.0.2/format.js +0 -1
- package/story-formats/snowman-2.0.2/icon.svg +0 -436
- package/story-formats/sugarcube-1.0.35/LICENSE +0 -23
- package/story-formats/sugarcube-1.0.35/format.js +0 -1
- package/story-formats/sugarcube-1.0.35/icon.svg +0 -56
- package/story-formats/sugarcube-2.31.1/LICENSE +0 -22
- package/story-formats/sugarcube-2.31.1/format.js +0 -1
- package/story-formats/sugarcube-2.31.1/icon.svg +0 -56
- package/test/CLI/test2.html +0 -45
- package/test/CLI.test.js +0 -30
- package/test/FileReader/t1.txt +0 -1
- package/test/FileReader.test.js +0 -14
- package/test/HTMLParser.test.js +0 -177
- package/test/HTMLWriter/example6.twee +0 -16
- package/test/HTMLWriter.test.js +0 -287
- package/test/Roundtrip/example1.twee +0 -21
- package/test/Roundtrip.test.js +0 -48
- package/test/Story/startmeta.twee +0 -29
- package/test/StoryFormatParser.test.js +0 -91
- package/test/TweeParser/test.twee +0 -25
- package/test/TweeParser.test.js +0 -79
- package/test/TweeWriter/test1.twee +0 -18
- package/test/TweeWriter/test3.twee +0 -12
- package/test/TweeWriter/test4.twee +0 -14
- package/test/TweeWriter/test5.twee +0 -20
- package/test/TweeWriter/test6.twee +0 -15
- package/test/TweeWriter/test7.twee +0 -15
- package/test/TweeWriter.test.js +0 -107
- /package/test/CLI/{test.twee → files/test.twee} +0 -0
- /package/test/{StoryFormatParser → StoryFormat/StoryFormatParser}/format.js +0 -0
- /package/test/{StoryFormatParser → StoryFormat/StoryFormatParser}/format_doublename.js +0 -0
- /package/test/{StoryFormatParser → StoryFormat/StoryFormatParser}/missingAuthor.js +0 -0
- /package/test/{StoryFormatParser → StoryFormat/StoryFormatParser}/missingDescription.js +0 -0
- /package/test/{StoryFormatParser → StoryFormat/StoryFormatParser}/missingImage.js +0 -0
- /package/test/{StoryFormatParser → StoryFormat/StoryFormatParser}/missingLicense.js +0 -0
- /package/test/{StoryFormatParser → StoryFormat/StoryFormatParser}/missingName.js +0 -0
- /package/test/{StoryFormatParser → StoryFormat/StoryFormatParser}/missingProofing.js +0 -0
- /package/test/{StoryFormatParser → StoryFormat/StoryFormatParser}/missingSource.js +0 -0
- /package/test/{StoryFormatParser → StoryFormat/StoryFormatParser}/missingURL.js +0 -0
- /package/test/{StoryFormatParser → StoryFormat/StoryFormatParser}/missingVersion.js +0 -0
- /package/test/{StoryFormatParser → StoryFormat/StoryFormatParser}/versionWrong.js +0 -0
- /package/test/{HTMLWriter → Twine2HTML/Twine2HTMLCompiler}/TestTags.html +0 -0
- /package/test/{HTMLWriter → Twine2HTML/Twine2HTMLCompiler}/test11.html +0 -0
- /package/test/{HTMLWriter → Twine2HTML/Twine2HTMLCompiler}/test6.html +0 -0
- /package/test/{HTMLParser → Twine2HTML/Twine2HTMLParser}/tagColors.html +0 -0
package/index.js
CHANGED
|
@@ -1,31 +1,29 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
export {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
writeHTML: HTMLWriter.write
|
|
31
|
-
};
|
|
1
|
+
import { parse as parseTwee } from './src/Twee/parse.js';
|
|
2
|
+
import { parse as parseJSON } from './src/JSON/parse.js';
|
|
3
|
+
import { parse as parseStoryFormat } from './src/StoryFormat/parse.js';
|
|
4
|
+
import { parse as parseTwine1HTML } from './src/Twine1HTML/parse.js';
|
|
5
|
+
import { parse as parseTwine2HTML } from './src/Twine2HTML/parse.js';
|
|
6
|
+
import { parse as parseTwine2ArchiveHTML } from './src/Twine2ArchiveHTML/parse.js';
|
|
7
|
+
import { parse as parseTWS } from './src/TWS/parse.js';
|
|
8
|
+
import { compile as compileTwine1HTML } from './src/Twine1HTML/compile.js';
|
|
9
|
+
import { compile as compileTwine2HTML } from './src/Twine2HTML/compile.js';
|
|
10
|
+
import { compile as compileTwine2ArchiveHTML } from './src/Twine2ArchiveHTML/compile.js';
|
|
11
|
+
import { Story } from './src/Story.js';
|
|
12
|
+
import Passage from './src/Passage.js';
|
|
13
|
+
import StoryFormat from './src/StoryFormat.js';
|
|
14
|
+
|
|
15
|
+
export {
|
|
16
|
+
parseTwee,
|
|
17
|
+
parseJSON,
|
|
18
|
+
parseTWS,
|
|
19
|
+
parseStoryFormat,
|
|
20
|
+
parseTwine1HTML,
|
|
21
|
+
parseTwine2HTML,
|
|
22
|
+
parseTwine2ArchiveHTML,
|
|
23
|
+
compileTwine1HTML,
|
|
24
|
+
compileTwine2HTML,
|
|
25
|
+
compileTwine2ArchiveHTML,
|
|
26
|
+
Story,
|
|
27
|
+
Passage,
|
|
28
|
+
StoryFormat
|
|
29
|
+
};
|
package/package.json
CHANGED
|
@@ -1,58 +1,68 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "extwee",
|
|
3
|
-
"version": "2.
|
|
4
|
-
"description": "A
|
|
5
|
-
"author": "Dan Cox",
|
|
6
|
-
"main": "index.js",
|
|
7
|
-
"bin": {
|
|
8
|
-
"extwee": "
|
|
9
|
-
},
|
|
10
|
-
"scripts": {
|
|
11
|
-
"test": "jest --silent --runInBand --coverage --colors",
|
|
12
|
-
"lint": "eslint ./src/**/*.js --fix",
|
|
13
|
-
"lint:test": "eslint ./test
|
|
14
|
-
"
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
"@babel/
|
|
35
|
-
"@babel/
|
|
36
|
-
"@babel/
|
|
37
|
-
"babel-
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"eslint
|
|
45
|
-
"eslint-
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
"
|
|
52
|
-
"
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
"
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "extwee",
|
|
3
|
+
"version": "2.2.1",
|
|
4
|
+
"description": "A story compiler tool using Twine-compatible formats",
|
|
5
|
+
"author": "Dan Cox",
|
|
6
|
+
"main": "index.js",
|
|
7
|
+
"bin": {
|
|
8
|
+
"extwee": "src/extwee.js"
|
|
9
|
+
},
|
|
10
|
+
"scripts": {
|
|
11
|
+
"test": "jest --silent --runInBand --coverage --colors",
|
|
12
|
+
"lint": "eslint ./src/**/*.js --fix",
|
|
13
|
+
"lint:test": "eslint ./test/**/*.test.js --fix",
|
|
14
|
+
"build:web": "webpack",
|
|
15
|
+
"build:bin": "esbuild ./src/extwee.js --bundle --platform=node --target=node12 --outfile=out.js && pkg -t node18-macos-x64 out.js --output ./build/extwee && rm out.js",
|
|
16
|
+
"all": "npm run lint && npm run lint:test && npm run test"
|
|
17
|
+
},
|
|
18
|
+
"keywords": [
|
|
19
|
+
"twine",
|
|
20
|
+
"twee",
|
|
21
|
+
"parser",
|
|
22
|
+
"compiler"
|
|
23
|
+
],
|
|
24
|
+
"license": "MIT",
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"commander": "^11.1.0",
|
|
27
|
+
"html-entities": "^2.4.0",
|
|
28
|
+
"node-html-parser": "^6.1.12",
|
|
29
|
+
"pickleparser": "^0.2.1",
|
|
30
|
+
"semver": "^7.5.4",
|
|
31
|
+
"uuid": "^9.0.1"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@babel/cli": "^7.23.4",
|
|
35
|
+
"@babel/core": "^7.23.7",
|
|
36
|
+
"@babel/eslint-parser": "^7.23.3",
|
|
37
|
+
"@babel/eslint-plugin": "^7.23.5",
|
|
38
|
+
"@babel/preset-env": "^7.23.8",
|
|
39
|
+
"babel-loader": "^9.1.3",
|
|
40
|
+
"clean-jsdoc-theme": "^4.2.17",
|
|
41
|
+
"core-js": "^3.35.0",
|
|
42
|
+
"docsify-cli": "^4.4.4",
|
|
43
|
+
"esbuild": "0.19.11",
|
|
44
|
+
"eslint": "^8.56.0",
|
|
45
|
+
"eslint-config-standard": "^17.1.0",
|
|
46
|
+
"eslint-plugin-import": "^2.29.1",
|
|
47
|
+
"eslint-plugin-jest": "^27.6.1",
|
|
48
|
+
"eslint-plugin-jsdoc": "^48.0.2",
|
|
49
|
+
"eslint-plugin-node": "^11.1.0",
|
|
50
|
+
"eslint-plugin-promise": "^6.1.1",
|
|
51
|
+
"jest": "^29.7.0",
|
|
52
|
+
"pkg": "^5.8.1",
|
|
53
|
+
"regenerator-runtime": "^0.14.1",
|
|
54
|
+
"shelljs": "^0.8.5",
|
|
55
|
+
"typescript": "^5.3.3",
|
|
56
|
+
"webpack": "^5.89.0",
|
|
57
|
+
"webpack-cli": "^5.1.4"
|
|
58
|
+
},
|
|
59
|
+
"repository": {
|
|
60
|
+
"type": "git",
|
|
61
|
+
"url": "https://github.com/videlais/extwee"
|
|
62
|
+
},
|
|
63
|
+
"bugs": {
|
|
64
|
+
"url": "https://github.com/videlais/extwee/issues"
|
|
65
|
+
},
|
|
66
|
+
"type": "module",
|
|
67
|
+
"types": "./types/index.d.ts"
|
|
68
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { Story } from '../Story.js';
|
|
2
|
+
import Passage from '../Passage.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Parse JSON representation into Story.
|
|
6
|
+
* @function parse
|
|
7
|
+
* @param {string} jsonString - JSON string to convert to Story.
|
|
8
|
+
* @returns {Story} Story object.
|
|
9
|
+
*/
|
|
10
|
+
function parse (jsonString) {
|
|
11
|
+
// Create future object.
|
|
12
|
+
let result = {};
|
|
13
|
+
|
|
14
|
+
// Create Story.
|
|
15
|
+
const s = new Story();
|
|
16
|
+
|
|
17
|
+
// Try to parse the string.
|
|
18
|
+
try {
|
|
19
|
+
result = JSON.parse(jsonString);
|
|
20
|
+
} catch (error) {
|
|
21
|
+
throw new Error('Invalid JSON!');
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Name
|
|
25
|
+
if (Object.prototype.hasOwnProperty.call(result, 'name')) {
|
|
26
|
+
// Convert to String (if not String).
|
|
27
|
+
s.name = String(result.name);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Start Passage
|
|
31
|
+
if (Object.prototype.hasOwnProperty.call(result, 'start')) {
|
|
32
|
+
// Convert to String (if not String).
|
|
33
|
+
s.start = String(result.start);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// IFID
|
|
37
|
+
if (Object.prototype.hasOwnProperty.call(result, 'ifid')) {
|
|
38
|
+
// Convert to String (if not String).
|
|
39
|
+
// Enforce the uppercase rule of Twine 2 and Twee 3.
|
|
40
|
+
s.IFID = String(result.ifid).toUpperCase();
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Format
|
|
44
|
+
if (Object.prototype.hasOwnProperty.call(result, 'format')) {
|
|
45
|
+
// Convert to String (if not String).
|
|
46
|
+
s.format = String(result.format);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Format Version
|
|
50
|
+
if (Object.prototype.hasOwnProperty.call(result, 'formatVersion')) {
|
|
51
|
+
// Convert to String (if not String).
|
|
52
|
+
s.formatVersion = String(result.formatVersion);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// Creator
|
|
56
|
+
if (Object.prototype.hasOwnProperty.call(result, 'creator')) {
|
|
57
|
+
// Convert to String (if not String).
|
|
58
|
+
s.creator = String(result.creator);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Creator Version
|
|
62
|
+
if (Object.prototype.hasOwnProperty.call(result, 'creatorVersion')) {
|
|
63
|
+
// Convert to String (if not String).
|
|
64
|
+
s.creatorVersion = String(result.creatorVersion);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// Zoom
|
|
68
|
+
if (Object.prototype.hasOwnProperty.call(result, 'zoom')) {
|
|
69
|
+
// Set Zoom.
|
|
70
|
+
s.zoom = result.zoom;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// Tag Colors
|
|
74
|
+
if (Object.prototype.hasOwnProperty.call(result, 'tagColors')) {
|
|
75
|
+
// Set tagColors.
|
|
76
|
+
s.tagColors = result.tagColors;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// Metadata
|
|
80
|
+
if (Object.prototype.hasOwnProperty.call(result, 'metadata')) {
|
|
81
|
+
// Set metadata.
|
|
82
|
+
s.metadata = result.metadata;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// Passages
|
|
86
|
+
if (Object.prototype.hasOwnProperty.call(result, 'passages')) {
|
|
87
|
+
// Is s an array?
|
|
88
|
+
if (Array.isArray(result.passages)) {
|
|
89
|
+
// For each passage, convert into Passage objects.
|
|
90
|
+
result.passages.forEach((p) => {
|
|
91
|
+
// Create default passage.
|
|
92
|
+
const newP = new Passage();
|
|
93
|
+
|
|
94
|
+
// Does s have a name?
|
|
95
|
+
if (Object.prototype.hasOwnProperty.call(p, 'name')) {
|
|
96
|
+
// Set name.
|
|
97
|
+
newP.name = p.name;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// Does s have tags?
|
|
101
|
+
if (Object.prototype.hasOwnProperty.call(p, 'tags')) {
|
|
102
|
+
// Set tags.
|
|
103
|
+
newP.tags = p.tags;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// Does s have metadata?
|
|
107
|
+
if (Object.prototype.hasOwnProperty.call(p, 'metadata')) {
|
|
108
|
+
// Set metadata.
|
|
109
|
+
newP.metadata = p.metadata;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// Does s have text?
|
|
113
|
+
if (Object.prototype.hasOwnProperty.call(p, 'text')) {
|
|
114
|
+
// Set text.
|
|
115
|
+
newP.text = p.text;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// Add the new passage.
|
|
119
|
+
s.addPassage(newP);
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// Return Story.
|
|
125
|
+
return s;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export { parse };
|