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 🙏

© 2024 – Pkg Stats / Ryan Hefner

webidl-tools

v0.1.1

Published

WebIDL Tools

Downloads

8

Readme

webidl-tools

NPM Build Status

Note: This project is a work-in-progress and exists primarily to enable some pet projects. As such, it is tuned to those use cases. If you need additional functionality, bug fixes, etc., please open a pull request.

webidl-tools provides a suite of commands for extracting and transforming WebIDL.

  • Extract WebIDL definitions from HTML documents (for example, W3C specifications).
  • Generate Flow type declarations from WebIDL definitions.
  • Generate JavaScript code from WebIDL definitions.

Install

npm install -g webidl-tools

Example

Set your .flowconfig to

[include]
validators.js

[libs]
decls

Then run

webidl-tools extract \
  https://w3c.github.io/webrtc-pc/archives/20160215/webrtc.html \
  --rename 'AlgorithmIdentifier|MediaStream|WorkerGlobalScope/Object'
webidl-tools flow
webidl-tools js
flow check

The file validators.js will contain typechecked validators for enums and dictionaries defined in the WebIDL. For example,

$ node
> var validators = require('./validators');
undefined
> validators.validateRTCIceRole('controlling')
"controlling"
> validators.validateRTCIceRole('foo')
TypeError: Invalid RTCIceRole "foo"

Usage

$ webidl-tools --help

  Usage: webidl-tools <sub-command> [options]

  webidl-tools provides a suite of commands for extracting and transforming
  WebIDL.

  Commands:

    extract                Extract WebIDL definitions from HTML documents (for
                           example, W3C specifications). This command also
                           accepts URLs.
    flow                   Generate Flow type declarations from WebIDL
                           definitions. If multiple WebIDL definitions with the
                           same name are provided, they will be merged. This
                           command also accepts URLs.
    js                     Generate JavaScript code from WebIDL definitions.
                           The generated code can be used to validate WebIDL
                           enums and dictionaries. If multiple WebIDL
                           definitions with the same name are provided, they
                           will be merged. This command also accepts URLs.
    help <sub-command>     Show the --help for a specific command

extract

$ webidl-tools extract --help

  Usage: webidl-tools-extract [options] <html ...>

  Extract WebIDL definitions from HTML documents (for example, W3C
  specifications). This command also accepts URLs.

  Options:

    -h, --help             output usage information
    -V, --version          output the version number
    --rename <s/foo/bar/>  Rename WebIDL interface, argument, etc., names
                           (can be specified multiple times; applied after
                           --skip)
    --only </foo/>         Only process WebIDL definitions with the given
                           name (can be specified multiple times)
    --skip </foo/>         Skip WebIDL definitions with the given name (can
                           be specified multiple times; applied after --only)
    -b, --bail             Exit on WebIDL parse failure
    --merge                Merge WebIDL definitions by unioning interface and
                           dictionary members
    --no-merge             Don't merge WebIDL definitions; if a merge is
                           required and this option is specified, the process
                           exits
    -o, --out <dir>        Directory to write the WebIDL to (defaults to ./idl)

flow

$ webidl-tools flow --help

  Usage: webidl-tools-flow [options] <idl ...>

  Generate Flow type declarations from WebIDL definitions. If multiple WebIDL
  definitions with the same name are provided, they will be merged. This
  command also accepts URLs.

  Options:

    -h, --help             output usage information
    -V, --version          output the version number
    --rename <s/foo/bar/>  Rename WebIDL interface, argument, etc., names
                           (can be specified multiple times; applied after
                           --skip)
    --only </foo/>         Only process WebIDL definitions with the given
                           name (can be specified multiple times)
    --skip </foo/>         Skip WebIDL definitions with the given name (can
                           be specified multiple times; applied after --only)
    -b, --bail             Exit on WebIDL parse failure
    --merge                Merge WebIDL definitions by unioning interface and
                           dictionary members (default)
    --no-merge             Don't merge WebIDL definitions; if a merge is
                           required and this option is specified, the process
                           exits
    -o, --out <dir>        Directory to write Flow type declarations to
                           (defualts to ./decls)

js

$ webidl-tools js --help

  Usage: webidl-tools-js [options] <idl ...>

  Generate JavaScript code from WebIDL definitions. The generated code can be
  used to validate WebIDL enums and dictionaries. If multiple WebIDL
  definitions with the same name are provided, they will be merged. This
  command also accepts URLs.

  Options:

    -h, --help                   output usage information
    -V, --version                output the version number
    --rename <s/foo/bar/>        Rename WebIDL interface, argument, etc.,
                                 names (can be specified multiple times;
                                 applied after --skip)
    --only </foo/>               Only process WebIDL definitions with the
                                 given name (can be specified multiple times)
    --skip </foo/>               Skip WebIDL definitions with the given name
                                 (can be specified multiple times; applied
                                 after --only)
    -b, --bail                   Exit on WebIDL parse failure
    --merge                      Merge WebIDL definitions by unioning
                                 interface and dictionary members (default)
    --no-merge                   Don't merge WebIDL definitions; if a merge
                                 is required and this option is specified,
                                 the process exits
    --flow-types-in-comments     Include Flow types in comments (default)
    --no-flow-types-in-comments  Do not include Flow types in comments
    --jsdoc                      Include JSDoc comments (default)
    --no-jsdoc                   Do not include JSDoc comments
    -o, --out <file>             File to write JavaScript code to (defaults
                                 to ./validators.js)