Senryoku / smol-string

Compression for browsers' localStorage. Alternative to lz-string written in Zig.

Home Page:https://senryoku.github.io/smol-string/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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`.

About

Compression for browsers' localStorage. Alternative to lz-string written in Zig.

https://senryoku.github.io/smol-string/

License:MIT License


Languages

Language:Zig 58.8%Language:TypeScript 24.0%Language:Vue 13.7%Language:CSS 2.1%Language:HTML 0.7%Language:JavaScript 0.7%