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';
const compressed = compress('The brown fox (๐ฆ) jumps over the lazy dog (๐ถ).');
if (compressed.success === false) {
throw new Error(`Compression failed: ${compressed.error}`);
}
const decompressed = decompress(compressed.result);
console.log(decompressed.result);
const compressedObj = compressObj({ name: 'John Doe', age: 30, city: 'New York' });
if (compressedObj.success === false) {
throw new Error(`Compression object failed: ${compressedObj.error}`);
}
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!