π JavaScript bindings for jcbhmr/hello-world-rust-wasm-component-lib
run();
//=> Hello Alan Turing!
console.log(getReport());
//=> {
// bouncyCastles: 100,
// funPercent: 0.9,
// catCount: 8,
// unicornNames: [ 'Fluffy', 'Marshmallow', 'Sparkles' ]
// }
console.log(computeArea({ center: { x: 0, y: 0 }, radius: 6 }));
//=> 113.09733552923255
console.log(greetMany(["Alan Turing", "Ada Lovelace"]));
//=> Hello, Alan Turing!
// Hello, Ada Lovelace! |
π·οΈ Using v1.0.0 of jcbhmr/hello-world-rust-wasm-component-lib
π¦ WASM is written in Rust
π¦ Includes TypeScript type definitions
π¦ Published as an npm package
π©ββοΈ 0BSD licensed template
You can install this package using your favorite npm package manager like npm, Yarn, pnpm, or Bun.
npm install hello-world-rust-wasm-component-lib
If you're using Deno you can import it straight from npm:
import {} from "npm:hello-world-rust-wasm-component-lib";
If you prefer to go buildless in the browser you can use an npm CDN like jsDelivr or esm.sh.
<script type="module">
import {} from "https://esm.run/hello-world-rust-wasm-component-lib";
</script>
You should be able to just import and use this JavaScript package like any other. The WASM magic is hidden behind a really nice wrapper layer.
import {
greetMany,
run,
getReport,
computeArea,
} from "hello-world-rust-wasm-component-lib";
run();
//=> Hello Alan Turing!
console.log(getReport());
//=> {
// bouncyCastles: 100,
// funPercent: 0.9,
// catCount: 8,
// unicornNames: [ 'Fluffy', 'Marshmallow', 'Sparkles' ]
// }
console.log(computeArea({ center: { x: 0, y: 0 }, radius: 6 }));
//=> 113.09733552923255
console.log(greetMany(["Alan Turing", "Ada Lovelace"]));
//=> Hello, Alan Turing!
// Hello, Ada Lovelace!
π Read more about the API surface on the documentation website
Versioning scheme: Use 1.2.3+4.5.6
where 1.2.3
is the main JS bindings
API version (this package) and 4.5.6
is the version of the upstream WASM
underlying library that was used to generate the JavaScript bindings. The
1.2.3+4.5.6
versioning scheme was adopted so that users of a particular
version can quickly see which version of the WASM library was used. Note that
the +4.5.6
part is just metadata. You can't publish both 1.2.3+4.5.6
and
1.2.3+7.8.9
. Think of it like a super important "description"
field.