# @amoutonbrady/lz-string

> Modern TypeScript port of lz-string: LZ-based compression for JavaScript strings

Latest version **0.2.0** (published 2026-09-06) · MIT license · 0 weekly downloads

## Install

```sh
npm install @amoutonbrady/lz-string
pnpm add @amoutonbrady/lz-string
yarn add @amoutonbrady/lz-string
bun add @amoutonbrady/lz-string
```

## Health

**Score 65/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; recently updated; high quality score.

Warnings: low downloads; pre 1.0.

## Facts

| | |
|---|---|
| Version | 0.2.0 |
| Published | 2026-09-06 |
| First published | 2021-01-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=20 |
| Dependencies | 0 |
| Unpacked size | 19.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 10 |
| Author | Alexandre Mouton-Brady |
| Maintainers | amoutonbrady |
| Keywords | lz-string, lz, compression, compress, decompress, base64, utf16, uint8array, typescript |

## Links

- npm: https://www.npmjs.com/package/@amoutonbrady/lz-string
- Repository: https://github.com/amoutonbrady/lz-string
- Homepage: https://github.com/amoutonbrady/lz-string#readme
- Issues: https://github.com/amoutonbrady/lz-string/issues
- npm.io page: https://npm.io/package/@amoutonbrady/lz-string

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 0.2.0 (latest) — 2026-09-06
- 0.1.0 — 2023-03-10
- 0.0.1 — 2021-01-25

## README

# @amoutonbrady/lz-string

Modern TypeScript port of [lz-string](https://github.com/pieroxy/lz-string), the LZ-based
compression algorithm for JavaScript strings.

- Wire-compatible with lz-string 1.x: anything compressed by one decompresses with the other
  (verified against the reference implementation in the test suite).
- Same API, fully typed, ESM and CommonJS builds, zero dependencies, tree-shakeable.
- About half the source of the original: the bit reader/writer is shared instead of copy-pasted.

## Install

```bash
pnpm add @amoutonbrady/lz-string
```

## Usage

```ts
import { compressToURL, decompressFromURL } from '@amoutonbrady/lz-string';

const compressed = compressToURL('hello world'); // safe to put in a query string as-is
const original = decompressFromURL(compressed); // 'hello world'
```

## API

Every `compress*` function returns `''` for `null`/`undefined`. Every `decompress*` function
returns `''` for `null`/`undefined`, `null` for an empty or corrupt input.

| Compress                                          | Decompress                                                    | Output                                                        |
| ------------------------------------------------- | ------------------------------------------------------------- | ------------------------------------------------------------- |
| `compress(input: string): string`                 | `decompress(input: string): string \| null`                   | Raw UTF-16 code units, smallest but not safe to store as text |
| `compressToUTF16(input: string): string`          | `decompressFromUTF16(input: string): string \| null`          | Valid UTF-16, safe for `localStorage`                         |
| `compressToBase64(input: string): string`         | `decompressFromBase64(input: string): string \| null`         | Standard Base64                                               |
| `compressToURL(input: string): string`            | `decompressFromURL(input: string): string \| null`            | URL-safe alphabet (`+-$`), no padding, no encoding needed     |
| `compressToUint8Array(input: string): Uint8Array` | `decompressFromUint8Array(input: Uint8Array): string \| null` | Binary                                                        |

`compressToURL` was named `compressToEncodedURIComponent` in the original library.

## Development

```bash
pnpm install
pnpm test       # node:test, runs the TypeScript sources directly
pnpm typecheck
pnpm build      # tsdown: ESM + CJS + .d.ts, then publint + arethetypeswrong
```

Releases: bump the version, push a `v*` tag. The `release.yml` workflow builds, tests and
publishes to npm with provenance through npm trusted publishing (no token to manage).

## License

MIT

---
_Source: https://npm.io/package/@amoutonbrady/lz-string · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
