npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ng-vscode-html-data-parser

v1.0.0-alpha.15

Published

This small library can read your Angular application source directory for components and directives and generate custom HTML data for VS Code to consume.

Downloads

7

Readme

Angular Custom HTML Data Parser for Visual Studio Code

Build NPM License

VS Code has the capability to load custom web component information into the HTML language services. These language services provide the IntelliSense we use everyday for code completion and functionality discovery. Imagine creating a set of directives and components within an Angular application and seeing those components within VS Code's own code hints.

Well now you can do just that.

This small library can read your Angular application source directory for components and directives and generate custom HTML data for VS Code to consume.

Add it to your build pipelines to keep your data up-to-date. Build extensions for your teams to use and provide built-in documentation around your organization's component system. Include it with your npm packages to enable your end users to keep coding without having to go back to the external documentation.

Disclaimer

This is still a work in progress and new features will be added as necessary. Feel free to use this project however you'd like, just please be sure to give acknowledgement where applicable.

Usage

Generating custom HTML data for VS Code is as simple as:

npx ng-vscode-html-data-parser

The default behavior will look for any *.ts within your package directory and attempt to generate custom HTML data from any components or directives found.

Command Line Options

This library also supports some flags to help provide all of the functionality you need:

[--d, --destination] {outputLocation}

This option will set the output location and filename for the custom HTML data file that's generated by this library. It's suggested that this file name end with ".html-data-.json". VS Code understands this file and will apply the proper JSON schema to it automatically when editing.

By default, this is a file named "custom.html-data.json" in the package directory.

Example

This will write the custom HTML data file to the package directory with the name "my-custom.html-data.json":

npx ng-vscode-html-data-parser --dest my-custom.html-data.json

[--f, --files] {filePattern}

This option will tell the library where to find the Angular component files. This should be in the glob pattern format.

By default, this is all TypeScript files, excluding test files, found from the root package directory (e.g.: **/!(*.spec).ts);

Example

This will chose all TypeScript files found in the "src" directory:

npx ng-vscode-html-data-parser --files src/**/*!(*.spec).ts

Config files

This library supports a separate config file called .ng-html-data.json, which can be used to provide the same functionality available in the command line options. Simply create the json file and fill it with the configuration values necessary:

Example

{
  "destination": "my-custom-html-data.json",
  "files": "src/**/*.ts"
}

The library also supports the usage of a JavaScript module, in a file called .ng-html-data.js, to populate the configuration and provide custom formatters.

Example

module.exports = () => ({
  /**
   * This formatter function is used when the description for an attribute is being compiled.
   * @param jsDoc This is the jsDoc object associated with the input/output property or directive class.
   * @param input This is a boolean that indicates weather or not the attribute has the {@Input} designation.
   * @param output This is a boolean that indicates weather or not the attribute has the {@Output} designation.
   * @returns A string representing the attribute's description.
   */ 
  attributeFormatter: function(jsDoc, input, output) {
    return jsDoc.comment 
      + (input ? '\n\n_@Input_' : '') 
      + (output ? '\n\n_@Output_' : '');
  },
  /**
   * This formatter function is used when the description for a component or element directive is being compiled.
   * @param jsDoc This is the jsDoc object associated with the input/output property or directive class.
   * @returns A string representing the tag's description.
   */
  tagFormatter: function(jsDoc) {
    return jsDoc.comment;
  },  
  destination: 'custom.html-data.json',
  files: '**/!(*.spec).ts'
});

For an example of an attribute formatter, see:

https://github.com/wthomas3/ng-vscode-html-data-parser/blob/main/src/formatters/simple-attribute-description-formatter.ts

The configurations can all be used at the same time, with the order of importance, from lowest to highest being:

  • JSON config file
  • JavaScript config module
  • Command line parameters

Setting up VS Code for Custom HTML Data

Setting up VS Code to use the output files from this library is very easy. Simply open up your folder or workspace settings and add this file to the html.customData setting. You may need to reload VS Code for your changes to take place.

More information on how to set this up can be found here: Custom Data for HTML Language Service

TODO

  • Support for components found in type declaration files in precompiled libraries.
  • Support enum types.

References