wasm-nanoid
TypeScript icon, indicating that this package has built-in type declarations

0.1.0 • Public • Published

wasm-nanoid

Tutorial for your first wasm package.

docker run -v "$PWD":/usr/src/myapp -w /usr/src/myapp --rm --interactive --tty stereobooster/rust-wasm
USER=stereobooster cargo generate --git https://github.com/rustwasm/wasm-pack-template
cd wasm-nanoid

Use your github handle instead of mine (USER=stereobooster).

Edit Cargo.toml:

description = "nanoid implemented in wasm"
repository = "https://github.com/stereobooster/wasm-nanoid"
license = "MIT"

Edit README.md. Run:

wasm-pack init

Add to .gitignore:

*.log
pkg/*

Commit (you may want to do this in different terminal, because git inside Docker is not configured).

git add .
git commit -m "initial commit"

I want to build simple thing, so I will reuse existing Nano ID package (they call it crate in Rust).

Add dependency to Cargo.toml (this is like a package.json for npm):

nanoid = "0.2.0"

Edit src/lib.rs:

extern crate nanoid;
 
use wasm_bindgen::prelude::*;
 
#[wasm_bindgen]
pub fn simpleNanoid() -> JsValue {
    JsValue::from_str(&nanoid::simple())
}

/wasm-nanoid/

    Package Sidebar

    Install

    npm i wasm-nanoid

    Weekly Downloads

    1

    Version

    0.1.0

    License

    MIT

    Unpacked Size

    53.2 kB

    Total Files

    5

    Last publish

    Collaborators

    • stereobooster