Skip to content

Commit

Permalink
Add types declaration file (#4)
Browse files Browse the repository at this point in the history
* Add types declaration file

* Add TS info to Readme, amend declaration file
  • Loading branch information
geopic authored Nov 25, 2020
1 parent a134700 commit 768c32c
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ import "text-terminal/dist/text-terminal.css";
const commands = {};

const config = {
containerId = "text-terminal",
containerId: "text-terminal",
prompt: "textTerm@quest",
theme: "dark",
commands: commands,
Expand All @@ -72,6 +72,22 @@ const config = {
const terminal = new TextTerminal(config);
```

Text Terminal also comes with TypeScript compatibility out of the box, so you can use it in your TypeScript projects. To adapt from the above excerpt:

```typescript
// Create a new TextTerminal with a config object where all properties are optional
const terminal = new TextTerminal({
containerId: "text-terminal",
prompt: "textTerm@quest",
theme: "dark",
commands: {},
});

// All methods of the TextTerminal class are recognised by your IDE with correct typing
terminal.createDom(document.getElementById("my-element")); // HTMLElement argument type
terminal.output("Hey Text Terminal!") // string argument type
```

## Themes

Text Terminal has the following themes bundled with it:
Expand Down
34 changes: 34 additions & 0 deletions dist/text-terminal.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
declare module "text-terminal" {
export default class TextTerminal {
constructor(options?: Partial<{
containerId: string;
commands: object;
prompt: string;
theme: string;
welcome: string;
separator: string;
}>);

addListeners(): void;

/**
* Clears the contents of the terminal output.
*/
clear(): void;

/**
* Outputs the version of Text Terminal.
*/
version(): void;

createDom(containerEl: HTMLElement): void;

onKeyDown: (event: Event) => void;

onKeyUp: (event: Event) => void;

output(command: string): void;

resetCommand: () => void;
}
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"lint-fix": "prettier --write ."
},
"main": "dist/text-terminal.js",
"types": "dist/text-terminal.d.ts",
"author": "Des Holmes https://github.com/desholmes",
"license": "MIT",
"devDependencies": {
Expand Down

0 comments on commit 768c32c

Please sign in to comment.