Skip to content

Commit

Permalink
Merge pull request #442 from videlais/440-consider-typescript-types
Browse files Browse the repository at this point in the history
TypeScript types
  • Loading branch information
videlais authored Jan 7, 2024
2 parents 2b3ac0d + 12579af commit d2e1ba6
Show file tree
Hide file tree
Showing 18 changed files with 1,247 additions and 11,282 deletions.
12,042 changes: 769 additions & 11,273 deletions package-lock.json

Large diffs are not rendered by default.

20 changes: 11 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,33 +25,34 @@
"dependencies": {
"commander": "^11.1.0",
"html-entities": "^2.4.0",
"node-html-parser": "^6.1.11",
"node-html-parser": "^6.1.12",
"pickleparser": "^0.2.1",
"semver": "^7.3.7",
"semver": "^7.5.4",
"uuid": "^9.0.1"
},
"devDependencies": {
"@babel/cli": "^7.23.4",
"@babel/core": "^7.23.6",
"@babel/core": "^7.23.7",
"@babel/eslint-parser": "^7.23.3",
"@babel/eslint-plugin": "^7.23.5",
"@babel/preset-env": "^7.23.6",
"@babel/preset-env": "^7.23.7",
"babel-loader": "^9.1.3",
"clean-jsdoc-theme": "^4.2.17",
"core-js": "^3.34.0",
"core-js": "^3.35.0",
"docsify-cli": "^4.4.4",
"esbuild": "0.19.11",
"eslint": "^8.56.0",
"eslint-config-standard": "^17.1.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-jest": "^27.6.0",
"eslint-plugin-jest": "^27.6.1",
"eslint-plugin-jsdoc": "^48.0.2",
"eslint-plugin-node": "^11.0.0",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^6.1.1",
"jest": "^29.7.0",
"pkg": "^5.8.1",
"regenerator-runtime": "^0.14.1",
"shelljs": "^0.8.4",
"shelljs": "^0.8.5",
"typescript": "^5.3.3",
"webpack": "^5.89.0",
"webpack-cli": "^5.1.4"
},
Expand All @@ -62,5 +63,6 @@
"bugs": {
"url": "https://github.com/videlais/extwee/issues"
},
"type": "module"
"type": "module",
"types": "./types/index.d.ts"
}
21 changes: 21 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
// Change this to match your project
"include": ["src/**/*"],
"compilerOptions": {
// Tells TypeScript to read JS files, as
// normally they are ignored as source files
"allowJs": true,
// Generate d.ts files
"declaration": true,
// This compiler run should
// only output d.ts files
"emitDeclarationOnly": true,
// Types should go into this directory.
// Removing this would place the .d.ts files
// next to the .js files
"outDir": "types",
// go to js file when using IDE functions like
// "Go to Definition" in VSCode
"declarationMap": true
}
}
14 changes: 14 additions & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { parse as parseTwee } from './src/Twee/parse.js';
import { parse as parseJSON } from './src/JSON/parse.js';
import { parse as parseTWS } from './src/TWS/parse.js';
import { parse as parseStoryFormat } from './src/StoryFormat/parse.js';
import { parse as parseTwine1HTML } from './src/Twine1HTML/parse.js';
import { parse as parseTwine2HTML } from './src/Twine2HTML/parse.js';
import { parse as parseTwine2ArchiveHTML } from './src/Twine2ArchiveHTML/parse.js';
import { compile as compileTwine1HTML } from './src/Twine1HTML/compile.js';
import { compile as compileTwine2HTML } from './src/Twine2HTML/compile.js';
import { compile as compileTwine2ArchiveHTML } from './src/Twine2ArchiveHTML/compile.js';
import Story from './src/Story.js';
import Passage from './src/Passage.js';
import StoryFormat from './src/StoryFormat.js';
export { parseTwee, parseJSON, parseTWS, parseStoryFormat, parseTwine1HTML, parseTwine2HTML, parseTwine2ArchiveHTML, compileTwine1HTML, compileTwine2HTML, compileTwine2ArchiveHTML, Story, Passage, StoryFormat };
8 changes: 8 additions & 0 deletions types/src/JSON/parse.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* Parse JSON representation into Story.
* @function parse
* @param {string} jsonString - JSON string to convert to Story.
* @returns {Story} Story object.
*/
export function parse(jsonString: string): Story;
import Story from '../Story.js';
72 changes: 72 additions & 0 deletions types/src/Passage.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/**
* A passage is the smallest unit of a Twine story.
*/
export default class Passage {
/**
* Create a passage.
* @param {string} name - Name
* @param {string} text - Content
* @param {Array} tags - Tags
* @param {object} metadata - Metadata
*/
constructor(name?: string, text?: string, tags?: any[], metadata?: object);
/**
* @param {string} s - Name to replace
*/
set name(s: string);
/**
* Name
* @returns {string} Name
*/
get name(): string;
/**
* @param {Array} t - Replacement array
*/
set tags(t: any[]);
/**
* Tags
* @returns {Array} Tags
*/
get tags(): any[];
/**
* @param {object} m - Replacement object
*/
set metadata(m: any);
/**
* Metadata
* @returns {object} Metadata
*/
get metadata(): any;
/**
* @param {string} t - Replacement text
*/
set text(t: string);
/**
* Text
* @returns {string} Text
*/
get text(): string;
/**
* Return a Twee representation.
* @returns {string} String form of passage.
*/
toTwee(): string;
/**
* Return JSON representation.
* @returns {string} JSON string.
*/
toJSON(): string;
/**
* Return Twine 2 HTML representation.
* (Default Passage ID is 1.)
* @param {number} pid - Passage ID (PID) to record in HTML.
* @returns {string} Twine 2 HTML string.
*/
toTwine2HTML(pid?: number): string;
/**
* Return Twine 1 HTML representation.
* @returns {string} Twine 1 HTML string.
*/
toTwine1HTML(): string;
#private;
}
161 changes: 161 additions & 0 deletions types/src/Story.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
export default class Story {
/**
* Creates a story.
* @param {string} name - Name of the story.
*/
constructor(name?: string);
/**
* @param {string} a - Replacement story name
*/
set name(a: string);
/**
* Each story has a name
* @returns {string} Name
*/
get name(): string;
/**
* @param {object} a - Replacement tag colors
*/
set tagColors(a: any);
/**
* Tag Colors object (each property is a tag and its color)
* @returns {object} tag colors array
*/
get tagColors(): any;
/**
* @param {string} i - Replacement IFID
*/
set IFID(i: string);
/**
* Interactive Fiction ID (IFID) of Story
* @returns {string} IFID
*/
get IFID(): string;
/**
* @param {string} s - Replacement start
*/
set start(s: string);
/**
* Name of start passage.
* @returns {string} start
*/
get start(): string;
/**
* @param {string} f - Replacement format version
*/
set formatVersion(f: string);
/**
* Story format version of Story.
* @returns {string} story format version
*/
get formatVersion(): string;
/**
* @param {object} o - Replacement metadata
*/
set metadata(o: any);
/**
* Metadata of Story.
* @returns {object} metadata of story
*/
get metadata(): any;
/**
* @param {string} f - Replacement format
*/
set format(f: string);
/**
* Story format of Story.
* @returns {string} format
*/
get format(): string;
/**
* @param {string} c - Creator Program of Story
*/
set creator(c: string);
/**
* Program used to create Story.
* @returns {string} Creator Program
*/
get creator(): string;
/**
* @param {string} c - Version of creator program
*/
set creatorVersion(c: string);
/**
* Version used to create Story.
* @returns {string} Version
*/
get creatorVersion(): string;
/**
* @param {number} n - Replacement zoom level
*/
set zoom(n: number);
/**
* Zoom level.
* @returns {number} Zoom level
*/
get zoom(): number;
/**
* Add a passage to the story.
* `StoryData` will override story metadata and `StoryTitle` will override story name.
* @param {Passage} p - Passage to add to Story.
*/
addPassage(p: Passage): void;
/**
* Remove a passage from the story by name.
* @param {string} name - Passage name to remove
*/
removePassageByName(name: string): void;
/**
* Find passages by tag.
* @param {string} t - Passage name to search for
* @returns {Array} Return array of passages
*/
getPassagesByTag(t: string): any[];
/**
* Find passage by name.
* @param {string} name - Passage name to search for
* @returns {Passage | null} Return passage or null
*/
getPassageByName(name: string): Passage | null;
/**
* Size (number of passages).
* @returns {number} Return number of passages
*/
size(): number;
/**
* forEach-style iterator of passages in Story.
* @param {Function} callback - Callback function
*/
forEachPassage(callback: Function): void;
/**
* Export Story as JSON representation.
* @returns {string} JSON string.
*/
toJSON(): string;
/**
* Return Twee representation.
*
* See: Twee 3 Specification
* (https://github.com/iftechfoundation/twine-specs/blob/master/twee-3-specification.md)
* @returns {string} Twee String
*/
toTwee(): string;
/**
* Return Twine 2 HTML.
*
* See: Twine 2 HTML Output
* (https://github.com/iftechfoundation/twine-specs/blob/master/twine-2-htmloutput-spec.md)
* @returns {string} Twine 2 HTML string
*/
toTwine2HTML(): string;
/**
* Return Twine 1 HTML.
*
* See: Twine 1 HTML Output
* (https://github.com/iftechfoundation/twine-specs/blob/master/twine-1-htmloutput-doc.md)
* @returns {string} Twine 1 HTML string.
*/
toTwine1HTML(): string;
#private;
}
import Passage from './Passage.js';
Loading

0 comments on commit d2e1ba6

Please sign in to comment.