Skip to content

Commit

Permalink
feat(index): add typescript definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
Frazer Smith committed Oct 26, 2020
1 parent c26a83e commit e2203a6
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 6 deletions.
6 changes: 3 additions & 3 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

- [UnRTF](#UnRTF)
- [new UnRTF([binPath])](#new_UnRTF_new)
- [.convert([options], file)](#UnRTF+convert) ⇒ <code>Promise.&lt;(string\|Error)&gt;</code>
- [.convert(options, file)](#UnRTF+convert) ⇒ <code>Promise.&lt;(string\|Error)&gt;</code>

<a name="new_UnRTF_new"></a>

Expand All @@ -33,7 +33,7 @@

<a name="UnRTF+convert"></a>

### unRTF.convert([options], file) ⇒ <code>Promise.&lt;(string\|Error)&gt;</code>
### unRTF.convert(options, file) ⇒ <code>Promise.&lt;(string\|Error)&gt;</code>

Converts a RTF file to HTML/LaTeX/RTF/TXT.
UnRTF will use the directory of the original file to store embedded pictures.
Expand All @@ -44,7 +44,7 @@ UnRTF will use the directory of the original file to store embedded pictures.

| Param | Type | Description |
| -------------------------- | -------------------- | ----------------------------------------------------------------------------------------- |
| [options] | <code>object</code> | Object containing options to pass to binary. |
| options | <code>object</code> | Object containing options to pass to binary. |
| [options.noPictures] | <code>boolean</code> | Disable the automatic storing of embedded pictures to the directory of the original file. |
| [options.noRemap] | <code>boolean</code> | Disable charset conversion (only works for 8-bit charsets) (UnRTF v0.20.5 or later only). |
| [options.outputHtml] | <code>boolean</code> | Generate HTML output. |
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
},
"scripts": {
"changelog": "conventional-changelog -p @commitlint/config-conventional -s -i CHANGELOG.md && prettier CHANGELOG.md --write",
"doc": "jsdoc2md src/index.js > API.md && prettier API.md --write",
"doc": "tsc && jsdoc2md src/index.js > API.md && prettier API.md --write",
"dupe-check": "yarn jsinspect ./src",
"lint": "eslint . --cache --ext js,jsx,ts,tsx --ignore-path .gitignore",
"prettier": "prettier . --write --ignore-path .gitignore",
Expand Down Expand Up @@ -70,6 +70,7 @@
"jest": "^26.6.0",
"jsdoc-to-markdown": "^6.0.1",
"jsinspect": "^0.12.7",
"prettier": "2.1.2"
"prettier": "2.1.2",
"typescript": "^4.0.3"
}
}
42 changes: 42 additions & 0 deletions src/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
export class UnRTF {
/**
* @param {string=} binPath - Path of UnRTF binary.
* Useful for Linux users who have UnRTF binary already installed.
*/
constructor(binPath?: string | undefined);
unrtfPath: string;
/**
* @author Frazer Smith
* @description Converts a RTF file to HTML/LaTeX/RTF/TXT.
* UnRTF will use the directory of the original file to store embedded pictures.
* @param {object} options - Object containing options to pass to binary.
* @param {boolean=} options.noPictures - Disable the automatic storing of embedded
* pictures to the directory of the original file.
* @param {boolean=} options.noRemap - Disable charset conversion (only works for 8-bit charsets)
* (UnRTF v0.20.5 or later only).
* @param {boolean=} options.outputHtml - Generate HTML output.
* @param {boolean=} options.outputLatex - Generate LaTeX output.
* @param {boolean=} options.outputPs - Generate PostScript (PS) output (UnRTF v0.19.4 or earlier only).
* @param {boolean=} options.outputRtf - Generate RTF output. (UnRTF v0.21.3 or later only).
* @param {boolean=} options.outputText - Generate ASCII text output.
* @param {boolean=} options.outputVt - Generate text output with VT100 escape codes.
* @param {boolean=} options.outputWpml - Generate WPML output (UnRTF v0.19.4 or earlier only).
* @param {boolean=} options.printVersionInfo - Print copyright and version info.
* @param {boolean=} options.quiet - Do not print any leading comments in output (UnRTF v0.21.3 or later only).
* @param {string} file - Filepath of the RTF file to read.
* @returns {Promise<string|Error>} Promise of stdout string on resolve, or Error object on rejection.
*/
convert(options: {
noPictures?: boolean | undefined;
noRemap?: boolean | undefined;
outputHtml?: boolean | undefined;
outputLatex?: boolean | undefined;
outputPs?: boolean | undefined;
outputRtf?: boolean | undefined;
outputText?: boolean | undefined;
outputVt?: boolean | undefined;
outputWpml?: boolean | undefined;
printVersionInfo?: boolean | undefined;
quiet?: boolean | undefined;
}, file: string): Promise<string | Error>;
}
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class UnRTF {
* @author Frazer Smith
* @description Converts a RTF file to HTML/LaTeX/RTF/TXT.
* UnRTF will use the directory of the original file to store embedded pictures.
* @param {object=} options - Object containing options to pass to binary.
* @param {object} options - Object containing options to pass to binary.
* @param {boolean=} options.noPictures - Disable the automatic storing of embedded
* pictures to the directory of the original file.
* @param {boolean=} options.noRemap - Disable charset conversion (only works for 8-bit charsets)
Expand Down
8 changes: 8 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"include": ["src/index.js"],
"compilerOptions": {
"declaration": true,
"emitDeclarationOnly": true,
"allowJs": true
}
}
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5602,6 +5602,11 @@ typedarray-to-buffer@^3.1.5:
dependencies:
is-typedarray "^1.0.0"

typescript@^4.0.3:
version "4.0.3"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.0.3.tgz#153bbd468ef07725c1df9c77e8b453f8d36abba5"
integrity sha512-tEu6DGxGgRJPb/mVPIZ48e69xCn2yRmCgYmDugAVwmJ6o+0u1RI18eO7E7WBTLYLaEVVOhwQmcdhQHweux/WPg==

typical@^2.4.2, typical@^2.6.0, typical@^2.6.1:
version "2.6.1"
resolved "https://registry.yarnpkg.com/typical/-/typical-2.6.1.tgz#5c080e5d661cbbe38259d2e70a3c7253e873881d"
Expand Down

0 comments on commit e2203a6

Please sign in to comment.