npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@rust-js/webapi

v0.0.2

Published

The web platform for rust-js programs: DOM bindings generated from WebIDL

Readme

webapi: the browser for rust-js

The webapi crate declares the web platform for rust-js programs: DOM bindings generated from W3C's WebIDL, the same source TypeScript's lib.dom.d.ts and Rust's web-sys come from. It holds declarations only, so it's never compiled to JS: a program calls what it declares, and the calls become plain JS. See ADR 0024.

use webapi::{document, element, event_target, node};

let b = document::create_element(document, "button");   // document.createElement("button")
node::set_text_content(b, "+");                          // b.textContent = "+"
event_target::add_event_listener(b, "click", Box::new(move |_| { .. }));
element::append(app, b);                                  // app.append(b)
  • Each interface is a type (Element, HtmlInputElement) and a module of its members (element, html_input_element).
  • Attributes are a getter and, if writable, a setter: html_input_element::value(i), html_input_element::set_value(i, "x").
  • Inheritance is Deref: an &HtmlButtonElement goes wherever an &Element or &Node is expected.
  • unchecked_from is a cast: html_input_element::unchecked_from(document::create_element(document, "input")).
  • A result that may be null is an Option: document::get_element_by_id(document, "app").expect("the page has an #app").
  • A promise is a Promise<T>, the js crate's, to .await: window::fetch(window, url).await (ADR 0029). js::settle(p).await is a Result.
  • Binary data is JS's ArrayBuffer and Uint8Array, the js crate's: response::bytes(r).await.
  • Names follow ReScript's webapi (ADR 0102): the common form keeps the plain name, window::fetch(window, url), and the others say what's different, fetch_with_request. An optional argument adds a form: window::fetch_with_init(window, url, init), text_encoder::encode_with_input(e, "hi").
  • An options object is a struct of Option fields, the rest ..Default::default(): RequestInit { method: Some("POST"), body: Some(&json), ..Default::default() }.
  • A constructor is new, event::new("ping"), or one per source, request::from_url(url).
  • A namespace is a module: web_assembly::compile(bytes).await is await WebAssembly.compile(bytes). An object parameter takes any Rust value as &dyn Any, such as a struct for an import object.

Use it

bun run build                                                    # its metadata, for the host
./target/debug/rust-js app.rs -- --extern webapi=target/libwebapi.rmeta --extern js=target/libjs.rmeta -L target

The playground compiles every program with the webapi crate available.

Regenerate it

bun run generate

generate.ts holds every rule: which specs and interfaces, how WebIDL types map to Rust, and the names. A member is generated only if rust-js supports all its types; the run prints what it skipped, and why. To update the platform, bump @webref/idl in package.json and regenerate. The diff of src/lib.rs is what changed.