JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 131
  • Score
    100M100P100Q73776F
  • License MIT

๐Ÿ”ฌ Reliable, Cross-Platform Compression & Decompression for Web, Node.js, Deno, and Bun

Package Exports

  • compress-kit

Readme

banner

compress-kit

Reliable, Cross-Platform Compression & Decompression
for Web, Node.js, Deno, and Bun

License npm version npm downloads stars

About ๐Ÿ“–

compress-kit is a modern compression toolkit for Web, Node.js, Deno, and Bun.
It offers a simple, consistent API for compressing and decompressing strings or objects, automatically deciding when compression is beneficial, while ensuring lossless results and type safety.

Features ๐ŸŒŸ

  • ๐Ÿ“‰ Strong Compression โ€“ Achieves size reductions of ~30% to 90% on typical text and JSON data using the Deflate algorithm via pako.
  • ๐Ÿง  Smart Compression โ€“ Automatically detects whether to store data compressed or uncompressed for optimal efficiency.
  • ๐ŸŒ Cross-Platform โ€“ Works seamlessly in Web, Node.js, Deno, and Bun with no code changes.
  • ๐Ÿ” Lossless Algorithms โ€“ Ensures perfect reconstruction of the original data.
  • ๐Ÿงช Strict Validation & Result<T> Typing โ€“ Unified return type and robust input checks for predictable results.

Installation ๐Ÿ”ฅ

npm install compress-kit@latest

๐Ÿ’ก Works with npm, pnpm, yarn, bun, and deno. You can use it in dev dependencies since it's typically used only for local HTTPS.

Usage ๐Ÿช›

import { compress, compressObj, decompress, decompressObj } from 'compress-kit';

// Compressing data
const compressed = compress('The brown fox (๐ŸฆŠ) jumps over the lazy dog (๐Ÿถ).');
if (compressed.success === false) {
  throw new Error(`Compression failed: ${compressed.error}`);
}

// Decompressing data
const decompressed = decompress(compressed.result);
console.log(decompressed.result);

// Compressing an object
const compressedObj = compressObj({ name: 'John Doe', age: 30, city: 'New York' });
if (compressedObj.success === false) {
  throw new Error(`Compression object failed: ${compressedObj.error}`);
}

// Decompressing an object
const decompressedObj = decompressObj(compressedObj.result);
console.log(decompressedObj.result);

NOTE: The compressed data follow the following format: <base64url>.<0 or 1>.. The first part is the base64url encoded compressed data, and the second part indicates whether the data is compressed (1) or not (0). The package hands the regex

Credit ๐Ÿ’ช๐Ÿฝ

We want to thank Pako for the inflate and deflate algorithms used in this package.

Contributions ๐Ÿค

Want to contribute or suggest a feature?

  • Open an issue or feature request
  • Submit a PR to improve the packages or add new ones
  • Star โญ the repo if you like what you see

License ๐Ÿ“œ

This project is licensed under the MIT License.

Thank you!