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

regpack

v5.0.1

Published

A packer intended for use on minified Javascript code

Downloads

42

Readme

RegPack is a packer intended for use on minified Javascript code. Current revision is 5.0.1

It is mostly suited to small size constraints (1kb, up to 4kb).

The current version works in seven stages :

  • (if enabled) 2D, WebGL and Audio contexts method shortcuts are defined and used instead of the long, original names.
  • (if enabled) variables are renamed in order to reduce character footprint and free tokens for compression.
  • (if enabled) Initialization code is pushed inside the main loop, with conditional execution on the time variable, so that the unpacker can execute everything through setInterval()
  • string quotes are altered in order to minimize escaping inside the strings
  • redundancies are eliminated and replaced by tokens, as done by JS Crush (by Aivo Paas) and First Crush (by Tim Down).
  • the token list is turned into a regular expression consisting in a character class.
  • the tokens are rearranged to create a negated character class (starting with a hyphen ^ then listing nontoken characters)

The text boxes show intermediate stage results. Best one gets a green highlight :

  • Preprocessed : after the first four stages. Hidden if no change was brought to the initial code.
  • Crushed : after the fifth stage
  • RegPack'ed : best between last two stages. Depends on how the characters present in the string are spread in the ASCII table.

--

Usage tips

  • Toggle method hashing for any type of context you use. If the method renaming yields a longer code, RegPack will revert to the original one.
  • "Assume global .. is a context" is for environments where the canvas is declared before your code. If entering js1k, keep this on, variable is c for classic and g for webgl.
  • Variable renaming is also performed inside strings, RegPack does not infer whether they are eval()ed or not. Disable if facing issues with this. Only one-letter variables are considered, others are ignored.
  • Crusher settings alter the choice of strings to compress. 1/0/0 is a good allrounder, although more exotic values can yield better results depending on your code.
  • Some preprocessing options negatively affect the performance and should be used with caution. Always test your packed code for speed after using these.
    • "Encapsulate with(Math)" get rid of all "Math." references in the code and enclose the evaluation with(Math).
    • "run with setInterval()" executes the unpacked code with setInterval() instead of eval() (meaning the evaluation is performed every frame).

Use it online or integrate it into your Node workflow (thanks to kanaka)

CLI usage

regpack input.js > output.js
regpack input.js --crushGainFactor 1 --crushLengthFactor 0 --crushCopiesFactor 0 > output.js

From STDIN

cat input.js | regpack - > output.js

--

Running unit tests with Node

cd tests
node AllTests

--

License

Licensed under MIT license.

Code produced by RegPack, including the hashing (if included) and unpacking routines, is not affected by the license. No restriction to its usage or redistribution arise from its compression by RegPack.

--

Any feedback or improvement suggestions appreciated. Contributions welcome.

@Siorki on Twitter