diff --git a/src/index.js b/src/index.js index 98e2d7c4..cecf3afe 100644 --- a/src/index.js +++ b/src/index.js @@ -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' }, @@ -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); @@ -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' }, @@ -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); @@ -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' }, @@ -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); @@ -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' }, @@ -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) { @@ -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' }, @@ -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); @@ -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' }, @@ -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); @@ -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' }, @@ -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) { @@ -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' }, @@ -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); @@ -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' }, @@ -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); @@ -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' }, @@ -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); @@ -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' }, @@ -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) { @@ -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' } @@ -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);