Skip to content

Commit

Permalink
Merge pull request #281 from Fdawgs/fix/defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
Fdawgs committed May 13, 2023
2 parents ed2b694 + 44fddd2 commit c480dc7
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

### unRTF.convert(file, [options]) ⇒ <code>Promise.&lt;(string\|Error)&gt;</code>
Converts an RTF file to HTML/LaTeX/RTF/TXT.
Defaults to HTML output if no `output*` options are provided.
UnRTF will use the directory of the original file to store embedded pictures.

**Kind**: instance method of [<code>UnRTF</code>](#UnRTF)
Expand Down
5 changes: 5 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ function parseOptions(acceptedOptions, options, version) {
if (Object.prototype.hasOwnProperty.call(acceptedOptions, key)) {
// eslint-disable-next-line valid-typeof
if (typeof options[key] === acceptedOptions[key].type) {
// Skip boolean options if false
if (acceptedOptions[key].type === "boolean" && !options[key]) {
return;
}
args.push(acceptedOptions[key].arg);
} else {
invalidArgs.push(
Expand Down Expand Up @@ -89,6 +93,7 @@ class UnRTF {
/**
* @author Frazer Smith
* @description Converts an RTF file to HTML/LaTeX/RTF/TXT.
* Defaults to HTML output if no `output*` options are provided.
* UnRTF will use the directory of the original file to store embedded pictures.
* @param {string} file - Filepath of the RTF file to read.
* @param {object=} options - Object containing options to pass to binary.
Expand Down
24 changes: 24 additions & 0 deletions src/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,30 @@ describe("Convert function", () => {
expect(isHtml(res)).toBe(true);
});

it("Converts RTF file to HTML if the `output*` option is set to false", async () => {
const outputOptions = [
"outputHtml",
"outputLatex",
"outputText",
"outputVt",
];

const unRtf = new UnRTF(testBinaryPath);

await Promise.all(
outputOptions.map(async (option) => {
const options = {
noPictures: true,
[option]: false,
};

const res = await unRtf.convert(file, options);

expect(isHtml(res)).toBe(true);
})
);
});

it("Converts RTF file to HTML without storing images", async () => {
const unRtf = new UnRTF(testBinaryPath);
const options = {
Expand Down
1 change: 1 addition & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export class UnRTF {
/**
* @author Frazer Smith
* @description Converts an RTF file to HTML/LaTeX/RTF/TXT.
* Defaults to HTML output if no `output*` options are provided.
* UnRTF will use the directory of the original file to store embedded pictures.
* @param {string} file - Filepath of the RTF file to read.
* @param {object=} options - Object containing options to pass to binary.
Expand Down

0 comments on commit c480dc7

Please sign in to comment.