@ts2doc/json
TypeScript icon, indicating that this package has built-in type declarations

0.3.0 • Public • Published

@ts2doc/json

Parse exported declarations from typescript files into json object, for documentation.

Installation

As dependency:

npm install @ts2doc/json

As devDependency:

npm install @ts2doc/json --save-dev

Usage

const { ts2doc } = require('@ts2doc/json');

const doc = ts2doc(['path/to/file.ts']);

API

ts2doc(filesPath: string[], options?: ts.CompilerOptions): Declaration[]

options is optional, and will be passed to typescript compiler. See typescript docs for more details.

Examples

// Movie.ts

/**
 * Interface description
 */
export interface Movie {
    /**
     * Property description
     */
    title: string;
    year: number;
    actors: string[];
}

Will be parsed into:

{
    Movie: {
        name: 'Movie',
        kind: 'interface',
        description: 'Interface description',
        props: [
            {
                name: 'title',
                kind: 'prop',
                type: 'string',
                description: 'Property description'
            },
            {
                name: 'year',
                kind: 'prop',
                type: 'number',
                description: ''
            },
            {
                name: 'actors',
                kind: 'prop',
                type: 'string[]',
                description: ''
            }
        ]
    }
};

More examples can be found in examples.

Supported declarations

Declaration Supported
variable
interface
function
type
enum
class
namespace

License

Distributed under the MIT License. See LICENSE file for more information.

Package Sidebar

Install

npm i @ts2doc/json

Weekly Downloads

102

Version

0.3.0

License

MIT

Unpacked Size

13.9 kB

Total Files

11

Last publish

Collaborators

  • jpiazzal