106.2.7 ā€¢ Published 5 months ago

hello-world-rust-wasm-component-lib v106.2.7

Weekly downloads
-
License
-
Repository
github
Last release
5 months ago

JavaScript bindings for "Hello world!" Rust WebAssembly component library

šŸ”— 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

Installation

npm Yarn pnpm Deno Bun jsDelivr

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>

Usage

Node.js Deno Bun Browser

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

Development

Node.js JavaScript

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.