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 🙏

© 2025 – Pkg Stats / Ryan Hefner

async-lz-string

v1.1.0

Published

LZ-based compression algorithm

Readme

async-lz-string

This is a JavaScript library which compresses and decompresses strings. It implements the same algorithm as the lz-string library but unlike that library this one is async and leaves time for other tasks to run while compressing/decompressing.

About

The reason for complicating the original lz-string library with async is that on slow devices it can take several seconds to compress long strings. If this wasn't done async the page would not be responsive to click events or anything during this time. So if compressing longer strings without causing the page to freeze is desired, async is the best option. If freezing the page is not a problem, the original lz-string will likely have better performance and be simpler to use since it does not require using promises.

The asynchronicity is implemented by awaiting a timeout of 0 after a certain number of iterations. This will let the browser run event handlers before the next iteration. The number of iterations between waits is tuned to be a number which doesn't affect the time taken to compress too much while still being frequent enough to not cause significant delay in processing events.

Use cases

Simply put: This project makes strings smaller. Why is that useful?

The first thing that comes to mind is localStorage. localStorage has limited space on many platforms, so if you for some reason need to store big strings in there this library can help you keep your strings small.

Note that the compression can be combined with JSON.stringify to compress any object that can be serialized to JSON.

The second thing that comes to mind is transfering things to the server. People on slow internet or with tight bandwidth caps will probably be happier if you transfer smaller amounts of data. Servers often GZip their responses but requests are usually not compressed in any way. If your requests are large enough it may be worth compressing them first, though it's not recommended that you always do it since it will make your code messier.

For a list of server side libraries implementing the same algorithm, see this page.

Usage

Add async-lz-string to your package.json and install it.

There are four functions exported as a UMD module: compressToUTF16, decompressFromUTF16, compressToBase64, and decompressFromBase64. They do exactly what you expect them to do.

Example usage in TypeScript:

import { compressToUTF16, decompressFromUTF16 } from "async-lz-string";

async function compressAndDecompress(str: string) {
  const compressed = await compressToUTF16(str);
  const decompressed = await decompressFromUTF16(compressed);
  console.log(str === decompressed); // true
}

Development

If you want to change something in async-lz-string you are welcome to send a pull request.

To get started, run the following in your terminal:

git clone https://github.com/jackbister/async-lz-string.git
cd async-lz-string
npm install
npm run watch

You will now have the project and all its dependencies checked out, and webpack will be running in watch mode so your changes will be reflected immediately.

There are currently two ways you can test your changes:

  • Running the test suite
    • There is a small test suite that ensures that the compressor and decompressor are compatible with the lz-string package.
    • To run this test suite once you can run npm run test
    • To run it in watch mode you can use npm run start-test
  • Using npm link
    • If you have another project that uses async-lz-string you can use npm link to use your local copy of async-lz-string.
    • Run npm link in the async-lz-string directory
    • Run npm link async-lz-string in the other project's directory.
    • When you're done, run npm unlink async-lz-string in the other project's directory and npm unlink in the async-lz-string directory.