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

lzjs

v1.3.1

Published

A JavaScript library for compressing and decompressing strings using an original algorithm based on the LZ algorithm

Downloads

7,049

Readme

lzjs

GitHub Actions Build Status

lzjs is a JavaScript library that compresses and decompresses strings using an original algorithm based on the LZ algorithm.

This can be particularly useful when storing large amounts of data in storage with size limitations, such as localStorage or cookies.

Installation

npm

$ npm install --save lzjs

using import

import lzjs from 'lzjs';

using require

const lzjs = require('lzjs');

browser (standalone)

You can install the library via npm or download it from the release list. Use the lzjs.js or lzjs.min.js files included in the package.
*Please note that if you use git clone, even the master branch may be under development.

<script src="lzjs.js"></script>

or the minified lzjs.min.js:

<script src="lzjs.min.js"></script>

When the script is loaded, the lzjs object is defined in the global scope (i.e., window.lzjs).

Demo

API


lzjs.compress(data, [options])

Compresses data into a binary string.

Arguments

  • data (string|Buffer) : Input data
  • [options] (object) : Compression options
    • onData (function (data) {}) : Called when a data is chunked
    • onEnd (function () {}) : Called when process ends

Returns

(string) : Compressed data

Example

Example of compressing and decompressing a string.

const data = 'hello hello hello';
const compressed = lzjs.compress(data);
console.log(compressed); // 'Whello \x80\x82\x84\x86\x83'

const decompressed = lzjs.decompress(compressed);
console.log(decompressed === data); // true

Compress data using onData and onEnd events.

const string = 'hello hello hello';
const compressed = [];

lzjs.compress(string, {
  onData: (data) => {
    compressed.push(data);
  },
  onEnd: () => {
    console.log(compressed.join('')); // 'Whello \x80\x82\x84\x86\x83'
  }
});

lzjs.decompress(data, [options])

Decompresses a string that has been compressed with lzjs.compress()

Arguments

  • data (string) : Input data
  • [options] (object) : Decompression options
    • onData (function (data) {}) : Called when a data is chunked
    • onEnd (function () {}) : Called when process ends

Returns

(string) : Decompressed data

Example

Example of decompressing a string that has been compressed with lzjs.compress().

const decompressed = lzjs.decompress('Wabc\x80\x82\x81\x83\x83');
console.log(decompressed); // 'abcabcabcabcabc'

Decompress data using onData and onEnd events.

const compressed = 'Whello \x80\x82\x84\x86\x83';
const decompressed = [];

lzjs.decompress(compressed, {
  onData: (data) => {
    decompressed.push(data);
  },
  onEnd: () => {
    console.log(decompressed.join('')); // 'hello hello hello'
  }
});

lzjs.compressToBase64(data)

Compresses and encodes data into a Base64 string.

Arguments

  • data (string|Buffer) : Input data

Returns

(string) : Compressed and Base64 encoded string

Example

const data = 'hello hello hello';
const compressed = lzjs.compressToBase64(data);
console.log(compressed); // 'V2hlbGxvIMKAwoLChMKGwoM='

lzjs.decompressFromBase64(data)

Decompresses a string that has been compressed with lzjs.compressToBase64().

Arguments

  • data (string) : Input data

Returns

(string) : Decompressed data

Example

const decompressed = lzjs.decompressFromBase64('V2FiY8KAwoLCgcKDwoM=');
console.log(decompressed); // 'abcabcabcabcabc'

Command line usage

After npm install -g lzjs

Add file to archive

lzjs -a something.txt

Extract file

lzjs -x something.txt.lzjs

All command line options

  -h, --help                 show Help
  -v, --version              show Version
  -a, --add <file_name>      Add file to archive
  -x, --extract <file_name>  eXtract file

Note that command line compression is only valid for the UTF-8 encoded file.

Contributing

We welcome contributions from everyone. For bug reports and feature requests, please create an issue on GitHub.

Pull Requests

Before submitting a pull request, please run $ npm run test to ensure there are no errors. We only accept pull requests that pass all tests.

License

This project is licensed under the terms of the MIT license. See the LICENSE file for details.