DeTeam / dts-dom

A DOM library for generation TypeScript declaration (.d.ts) files

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

npm version

dts-dom is a library for programatically generating TypeScript declaration files. It is based mostly on the same CodeDOM provided for C# and other .NET languages.

dts-dom automatically handles indentation, formatting, and proper placement of declare and export keywords.

As with other CodeDOM libraries, this is overkill for small projects, but is useful in more complex code generation scenarios.

PRs gladly accepted as this is mostly implemented on an as-needed basis for another project.

Usage

npm install --save dts-dom

import * as dom from 'dts-dom';

const intf = dom.create.interface('MyInterface');
intf.jsDocComment = 'This is my nice interface';
intf.members.push(dom.create.method(
    'getThing',
    [dom.create.parameter('x', dom.type.number)],
    dom.type.void,
    dom.DeclarationFlags.Optional));

const ns = dom.create.namespace('SomeNamespace');
ns.members.push(intf);

console.log(dom.emit(ns));

This writes out the block:

declare namespace SomeNamespace {
    /**
     * This is my nice interface
     */
    interface MyInterface {
        getThing?(x: number): void;
    }
}

Contributors

The following people have contributed features and/or bug requests. Thank you!

About

A DOM library for generation TypeScript declaration (.d.ts) files

License:Apache License 2.0


Languages

Language:TypeScript 99.2%Language:JavaScript 0.8%