GithubHelp home page GithubHelp logo

mkwtys / webidl-tools Goto Github PK

View Code? Open in Web Editor NEW

This project forked from markandrus/webidl-tools

0.0 2.0 0.0 42 KB

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

JavaScript 100.00%

webidl-tools's Introduction

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)

webidl-tools's People

Contributors

markandrus avatar

Watchers

mkwtys avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.