angular-docgen
TypeScript icon, indicating that this package has built-in type declarations

1.3.2 • Public • Published

Angular Docgen

This is a low level library for parsing Angular components into JSON, inspired heavily by react-docgen. The intended use case is for documenting design systems where you want full control over the visuals.

Use in conjunction with angular-docgen-loader to load the component definitions into your angular project.

Sample input

import { Component, Input } from "@angular/core";
 
/**
 * A nice button component
 */
@Component({
  selector: "my-button",
  templateUrl: "template.html",
  styleUrls: ["styles1.css", "styles2.css"]
})
export class Button {
  /**
   * Is button disabled
   */
  @Input() disabled: boolean = false;
 
  /**
   * Button variant
   */
  @Input() variant: "primary" | "secondary" = "primary";
 
  /**
   * onClick output
   */
  @Output() onClick = new EventEmitter<boolean>();
}

Sample output

{
  "component": {
    "name": "Button",
    "description": "A nice button component",
    "templateUrl": "template.html",
    "selector": "my-button",
    "styleUrls": [
      "styles1.css",
      "styles2.css",
    ],
  },
  "inputs": [{
    "description": "Is button disabled",
    "name": "disabled",
    "type": "boolean",
    "value": false
  }, {
    "description": "Button variant",
    "name": "type",
    "variant": "string",
    "options": ["primary", "secondary"],
    "value": "primary"
  }],
  "outputs": [{
    "description": "onClick output",
    "name": "onClick",
    "value": "new EventEmitter<boolean>()",
  }]
}

It works by using the typescript parser to parse an Angular component file into an Abstract Syntax Tree (AST).

If you fancy a go at working with this I recommend using the wonderful astexplorer.net. Paste the sample component in, use the Typescript loader and then you can see the AST that you need to navigate.

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
1.3.24latest

Version History

VersionDownloads (Last 7 Days)Published
1.3.24
1.3.1242
1.3.00
1.2.00
1.1.00
1.0.10
1.0.0-alpha.30
1.0.0-alpha.20
1.0.0-alpha.10
1.0.0-alpha.00

Package Sidebar

Install

npm i angular-docgen

Weekly Downloads

246

Version

1.3.2

License

ISC

Unpacked Size

36.6 kB

Total Files

25

Last publish

Collaborators

  • thatguynamedandy