Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

pdf2pic

Package Overview
Dependencies
Maintainers
1
Versions
47
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pdf2pic - npm Package Compare versions

Comparing version 2.1.4 to 2.2.0

.github/dependabot.yml

2

dist/index.js

@@ -1,1 +0,1 @@

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("gm"),e=require("path"),i=require("fs-extra"),s=require("stream");function r(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var n=r(t),a=r(e),h=r(i);const o={quality:0,format:"png",width:768,height:512,density:72,savePath:"./",saveFilename:"untitled",compression:"jpeg"};class u{constructor(){this.quality=0,this.format="png",this.width=768,this.height=512,this.density=72,this.savePath="./",this.saveFilename="untitled",this.compression="jpeg",this.gm=n.default.subClass({imageMagick:!1})}generateValidFilename(t){return"number"==typeof t?`${this.savePath}/${this.saveFilename}.${t+1}.${this.format}`:`${this.savePath}/${this.saveFilename}.${this.format}`}gmBaseCommand(t,e){return this.gm(t,e).density(this.density,this.density).resize(this.width,this.height,"!").quality(this.quality).compress(this.compression)}toBase64(t,e){const i=`${t.path}[${e}]`;return new Promise((s,r)=>{this.gmBaseCommand(t,i).stream(this.format,(t,i)=>{let n="";if(t)return r(t);i.on("data",t=>{n+=t.toString("binary")}).on("end",()=>{const t=Buffer.from(n,"binary").toString("base64");return s({base64:t,size:`${this.width}x${this.height}`,page:e+1})})})})}writeImage(t,e){const i=this.generateValidFilename(e),s=`${t.path}[${e}]`;return new Promise((r,n)=>{this.gmBaseCommand(t,s).write(i,t=>t?n(t):r({name:a.default.basename(i),size:`${this.width}x${this.height}`,fileSize:h.default.statSync(i).size/1e3,path:i,page:e+1}))})}identify(t,e){const i=this.gm(t);return new Promise((t,s)=>{e?i.identify(e,(e,i)=>e?s(e):t(i.replace(/^[\w\W]*?1/,"1"))):i.identify((e,i)=>e?s(e):t(i))})}setQuality(t){return this.quality=t,this}setFormat(t){return this.format=t,this}setSize(t,e){return this.width=t,this.height=e||t,this}setDensity(t){return this.density=t,this}setSavePath(t){return this.savePath=t,this}setSaveFilename(t){return this.saveFilename=t,this}setCompression(t){return this.compression=t,this}setGMClass(t){return"boolean"==typeof t?(this.gm=n.default.subClass({imageMagick:t}),this):"imagemagick"===t.toLocaleLowerCase()?(this.gm=n.default.subClass({imageMagick:!0}),this):(this.gm=n.default.subClass({appPath:t}),this)}getOptions(){return{quality:this.quality,format:this.format,width:this.width,height:this.height,density:this.density,savePath:this.savePath,saveFilename:this.saveFilename,compression:this.compression}}}function m(t){return new s.Readable({read(){this.push(t),this.push(null)}})}function f(t,e){if("buffer"===t)return m(e);if("path"===t)return i.createReadStream(e);if("base64"===t)return s=e,m(Buffer.from(s,"base64"));var s;throw new Error("Cannot recognize specified source")}function l(t,e,i,s){return new(i||(i=Promise))((function(r,n){function a(t){try{o(s.next(t))}catch(t){n(t)}}function h(t){try{o(s.throw(t))}catch(t){n(t)}}function o(t){var e;t.done?r(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(a,h)}o((s=s.apply(t,e||[])).next())}))}function c(t,e,i,s=1,r=!1){return l(this,void 0,void 0,(function*(){if(-1!==s&&s<1)throw new Error("Page number should be more than or equal 1");const n=f(e,i),a=f(e,i),h=Array.isArray(s)?s:[s],o=(s=-1===s?yield function(t,e){return l(this,void 0,void 0,(function*(){return(yield t.identify(e,"%p ")).split(" ").map(t=>parseInt(t,10))}))}(t,a):h).map(e=>{if(s<1)throw new Error("Page number should be more than or equal 1");return r?t.toBase64(n,e-1):t.writeImage(n,e-1)});return Promise.all(o)}))}function d(t,e,i=o){const s=new u;i=Object.assign(Object.assign({},o),i);const r=(i=1,r=!1)=>{if(i<1)throw new Error("Page number should be more than or equal 1");const n=f(t,e);return r?s.toBase64(n,i-1):s.writeImage(n,i-1)};return r.bulk=(i,r=!1)=>c(s,t,e,i,r),r.setOptions=()=>function(t,e){return void t.setQuality(e.quality).setFormat(e.format).setSize(e.width,e.height).setDensity(e.density).setSavePath(e.savePath).setSaveFilename(e.saveFilename).setCompression(e.compression)}(s,i),r.setGMClass=t=>{s.setGMClass(t)},r.setOptions(),r}exports.fromBase64=function(t,e=o){return d("base64",t,e)},exports.fromBuffer=function(t,e=o){return d("buffer",t,e)},exports.fromPath=function(t,e=o){return d("path",t,e)};
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("gm"),e=require("path"),i=require("fs-extra"),s=require("stream");function n(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var r=n(t),a=n(e),o=n(i);const h={quality:0,format:"png",width:768,height:512,density:72,savePath:"./",saveFilename:"untitled",compression:"jpeg"};class u{constructor(){this.quality=0,this.format="png",this.width=768,this.height=512,this.density=72,this.savePath="./",this.saveFilename="untitled",this.compression="jpeg",this.gm=r.default.subClass({imageMagick:!1})}generateValidFilename(t){return"number"==typeof t?`${this.savePath}/${this.saveFilename}.${t+1}.${this.format}`:`${this.savePath}/${this.saveFilename}.${this.format}`}gmBaseCommand(t,e){return this.gm(t,e).density(this.density,this.density).resize(this.width,this.height,"!").quality(this.quality).compress(this.compression)}toBase64(t,e){const i=`${t.path}[${e}]`;return new Promise(((s,n)=>{this.gmBaseCommand(t,i).stream(this.format,((t,i)=>{let r="";if(t)return n(t);i.on("data",(t=>{r+=t.toString("binary")})).on("end",(()=>{const t=Buffer.from(r,"binary").toString("base64");return s({base64:t,size:`${this.width}x${this.height}`,page:e+1})}))}))}))}writeImage(t,e){const i=this.generateValidFilename(e),s=`${t.path}[${e}]`;return new Promise(((n,r)=>{this.gmBaseCommand(t,s).write(i,(t=>t?r(t):n({name:a.default.basename(i),size:`${this.width}x${this.height}`,fileSize:o.default.statSync(i).size/1e3,path:i,page:e+1})))}))}identify(t,e){const i=this.gm(t);return new Promise(((t,s)=>{e?i.identify(e,((e,i)=>e?s(e):t(i.replace(/^[\w\W]*?1/,"1")))):i.identify(((e,i)=>e?s(e):t(i)))}))}setQuality(t){return this.quality=t,this}setFormat(t){return this.format=t,this}setSize(t,e){return this.width=t,this.height=e||t,this}setDensity(t){return this.density=t,this}setSavePath(t){return this.savePath=t,this}setSaveFilename(t){return this.saveFilename=t,this}setCompression(t){return this.compression=t,this}setGMClass(t){return"boolean"==typeof t?(this.gm=r.default.subClass({imageMagick:t}),this):"imagemagick"===t.toLocaleLowerCase()?(this.gm=r.default.subClass({imageMagick:!0}),this):(this.gm=r.default.subClass({appPath:t}),this)}getOptions(){return{quality:this.quality,format:this.format,width:this.width,height:this.height,density:this.density,savePath:this.savePath,saveFilename:this.saveFilename,compression:this.compression}}}function m(t){return new s.Readable({read(){this.push(t),this.push(null)}})}function f(t,e){if("buffer"===t)return m(e);if("path"===t)return i.createReadStream(e);if("base64"===t)return s=e,m(Buffer.from(s,"base64"));var s;throw new Error("Cannot recognize specified source")}function l(t,e,i,s){return new(i||(i=Promise))((function(n,r){function a(t){try{h(s.next(t))}catch(t){r(t)}}function o(t){try{h(s.throw(t))}catch(t){r(t)}}function h(t){var e;t.done?n(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(a,o)}h((s=s.apply(t,e||[])).next())}))}function c(t,e,i,s,n=!1){const r=f(e,i),a=s.map((e=>{if(e<1)throw new Error("Page number should be more than or equal 1");return n?t.toBase64(r,e-1):t.writeImage(r,e-1)}));return Promise.all(a)}function d(t,e,i,s=1,n=!1){return l(this,void 0,void 0,(function*(){const r=-1===s?yield function(t,e){return l(this,void 0,void 0,(function*(){return(yield t.identify(e,"%p ")).split(" ").map((t=>parseInt(t,10)))}))}(t,f(e,i)):Array.isArray(s)?s:[s],a=[];for(let s=0;s<r.length;s+=10)a.concat(...yield c(t,e,i,r.slice(s,s+10),n));return a}))}function g(t,e,i=h){const s=new u;i=Object.assign(Object.assign({},h),i);const n=(i=1,n=!1)=>{if(i<1)throw new Error("Page number should be more than or equal 1");const r=f(t,e);return n?s.toBase64(r,i-1):s.writeImage(r,i-1)};return n.bulk=(i,n=!1)=>d(s,t,e,i,n),n.setOptions=()=>function(t,e){return void t.setQuality(e.quality).setFormat(e.format).setSize(e.width,e.height).setDensity(e.density).setSavePath(e.savePath).setSaveFilename(e.saveFilename).setCompression(e.compression)}(s,i),n.setGMClass=t=>{s.setGMClass(t)},n.setOptions(),n}exports.fromBase64=function(t,e=h){return g("base64",t,e)},exports.fromBuffer=function(t,e=h){return g("buffer",t,e)},exports.fromPath=function(t,e=h){return g("path",t,e)};
import { WriteImageResponse } from "./writeImageResponse";
import { ToBase64Response } from "./toBase64Response";
export declare type Convert = {
export type Convert = {
bulk?: (pages?: number | number[], toBase64?: boolean) => Promise<WriteImageResponse[] | ToBase64Response[]>;

@@ -5,0 +5,0 @@ setOptions?: () => void;

@@ -1,2 +0,2 @@

export declare type Options = {
export type Options = {
quality?: number;

@@ -3,0 +3,0 @@ format?: string;

@@ -1,2 +0,2 @@

export declare type ToBase64Response = {
export type ToBase64Response = {
base64?: string;

@@ -3,0 +3,0 @@ size?: string;

@@ -1,2 +0,2 @@

export declare type WriteImageResponse = {
export type WriteImageResponse = {
name?: string;

@@ -3,0 +3,0 @@ size?: string;

/// <reference types="node" />
/// <reference types="node" />
import { ReadStream } from "fs-extra";
export declare function bufferToStream(buffer: Buffer): ReadStream;
/// <reference types="node" />
/// <reference types="node" />
import { ReadStream } from "fs-extra";
export declare function convertToStream(source: string, file: string | Buffer): ReadStream;
{
"name": "pdf2pic",
"version": "2.1.4",
"version": "2.2.0",
"description": "A utility for converting pdf to image and base64 format.",

@@ -8,3 +8,3 @@ "main": "dist/index.js",

"dependencies": {
"fs-extra": "^9.1.0",
"fs-extra": "^10.0.0",
"gm": "^1.23.1"

@@ -21,3 +21,3 @@ },

"@types/mocha": "^8.2.0",
"@types/node": "^14.14.25",
"@types/node": "^15.0.0",
"@types/rimraf": "^3.0.0",

@@ -28,3 +28,3 @@ "@typescript-eslint/eslint-plugin": "^4.14.2",

"eslint": "^7.19.0",
"mocha": "^8.2.1",
"mocha": "^9.0.0",
"nyc": "^15.1.0",

@@ -34,4 +34,4 @@ "rimraf": "^3.0.2",

"rollup-plugin-terser": "^7.0.2",
"rollup-plugin-typescript2": "^0.29.0",
"ts-node": "^9.1.1",
"rollup-plugin-typescript2": "^0.30.0",
"ts-node": "^10.0.0",
"tsconfig-paths": "^3.9.0",

@@ -42,3 +42,3 @@ "tslib": "^2.1.0",

"scripts": {
"mocha": "./node_modules/.bin/mocha test/**/*.test.ts",
"mocha": "mocha test/**/*.test.ts",
"test": "npm run lint && nyc --reporter=lcov npm run mocha",

@@ -45,0 +45,0 @@ "test:text": "npm run lint && nyc --reporter=text npm run mocha",

@@ -117,6 +117,6 @@ # PDF2Pic

```javascript
fromBuffer(buffer, options).convert(pageNumber, isBase64)
fromBuffer(buffer, options)(pageNumber, isBase64)
```
Functions same as `fromPath(filePath, options).convert(pageNumber, isBase64)` only input is changed
Functions same as `fromPath(filePath, options)(pageNumber, isBase64)` only input is changed

@@ -149,6 +149,6 @@ ---

```javascript
fromBase64(b64string, options).convert(pageNumber, isBase64)
fromBase64(b64string, options)(pageNumber, isBase64)
```
Functions same as `fromPath(filePath, options).convert(pageNumber, isBase64)` only input is changed
Functions same as `fromPath(filePath, options)(pageNumber, isBase64)` only input is changed

@@ -155,0 +155,0 @@ ---

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