New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

pdftopic

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pdftopic - npm Package Compare versions

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc