2 unstable releases

0.2.0 Jul 27, 2019
0.1.0 Jul 27, 2019

#709 in WebAssembly

21 downloads per month

MIT license

67KB
204 lines

blurhash-wasm

A Rust implementation of the blurhash algorithm.

It is compiled to WebAssembly (WASM), and available on npm as blurhash-wasm.

Usage in JS

Installation

You will need a package manager, either npm (comes with node) or yarn.

You will also need a bundler, webpack or Rollup, configured for your project.

Then, in a terminal:

npm install blurhash-wasm
# Or, yarn add blurhash-wasm

The demo app source has a complete example of using blurhash-wasm.

decode

import * as blurhash from "blurhash-wasm";

// Returned as Uint8Array | undefined
// You can use this to construct canvas-compatible resources
const pixels = blurhash.decode("LKO2?U%2Tw=w]~RBVZRi};RPxuwH", 40, 30);

encode

Not yet implemented :)

Usage in Rust

Installation

You will need Rust and Cargo.

Add the version you want to Cargo.toml:

[dependencies]
blurhash-wasm = "0.1.0"

decode

use blurhash_wasm;

// Result<Vec<u8>, blurhash::Error>
let res = blurhash::decode("LKO2?U%2Tw=w]~RBVZRi};RPxuwH", 40, 30);

encode

Not yet implemented :)

About the setup

Based on the rust wasm-pack template

This template is designed for compiling Rust libraries into WebAssembly and publishing the resulting package to NPM.

Be sure to check out other wasm-pack tutorials online for other templates and usages of wasm-pack.

🚴 Usage

🛠️ Build with wasm-pack build

wasm-pack build

🔬 Test in Headless Browsers with wasm-pack test

wasm-pack test --headless --firefox

🎁 Publish to NPM with wasm-pack publish

wasm-pack publish

🔋 Batteries Included

Dependencies

~1.2–2MB
~29K SLoC