smol-string
smol-string
is a compression library designed for use with browsers' localStorage
(and sessionStorage
). It serves as a faster alternative to lz-string
.
The library is composed of a core algorithm written in Zig compiled to WebAssembly, along with a wrapper provided as a TypeScript library.
Originally, I ensured that it produced valid UTF-16 strings to ensure browser compatibility. However, it now appears that this is not necessary for any of the tested browsers. The default behavior can now result in technically invalid UTF-16 strings.
Installation
npm install -S smol-string
Usage
import { compress, decompress } from "smol-string";
const input = "Any JS String";
const compressed = compress(input);
const decompressed = decompress(compressed);
An async version offloading the processing to a webworker is also available. API is identical, except that each function returns a promise:
import { compress, decompress } from "smol-string/worker";
const compressed = await compress(input);
const decompressed = await decompress(compressed);
Build
zig build # Builds the wasm modules to `zig-out/lib/` by default.
cd ts-lib
npm ci # Installs Dependencies.
npm run build # Builds the Typescript library to `ts-lib/dist`.