npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

massage

v0.11.1

Published

functions to help you interact with files

Downloads

110

Readme

Massage

NPM version Downloads Build Status Dependency Status Coverage Status

Dependencies

###ImageMagick and GhostScript

  osx> brew install imagemagick ghostscript
  ubuntu> sudo apt-get install imagemagick ghostscript pdftk

###PDFtk Go to http://www.pdflabs.com/tools/pdftk-server/ for official installation of PDFtk

Usage

#####getMetaData( [Buffer image] ) -> Object

Returns a promise of an object with metadata about the buffer, as told by ImageMagick.

{
  fileType: 'pdf|png|jpg|etc...' [String]
  width: document width in inches [Number]
  length: document length in inches [Number]
  numPages: number of images in the image sequence (number of pages in the PDF) [Number]
}

If ImageMagick's identify tool can't handle the passed buffer, then the promise is rejected.

var myDoc = Fs.readFileSync('myDoc.pdf');
Massage.getMetaData(myPic)
.then(function (data) {
  console.log(data.fileType); // 'PDF'
  console.log(data.width); // '8.5'
  console.log(data.length); // '11'
  console.log(data.numPages); // '2'
});

#####validateUrl( [String url] ) -> String

Returns a promise that is rejected if the given URL is not valid. Otherwise it resolves to the URL.

Massage.validateUrl('https://www.google.com')
.then(function doStuff (url) {
  dependOnURLBeingValid(); // ok
});

#####getBuffer( [String url|Buffer buffer|Object options] ) -> Buffer

Takes a buffer, a URL, or an options object and return a Promise that resolves to a buffer. If you pass an options object it is passed into the request.js constructor, but if you don't supply a method, timeout, or encoding, they default to GET, 10000, and null respectively. The promise always resolves to a buffer which is either the passed buffer or the result of request.js GET'ing the URL.

#####getStream( [String url] ) -> Stream

Takes a URL determines if it is valid and if so returns a readable stream.

If the URL is invalid or request.js fails, the promise is rejected.

#####merge( [Buffer/Stream pdf], [Buffer/Stream pdf] ) -> Stream pdf

Massage.getBuffer('http://internet.site/myPic.jpg')
.then(function (myPic) {
  return Fs.writeFileSync('myPic.jpg', myPic);
});

Merge two PDFs using pdftk and returns a promise which resolves to the resulting rotated pdf (as a stream.)

Could be rejected if pdftk chokes on the files, or you don't have enough disk space to write the results.

#####rotatePdf( [Buffer/Stream pdf], [Number degrees] ) -> Stream pdf

var first  = Fs.readFileSync('firstHalf.pdf');
var second = Fs.readFileSync('secondHalf.pdf');
Massage.merge(first, second)
.then(function (merged) {
  return Fs.writeFileSync('wholeThing.pdf', merged);
});

Returns a promise which resolves to the pdf, rotated clockwise by the given number of degrees. Backed by ImageMagick convert.

Could be rejected if convert chokes on the buffer, or you don't have enough disk space to write the results.

#####burstPdf( [Buffer/Stream pdf] ) -> [Stream]

var wrongWay = Fs.readFileSync('sideways.pdf');
Massage.rotatePdf(wrongWay, 90)
.then(function (rightWay) {
  Fs.writeFileSync('corrected.pdf', rightWay);
});

Takes a multi-page PDF buffer and returns a promise of an array of 1-page pdf streams. Backed by pdftk's burst utility. Always resolves to an array, even if there's just one page in the PDF.

Could be rejected if pdftk chokes on the buffer, or you don't have enough disk space to write the results.

#####imageToPdf( [Buffer/Stream image], [Number dpi] ) -> Stream pdf

Takes a buffer containing an image file and converts it to pdf format at the specified DPI. Returns a promise that resolves to a stream containing the pdf file. Backed by ImageMagick convert.

Could be rejected if convert chokes on the buffer, or you don't have enough disk space to write the results.

var jpegPic = Fs.readFileSync('me.jpg');
Massage.imageToPdf(jpegPic, 300)
.then(function (pdf) {
  // pdf is a pdf of me.jpg
});