Comparing version 1.0.0-alpha to 1.0.1-alpha
48
index.js
@@ -9,26 +9,2 @@ const imagemagick = require("imagemagick-stream"); | ||
const pdftobuffer = async (pdf, page, progress = false) => { | ||
const pdfcount = await pdftocount(pdf); | ||
assert(Buffer.isBuffer(pdf) || isstream.readable(pdf), 'The pdf must be either a readable stream or a buffer'); | ||
if (page !== "all" && !Array.isArray(page)) { | ||
assert((pdfcount - 1) >= page, 'the page does not exist please try again'); | ||
assert(typeof page === 'number', `page should be one number, given ${page}`); | ||
assert(Number.isInteger(page), `page should be an integer, given ${page}`); | ||
assert(page >= 0, `the page must be equal to or greater than 0 in the case of ${page}`); | ||
} else if(Array.isArray(page)) { | ||
Array.from(page, (_) => assert((pdfcount - 1) >= _, 'the page does not exist please try again')); | ||
} | ||
const bar = progress ? new ProgressBar('Processing [:bar] :percent :etas', { complete: '=', incomplete: ' ', width: 30, total: page === "all" ? pdfcount : 1 }) : null; | ||
if (page === "all" || Array.isArray(page)) { | ||
const promises = Array.from(Array.isArray(page) ? page : { length: pdfcount }, (_, index) => imagemagickconverter(pdf, Array.isArray(page) ? _ : index, progress ? bar : null)); | ||
return Promise.all(promises); | ||
} else { | ||
return [await imagemagickconverter(pdf, page, progress ? bar : null)]; | ||
} | ||
} | ||
const imagemagickconverter = async (pdf, page, bar) => { | ||
@@ -73,2 +49,26 @@ const imagemagickstream = imagemagick() | ||
const pdftobuffer = async (pdf, page, progress = false) => { | ||
const pdfcount = await pdftocount(pdf); | ||
assert(Buffer.isBuffer(pdf) || isstream.readable(pdf), 'The pdf must be either a readable stream or a buffer'); | ||
if (page !== "all" && !Array.isArray(page)) { | ||
assert((pdfcount - 1) >= page, 'the page does not exist please try again'); | ||
assert(typeof page === 'number', `page should be one number, given ${page}`); | ||
assert(Number.isInteger(page), `page should be an integer, given ${page}`); | ||
assert(page >= 0, `the page must be equal to or greater than 0 in the case of ${page}`); | ||
} else if(Array.isArray(page)) { | ||
Array.from(page, (_) => assert((pdfcount - 1) >= _, 'the page does not exist please try again')); | ||
} | ||
const bar = progress ? new ProgressBar('Processing [:bar] :percent :etas', { complete: '=', incomplete: ' ', width: 30, total: page === "all" ? pdfcount : 1 }) : null; | ||
if (page === "all" || Array.isArray(page)) { | ||
const promises = Array.from(Array.isArray(page) ? page : { length: pdfcount }, (_, index) => imagemagickconverter(pdf, Array.isArray(page) ? _ : index, progress ? bar : null)); | ||
return Promise.all(promises); | ||
} else { | ||
return [await imagemagickconverter(pdf, page, progress ? bar : null)]; | ||
} | ||
} | ||
const pdftocount = async (pdf) => { | ||
@@ -75,0 +75,0 @@ const pdfDoc = await PDFDocument.load(pdf); |
@@ -1,23 +0,5 @@ | ||
const exp = require("constants"); | ||
const pdftopic = require("./"); | ||
const fs = require("fs"); | ||
/*test('converting pdftopic@0.1.3 (single file)', async () => { | ||
test('converting pdftopic@1.0.0 (single file)', async () => { | ||
const pdf = fs.readFileSync('./pdf_files/ilyes.pdf'); | ||
const result = await pdftobuffer(pdf, 0); | ||
expect(result).not.toBeNull(); | ||
}); | ||
test('converting pdftopic@0.1.3 (multiple file)', async () => { | ||
const pdf = fs.readFileSync('./pdf_files/curriculum_vitae.pdf'); | ||
var results = []; | ||
for (let index = 0; index < 4; index++) { | ||
const result = await pdftobuffer(pdf, index); | ||
results.push(result); | ||
} | ||
expect(results).not.toBeNull(); | ||
});*/ | ||
/*test('converting pdftopic@1.0.0 (single file)', async () => { | ||
const pdf = fs.readFileSync('./pdf_files/ilyes.pdf'); | ||
const result = await pdftopic.pdftobuffer(pdf, 0); | ||
@@ -37,3 +19,3 @@ expect(result).not.toBeNull(); | ||
expect(result).not.toBeNull(); | ||
});*/ | ||
}); | ||
@@ -40,0 +22,0 @@ test('converting pdftopic@1.0.0 (all images in one image)', async () => { |
{ | ||
"name": "pdftopic", | ||
"version": "1.0.0-alpha", | ||
"version": "1.0.1-alpha", | ||
"description": "Built for Node.js, this package empowers users to effortlessly convert PDF files into images of exceptional quality, supporting multiple formats including PNG, JPG, GIF, and others. Its streamlined functionality ensures a smooth and reliable conversion process, providing users with the flexibility to obtain top-notch images from their PDF documents", | ||
"main": "index.js", | ||
"funding":{ | ||
"type": "paypal", | ||
"url": "https://www.paypal.me/IlyesElMajouti" | ||
}, | ||
"scripts": { | ||
@@ -51,3 +55,3 @@ "test": "jest" | ||
], | ||
"author": "Ilyes-El-Majouti", | ||
"author": "Ilyes-El-Majouti <ilyes.elmajouti@gmail.com>", | ||
"license": "ISC", | ||
@@ -65,3 +69,2 @@ "bugs": { | ||
"sharp": "^0.32.6", | ||
"stream": "^0.0.2", | ||
"stream-to-array": "^2.3.0" | ||
@@ -68,0 +71,0 @@ }, |
Sorry, the diff of this file is not supported yet
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
7
0
3009476
138
- Removedstream@^0.0.2
- Removedemitter-component@1.1.2(transitive)
- Removedstream@0.0.2(transitive)