Get started with lzutf8 CDN
MIT licensed
Lzutf8: Lightweight JS library for lossless text compression/decompression .
Tags:- compression
- string compression
- text compression
- lz77
- utf8
- utf-8
Stable version
Copied!
How to start using lzutf8 CDN
// Include the library from the CDN
const lzutf8 = async () => {
const script = document.createElement('script');
script.src = 'https://cdn.cdnhub.io/lzutf8/0.6.3/lzutf8.min.js';
await new Promise((resolve) => script.onload = resolve);
document.head.appendChild(script);
};
lzutf8();
// Compression function
const compressText = (text) => {
const lzutf8Compressor = LZUTF8.compressToUTF8Array(text);
return btoa(String.fromCharCode.apply(null, lzutf8Compressor));
};
// Decompression function
const decompressText = (base64Text) => {
const lzutf8Array = Uint8Array.from(atob(base64Text), (c) => c.charCodeAt(0));
return new TextDecoder().decode(LZUTF8.decompress(lzutf8Array));
};
// Usage
const originalText = 'This is some text to compress and decompress using LZUTF8.';
const compressedText = compressText(originalText);
console.log('Compressed Text:', compressedText);
const decompressedText = decompressText(compressedText);
console.log('Decompressed Text:', decompressedText);
Copied!
Copied!
Copied!