Git Product home page Git Product logo

-googlecolab-tswidgets's Introduction

TsWidgets: A tool to convert from TypeScript custom element class to UI Widget classes in other languages.

Takes a class like this:

export class HelloWorld extends HTMLElement {
  sayHi() {
    console.log('Hello, World');
  }
}

customElements.define('hello-world', HelloWorld)

And converts it to Python that looks like this:

"""HelloWorld Proxy."""

class HelloWorld(html.Element):
  def __init__(self):
    super(HelloWorld, self).__init__('hello-world')

  def say_hi(self):
    """sayHi method."""
    self._call('sayHi')

Notes:

  1. The TypeScript compiler will resolve imports automatically, so any imported classes will also be exported as Python.
  2. The HTMLElement name is derived from the class's name, such that capitalized letters are converted to hyphens, i.e. XFoo becomes x-foo. (Note that we ignore the first letter.) If a class has no capitalized letters beyond the first one, e.g. Foo, the derived name will be prepended with 'x-', i.e. 'x-foo'.

Running

The tool requires Node.js 6+.

  1. Clone the repo.
  2. Install the TypeScript Compiler: npm install -g typescript.
  3. Run npm install.
  4. Compile: tsc --target es6 tswidgets.ts.
  5. Run against the TypeScript code: node tswidgets.js /path/to/your/class.ts.
  6. Python files will be written to the current working directory for any TypeScript classes found.

-googlecolab-tswidgets's People

Contributors

doug avatar

Watchers

 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.