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

smug

v0.4.2

Published

Really, really small executable js.

Downloads

5

Readme

smug

Really really minified js via uglify, gzip, base64, and EVAL.

why?

To scratch an itch. Minifying code is common, but how small can you really get it? Well, you could minifiy it, then zip it up...but then it's not actually usable till you unzip it. Well, if you're using node, zlib is already installed, so you could actually programmatically unzip and eval it. If you save it in base64 it's still text, so the intermediate zipped version won't give you any trouble when you try to print it or load it into an editor. Hmmm...

why the name?

base(S)ixtyfour (M)inified (U)glify (G)zip. Smug about being as small as possible. I like jumbled acronyms that also describe or anthropomorphize the project. "smug" seems to apply to something as silly as this - "I have smaller code than you do". Like many smug people, "smug" has a flaw or 4 which it should not be so proud of...

what's the catch?

  • node only
  • use of zlib means that requiring a smugified module is asynchronous. You have to use the .smugly(cb) init function. 'cb' will be called when the module is actually loaded.
  • for small files, minifying the code with uglify-js (which smug uses) results in code which is smaller than smug produces with its minify-gzip-base64-wrap nonsense. In this case, we use the minified code raw, but still add the .smugly callback, because otherwise you'd have to know whether the code was smuglified or just minified in order to use it correctly. This means that for small files, smug will produce a larger file than uglify-js, which is the opposite of the point. Until there's transparent support in node for modules which load asynchronously, this will be a problem.
  • in general, the use of base64 encoding means that the file is larger than it strictly needs to be, but unless you want to split the original file in two (maximally compressed binary + minified shim/loader file), this is the price.

how does it work?

smug is actually pretty straightforward - other modules do the heavy lifting. Here's the basic flow:

  1. pass your file names to uglify-js for some advanced minification.
  2. pass that minified file through node's zlib library to gzip the minified text
  3. convert that gzipped data to base64
  4. wrap that in code which will reverse the process when smugly is called on it
  5. re-minify (with uglify-js again)
  6. return the resulting text

As noted in the prior section, there is a case in which the minified code is as condensed as it will get, because there isn't enough code to compress with gzip - the gains are overwhelmed by the cost of base64 conversion and adding the extraction wrapper code. smug catches that condition, tosses in a smugly function for compatiblility/uniformity, reminifies, and then returns that (non-gzipped) text instead.

example usage please

cli:

npm install -g smug
smugify wisper.js > wisper.smug.js

# wisper.js -> 19k
# wisper.min.js (with uglify-js) -> 9.5k
# wisper.smug.js -> 2.9k

node:

#! /usr/bin/env node

var smug = require('./smug.js');

var files = process.argv.slice(2);

smug.smugify(files, function(error, result) {
    if (error) {
        console.error(error);
    } else {
        console.log(result);
    }
});