Skip to content

Commit

Permalink
refactor(index): remove options if statement; make each option arg obj
Browse files Browse the repository at this point in the history
  • Loading branch information
Frazer Smith committed Apr 1, 2020
1 parent 61899b0 commit 20a33f3
Showing 1 changed file with 48 additions and 72 deletions.
120 changes: 48 additions & 72 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class Poppler {
* @param {String} outputFile - Filepath of the file to output the results to.
* @returns {Promise}
*/
pdfAttach(options, file, fileToAttach, outputFile) {
pdfAttach(options = {}, file, fileToAttach, outputFile) {
return new Promise((resolve, reject) => {
const acceptedOptions = {
printVersionInfo: { arg: '-v', type: 'boolean' },
Expand All @@ -104,11 +104,9 @@ class Poppler {
* Check each option provided is valid and of the correct type,
* before adding it to argument list.
*/
if (options) {
parseOptions(options, acceptedOptions, args).catch((err) => {
reject(err);
});
}
parseOptions(options, acceptedOptions, args).catch((err) => {
reject(err);
});

args.push(file);
args.push(fileToAttach);
Expand Down Expand Up @@ -152,7 +150,7 @@ class Poppler {
* @param {String} file - Filepath of the PDF file to read.
* @returns {Promise}
*/
pdfDetach(options, file) {
pdfDetach(options = {}, file) {
return new Promise((resolve, reject) => {
const acceptedOptions = {
listEmbedded: { arg: '-list', type: 'boolean' },
Expand All @@ -172,11 +170,9 @@ class Poppler {
* Check each option provided is valid and of the correct type,
* before adding it to argument list.
*/
if (options) {
parseOptions(options, acceptedOptions, args).catch((err) => {
reject(err);
});
}
parseOptions(options, acceptedOptions, args).catch((err) => {
reject(err);
});

args.push(file);

Expand Down Expand Up @@ -209,7 +205,7 @@ class Poppler {
* @param {String} file - Filepath of the PDF file to read.
* @returns {Promise}
*/
pdfFonts(options, file) {
pdfFonts(options = {}, file) {
return new Promise((resolve, reject) => {
const acceptedOptions = {
firstPageToExamine: { arg: '-f', type: 'number' },
Expand All @@ -227,11 +223,9 @@ class Poppler {
* Check each option provided is valid and of the correct type,
* before adding it to argument list.
*/
if (options) {
parseOptions(options, acceptedOptions, args).catch((err) => {
reject(err);
});
}
parseOptions(options, acceptedOptions, args).catch((err) => {
reject(err);
});

args.push(file);

Expand Down Expand Up @@ -273,7 +267,7 @@ class Poppler {
* @param {String} file - Filepath of the PDF file to read.
* @param {String} outputPrefix - Filename prefix of output files.
*/
pdfImages(options, file, outputPrefix) {
pdfImages(options = {}, file, outputPrefix) {
return new Promise((resolve, reject) => {
const acceptedOptions = {
allFiles: { arg: '-all', type: 'boolean' },
Expand All @@ -298,11 +292,9 @@ class Poppler {
* Check each option provided is valid and of the correct type,
* before adding it to argument list.
*/
if (options) {
parseOptions(options, acceptedOptions, args).catch((err) => {
reject(err);
});
}
parseOptions(options, acceptedOptions, args).catch((err) => {
reject(err);
});

args.push(file);
if (outputPrefix) {
Expand Down Expand Up @@ -355,7 +347,7 @@ class Poppler {
* @param {String} file - Filepath of the PDF file to read.
* @returns {Promise}
*/
pdfInfo(options, file) {
pdfInfo(options = {}, file) {
return new Promise((resolve, reject) => {
const acceptedOptions = {
firstPageToConvert: { arg: '-f', type: 'number' },
Expand All @@ -382,11 +374,9 @@ class Poppler {
* Check each option provided is valid and of the correct type,
* before adding it to argument list.
*/
if (options) {
parseOptions(options, acceptedOptions, args).catch((err) => {
reject(err);
});
}
parseOptions(options, acceptedOptions, args).catch((err) => {
reject(err);
});

args.push(file);

Expand Down Expand Up @@ -422,7 +412,7 @@ class Poppler {
* As an example, 'sample-%d.pdf' will produce 'sample-1.pdf' for a single page document.
* @returns {Promise}
*/
pdfSeparate(options, file, outputPattern) {
pdfSeparate(options = {}, file, outputPattern) {
return new Promise((resolve, reject) => {
const acceptedOptions = {
firstPageToExtract: { arg: '-f', type: 'number' },
Expand All @@ -437,11 +427,9 @@ class Poppler {
* Check each option provided is valid and of the correct type,
* before adding it to argument list.
*/
if (options) {
parseOptions(options, acceptedOptions, args).catch((err) => {
reject(err);
});
}
parseOptions(options, acceptedOptions, args).catch((err) => {
reject(err);
});

args.push(file);
args.push(outputPattern);
Expand Down Expand Up @@ -548,7 +536,7 @@ class Poppler {
* @param {String=} outputFile - Filepath of the file to output the results to.
* @returns {Promise}
*/
pdfToCairo(options, file, outputFile) {
pdfToCairo(options = {}, file, outputFile) {
return new Promise((resolve, reject) => {
const acceptedOptions = {
antialias: { arg: '-antialias', type: 'string' },
Expand Down Expand Up @@ -605,11 +593,9 @@ class Poppler {
* Check each option provided is valid and of the correct type,
* before adding it to argument list.
*/
if (options) {
parseOptions(options, acceptedOptions, args).catch((err) => {
reject(err);
});
}
parseOptions(options, acceptedOptions, args).catch((err) => {
reject(err);
});

args.push(file);
if (outputFile) {
Expand Down Expand Up @@ -667,7 +653,7 @@ class Poppler {
* @param {String} file - Filepath of the PDF file to read.
* @returns {Promise}
*/
pdfToHtml(options, file) {
pdfToHtml(options = {}, file) {
return new Promise((resolve, reject) => {
const acceptedOptions = {
complexOutput: { arg: '-c', type: 'boolean' },
Expand Down Expand Up @@ -701,11 +687,9 @@ class Poppler {
* Check each option provided is valid and of the correct type,
* before adding it to argument list.
*/
if (options) {
parseOptions(options, acceptedOptions, args).catch((err) => {
reject(err);
});
}
parseOptions(options, acceptedOptions, args).catch((err) => {
reject(err);
});

args.push(file);

Expand Down Expand Up @@ -784,7 +768,7 @@ class Poppler {
* @param {String} outputPath - Filepath to output the results to.
* @returns {Promise}
*/
pdfToPpm(options, file, outputPath) {
pdfToPpm(options = {}, file, outputPath) {
return new Promise((resolve, reject) => {
const acceptedOptions = {
antialiasFonts: { arg: '-aa', type: 'string' },
Expand Down Expand Up @@ -827,11 +811,9 @@ class Poppler {
* Check each option provided is valid and of the correct type,
* before adding it to argument list.
*/
if (options) {
parseOptions(options, acceptedOptions, args).catch((err) => {
reject(err);
});
}
parseOptions(options, acceptedOptions, args).catch((err) => {
reject(err);
});

args.push(file);
args.push(outputPath);
Expand Down Expand Up @@ -939,7 +921,7 @@ class Poppler {
* @param {String} outputFile - Filepath of the file to output the results to.
* @returns {Promise}
*/
pdfToPs(options, file, outputFile) {
pdfToPs(options = {}, file, outputFile) {
return new Promise((resolve, reject) => {
const acceptedOptions = {
antialias: { arg: '-aaRaster', type: 'string' },
Expand Down Expand Up @@ -992,11 +974,9 @@ class Poppler {
* Check each option provided is valid and of the correct type,
* before adding it to argument list.
*/
if (options) {
parseOptions(options, acceptedOptions, args).catch((err) => {
reject(err);
});
}
parseOptions(options, acceptedOptions, args).catch((err) => {
reject(err);
});

args.push(file);
args.push(outputFile);
Expand Down Expand Up @@ -1059,7 +1039,7 @@ class Poppler {
* @param {String=} outputFile - Filepath of the file to output the results to.
* @returns {Promise}
*/
pdfToText(options, file, outputFile) {
pdfToText(options = {}, file, outputFile) {
return new Promise((resolve, reject) => {
const acceptedOptions = {
boundingBoxXhtml: { arg: '-bbox', type: 'boolean' },
Expand Down Expand Up @@ -1096,11 +1076,9 @@ class Poppler {
* Check each option provided is valid and of the correct type,
* before adding it to argument list.
*/
if (options) {
parseOptions(options, acceptedOptions, args).catch((err) => {
reject(err);
});
}
parseOptions(options, acceptedOptions, args).catch((err) => {
reject(err);
});

args.push(file);
if (outputFile) {
Expand Down Expand Up @@ -1133,7 +1111,7 @@ class Poppler {
* @param {String=} outputFile - Filepath of the file to output the resulting merged PDF to.
* @returns {Promise}
*/
pdfUnite(options, files, outputFile) {
pdfUnite(options = {}, files, outputFile) {
return new Promise((resolve, reject) => {
const acceptedOptions = {
printVersionInfo: { arg: '-v', type: 'boolean' }
Expand All @@ -1146,11 +1124,9 @@ class Poppler {
* Check each option provided is valid and of the correct type,
* before adding it to argument list.
*/
if (options) {
parseOptions(options, acceptedOptions, args).catch((err) => {
reject(err);
});
}
parseOptions(options, acceptedOptions, args).catch((err) => {
reject(err);
});

files.forEach((element) => {
args.push(element);
Expand Down

0 comments on commit 20a33f3

Please sign in to comment.