You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

js1k-compress

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

js1k-compress

1K LZ77 source compression npm module

0.0.1
latest
Source
npmnpm
Version published
Maintainers
1
Created
Source

<img src=https://js1k-compress.solsort.com/icon.png width=96 height=96 align=right>

website github travis npm

1K source compression npm module

Two source code compressors, for JS1K. Makes self-extracting JavaScript. Both are less than 1KB.

Full of bugs, may or may not work :)

  • Version 1 is grammar based compression, (awesome theory), with a greedy binary grammar. The compression is quite bad, as I originally designed for byte, and not utf-8 encoding. Redesigning for utf-8 encoding thus made the grammar very small. It compresses itself from 1226 bytes to 968 bytes.
  • Version 2 is semi-lz77. This is more suitable for self-extracting utf-8 encoded JavaScript. It only works for small programs up to ~2K, without unicode characters, and has other bugs. It compresses itself from 2040 bytes to 687 characters = 995 bytes.

Usage example:

$ npm install js1k-compress

[...]

$ node 

> compress = require('js1k-compress')

[Function]

> compressed = compress(require('fs').readFileSync('lz.js','utf-8'));

'(f=(i,o,p,c)=>(c=i.charCodeAt(p),c?f(i,o+(c<256?i[p]:o.slice(c&2047,(c&2047)+(c>>11))),++p):o))(`/***᠁、态쀁ꀁ\\n *   ᡈえ恈쁈遈1K LZ77 source compression npm module碅See http://js1k-䃱.solsort.ᣱ for descript⃹境...

> console.log(eval(compressed));

/********************************************************************
 *                                                                  *
 *                                                                  *
 *              1K LZ77 source compression npm module               *
 *                                                                  *
 *                                                                  *
 *      See http://js1k-compress.solsort.com for description        *
 *                                                                  *
 *                                                                  *
 *                                                                  *
 ********************************************************************/

var compress = input => {
[...]


> require('fs').writeFile('./lz.min.js', 'eval(' + compressed + ')');

undefined

> require('lz.min.js');

[Function]

> // lz.js has now been minified, saved as lz.min.js, and is working :)

Files:

  • grammar.js - version 1, grammar based compression
  • lz.js - version 2, semi-lz77
  • entry-* compressed versions of above
  • build.js node script that uses the module, and makes the entries
  • index.html shows the readme, and runs some of the entries in the browser

Keywords

js1k

FAQs

Package last updated on 11 Feb 2017

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