@danmarshall/ts-extractor
TypeScript icon, indicating that this package has built-in type declarations

4.0.1-rc.4 • Public • Published

ts-extractor

NPM version Build Status Coverage Status dependencies Status devDependencies Status devDependencies Status

TypeScript AST extractor to a useful JSON structure.

The purpose of this package is to extract AST into a flat JSON structure.

After extraction, it can be used for documentation generation tool, easier code analysis without compiler, etc.

Relation to API Extractor

The library is inspired by API Extractor created by Microsoft.

ts-extractor does everything api-extractor was supposed to do and supports ALL things that latest TypeScript has, compared to a limited support in api-extractor.

In essence, it is an evolution of what api-extractor does, though outputs are not interchangable directly.

Usage example

import * as path from "path";
import * as process from "process";
import { Extractor, GetCompilerOptions } from "ts-extractor";

async function Main(): Promise<void> {
    // Absolute path to projectDirectory
    const projectDirectory = process.cwd();
    const pathToTsconfig = path.join(projectDirectory, "./tsconfig.json");

    const compilerOptions = await GetCompilerOptions(pathToTsconfig);

    const extractor = new Extractor({
        CompilerOptions: compilerOptions,
        ProjectDirectory: projectDirectory
    });

    const extractedOutput = extractor.Extract(["./src/index.ts", "./src/another-entry-file.ts"]);
    console.log(extractedOutput);
}

Main();

Package Sidebar

Install

npm i @danmarshall/ts-extractor

Weekly Downloads

6

Version

4.0.1-rc.4

License

MIT

Unpacked Size

440 kB

Total Files

101

Last publish

Collaborators

  • danmarshall