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 🙏

© 2025 – Pkg Stats / Ryan Hefner

ngx-html-bridge

v0.0.33

Published

An Angular Template Parser to convert Angular templates into an array of standard, static HTML strings.

Readme

ngx-html-bridge (WIP)

NPM Version Build Status License: MIT

ngx-html-bridge is a powerful parser that converts Angular templates into an array of standard, static HTML strings. This enables you to use any HTML validator of your choice on your Angular templates, bridging the gap between Angular's dynamic syntax and standard HTML validation tools.

Core Purpose

The primary goal of this project is to allow developers to validate the potential HTML output of their Angular templates. By parsing Angular-specific syntax and generating all possible static HTML variations, it provides a reliable input for linters and validators that only understand plain HTML.

How It Works

The tool operates in a multi-step process:

  1. Parses the Angular Template: It uses the @angular/compiler to parse the HTML template file into an Abstract Syntax Tree (AST).
  2. Parses the Component File: It looks for a corresponding .ts file for the template and uses @typescript-eslint/typescript-estree to parse it. This allows it to extract initial values from public and protected properties, which are used to resolve attribute bindings.
  3. Transforms the AST: It walks the AST and transforms Angular-specific syntax into a series of DOM node variations.
  4. Generates HTML: Finally, it uses jsdom to convert the DOM node variations into an array of pure, static HTML strings.

Supported Features

ngx-html-bridge supports a wide range of Angular template syntax:

  • Structural Directives:
    • *ngIf (with then and else clauses)
  • Built-in Control Flow:
    • @if, @else if, @else
    • @for (including the @empty block)
    • @switch, @case, @default
    • @defer (including @placeholder and @loading blocks)
  • Property and Attribute Binding:
    • Resolves [attribute] bindings based on property values from the component's TypeScript file.
    • Handles ternary operators in bindings to generate multiple output variations.

Limitations

It's important to understand the current limitations of the tool to use it effectively:

  • Placeholder Values: The library often uses placeholder values for dynamic content.
    • Text bindings (e.g., {{ myProperty }}) are replaced with a static placeholder string: "some random text".
    • Property bindings that cannot be resolved to a simple literal (e.g., complex function calls) will also fall back to a placeholder.
  • @for Loop Behavior: The parser does not render @for loops based on actual data. Instead, it generates a fixed set of variations to cover common scenarios:
    • One variation for the @empty case (if the block exists).
    • One variation for a single loop iteration.
    • One variation for two loop iterations (to test the plural case).

Installation

To get started with development, clone the repository and install the dependencies:

git clone https://github.com/your-username/ngx-html-bridge.git
cd ngx-html-bridge
npm install

Usage

The tool can be used as a library in your own scripts. Here is a basic example:

// examples/basic-usage.ts
import { parseAngularTemplate } from '../src/main';

// Define the path to your Angular template
const templatePath = 'path/to/your/template.html';

// Parse the template to get all possible HTML string outputs
const htmlVariations = parseAngularTemplate(templatePath);

// Log the variations to the console
console.log(htmlVariations);

/*
  You can now iterate through `htmlVariations` and run each string
  through your favorite HTML validator or linter.
*/

To run the example file, use:

npm run example

Development Scripts

  • Install dependencies: npm install
  • Build the tool: npm run build
  • Run tests: npm test
  • Lint the code: npm run lint

Contributing

Contributions are welcome! Please feel free to fork the repository, make your changes, and submit a pull request. Ensure that all tests and lint checks pass before submitting.

License

This project is licensed under the MIT License.