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

abridge

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

abridge

Minifier based on srod/node-minify, with various improvemens.

  • 0.2.10
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
114
decreased by-67.52%
Maintainers
1
Weekly downloads
 
Created
Source

Abridge

npm install abridge

Abridge is a wild fork of node-minify module. It is not a drop-in replacement, but improves upon the original code in various ways.

  • Dropped support for Google Closure
  • Dropped no-minify file concat
  • Do not create temporary files, pipe to chld process's stdin instead
  • Use streams wherever possible
  • Supply minified data to callbacks
  • Major API improvements

Usage

The old API style is mostly preserved.

var Minifier = require('abridge').Minifier;

var minifier = new Minifier({
    type: 'yui',
    fileIn: 'public/js/base.js',
    fileOut: 'public/js/base-min.js',
    callback: function(err){
        console.log(err);
    }
});

minifier.compress();

But now we can just call the minify function without creating an instance of Minify:

var abridge = require('abridge');
var options = {
    type: 'yui',
    fileIn: 'public/js/base.js',
    fileOut: 'public/js/base-min.js',
    callback: function(err){
        console.log(err);
    }
};

abridge.minify(options);

We can also supply a callback as a second argument, as per tradition:

var options = {
    type: 'yui',
    fileIn: 'public/js/base.js',
    fileOut: 'public/js/base-min.js'
};

abridge.minify(options, function(err) {
    console.log(err);
});

And our callback is given the minified data:

abridge.minify(options, function(err, data) {
    console.log(err, data);
});

Also fileOut and type are optional. If CSS is detected, Abridge will default to YUICompressor, as uglifyjs compresses only JavaScript. However, if minifying JavaScript, Abridge will use Uglify-js instead, as it is more efficient:

var options = {
    fileIn: 'public/js/base.js'
};

abridge.minify(options, console.log);

In fact you no longer need an options object:

var fileIn = ['public/js/base.js', 'public/js/somn.js'];
var fileOut = 'public/js/common.js';
abridge.minify(fileIn, fileOut, console.log);

In the simplest case, we have:

abridge.minify('public/js/base.js', function(err, data) {

});

The function also returns a pipeable Stream instance:

var http = require('http');
var server = new http.Server();

server.addListener('request', function(req, res) {
    var url = req.url;
    if (/^\/files/.test(url)) {
       url = url.substring(1);
       abridge.minify(url).pipe(res);
    };
});

But this would be absurdly inefficient without file caching. See Lactate for that.

Note

To use YUICompressor (default for CSS files) you must have Java installed.

FAQs

Package last updated on 11 Oct 2012

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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