lz-string
Fast, dependency-free LZ-based string compression for JavaScript and TypeScript
Repository Health
Technical Analysis
lz-string is a lightweight JavaScript/TypeScript implementation of an LZ-based compression algorithm purpose-built for compressing strings, not files. Version 2 ships as a joint CommonJS/ESM package with a bundled CLI, and offers multiple output encodings (base64, UTF-16, URI-component-safe, raw, Uint8Array) so compressed data can be safely stored wherever plain strings are expected.
It is one of the most widely used compression utilities in the JS ecosystem for shrinking data before writing to localStorage, embedding in URLs, or shipping over constrained network payloads, and has been ported to numerous other languages for cross-platform compatibility.
What You Get
- Core
compress()/decompress()functions for raw string compression - Encoding-specific helpers: base64, UTF-16, URI-component-safe, and Uint8Array output formats
- A CLI (
lz-stringbinary) for compressing/decompressing files from the command line - Dual CommonJS/ESM build output with TypeScript type definitions
- Zero runtime dependencies, keeping bundle size minimal for browser use
Common Use Cases
- Compressing large JSON or state blobs before storing them in browser localStorage/sessionStorage
- Shrinking data to fit within URL length limits by compressing to a URI-component-safe encoding
- Reducing payload size for data embedded in query strings or QR codes
- Cross-language data interchange using one of the library’s many community ports (Java, Python, Go, etc.)
Under The Hood
Architecture The library centers on a shared LZ78-style compression core split across _compress.ts and _decompress.ts, with index.ts acting as a thin dispatcher that wires the core engine to encoding-specific wrappers (base64, UTF-16, URI-component, raw, Uint8Array) found in their own subdirectories; a separate cli.ts built on commander exposes the same engine as a standalone binary for file-based compression, and node.ts provides Node-specific entry adjustments. Tech Stack Written in TypeScript, built with Vite (vite.config.mts for the library, a second config for the CLI) producing dual CJS/ESM output plus .d.ts type declarations via vite-plugin-dts; the package has zero runtime dependencies, keeping the compiled bundle minimal for browser consumption. Code Quality Tests live under src/__tests__ with accompanying __snapshots__, run via Vitest with coverage and benchmark modes (test:bench, test:coverage) configured in package.json; the recent v2 rewrite (joint CJS/ESM layout) suggests active modernization even though day-to-day commit activity is currently low. API Design The API is deliberately minimal — a handful of compress*/decompress* function pairs named after their target encoding — which makes the library trivial to adopt with almost no boilerplate, though the multiple encoding variants (base64 vs UTF-16 vs raw) require the caller to understand which encoding matches their storage target to avoid corruption.
Used by 8 apps in this directory
AFFiNE
Productivity · Project Management · Note Taking
Write, draw, and plan in one infinite canvas — the open-source alternative to Notion and Miro that keeps your data yours.
agenta
Developer Tools · Devops · AI Development
The open-source LLMOps platform unifying prompt engineering, evaluation, and observability for teams building reliable LLM applications.
GraphQL Hive
Developer Tools · Devops · Monitoring
Open-source GraphQL schema registry and observability platform with breaking change detection, federation support, and CI/CD integration for teams of any size.
Kibana
Analytics · Monitoring
Your open source window into the Elastic Stack — query, visualize, and act on data stored in Elasticsearch with real-time dashboards, AI-assisted search, and automated alerting.
marimo
Developer Tools · Data Engineering
A reactive Python notebook that eliminates hidden state, runs reproducibly, and deploys as a web app or script — stored as pure Python, built for the AI era.
OpenPanel
Hosting Control Panel · Devops
Docker-powered web hosting control panel that gives every user a fully isolated environment with dedicated web server, database, and networking — VPS-grade security on shared hardware.
Openship
Devops · Hosting Control Panel
Openship is an open-source, self-hostable deployment platform that points at a repo and builds, ships, routes, and TLS-terminates the app — driven from a desktop app, web dashboard, or CLI.
RSSHub
Automation · Social Media
Turn any website into an RSS feed — social media, streaming platforms, and niche sites all become subscribable in seconds.