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

html-stitcher

v0.1.2

Published

CLI tool to build HTML files from partial files

Downloads

2

Readme

html-stitcher

About The Project

html-stitcher is a CLI build tool for compiling HTML files from re-usable components. It is designed for decomposing large HTML files into smaller chunks to make them easier to work with, improving readability and allowing re-use.

To illustrate the concept, html-stitcher takes the files:

<!-- index.html -->
<html>
<body>
    <greeting></greeting>
</body>
</html>

<!-- greeting.partial.html -->
<p>Hello from html-stitcher!</p>

And compiles them into:

<html>
<body>
    <p>Hello from html-stitcher!</p>
</body>
</html>

The Build Process

html-stitcher reads HTML files, which are either categorized into root files or partial files:

  • Root files act as entrypoints for html-stitcher to process and generate output for. Output may be written to file or to the terminal to be piped elsewhere.
  • Partial files are only processed when referenced by another file. The output of processing a partial file is written into the output for the file that referenced it.

Any file can include the output of a partial file in its own output by including a <name></name> element, where name is the name of the partial file, preceding the first dot.

Installation

npm install --save-dev html-stitcher

Usage

Process a single file:

html-stitcher path/to/root/file.html

Or process a directory:

html-stitcher path/to/src/directory -o path/to/dist/directory

Options

For the full set of arguments, see html-stitcher --help.

--output <path>

  • When processing a single file, <path> is a file where the output will be written to
  • When processing a directory, <path> is an existing directory where all output files will be written

--partial-files <pattern>

  • <pattern> is a glob pattern that html-stitcher uses to find partial files, relative to the input file or directory.

--root-files <pattern>

  • <pattern> is a glob pattern that html-stitcher uses to find root files, relative to the input directory. This option is not used when processing single file inputs.

--parameters <params..>

Features

Parameter Substitution

Files processed by html-stitcher may include ${param} strings, where param is the name of a parameter value to be substituted in its place:

<!-- city.partial.html -->
<li>
    <b style="color: ${color}">${name}</b>
    <p>Population: ${population}</p>
</li>

Parameters can either be defined with the --parameters argument, or they can be defined as attributes added to the partial element of the including file:

<!-- index.html -->
<h2>Largest Cities by Population</h2>
<ol>
    <!-- Each city has a `name`, `population` and `color` parameter -->
    <city name="Tokyo" population="37,468,000" color="red"></city>
    <city name="Delhi" population="28,514,000" color="blue"></city>
    <city name="Shanghai" population="25,582,000" color="green"></city>
</ol>

The output of processing index.html is:

<!-- output.html -->
<h2>Largest Cities by Population</h2>
<ol>
    <li>
        <b style="color: red">Tokyo</b>
        <p>Population: 37,468,000</p>
    </li>
    <li>
        <b style="color: blue">Delhi</b>
        <p>Population: 28,514,000</p>
    </li>
    <li>
        <b style="color: green">Shanghai</b>
        <p>Population: 25,582,000</p>
    </li>
</ol>

Inner Substitution

Inner substitution is a variation of parameter substitution, only the parameter name is inner and the parameter value is the inner HTML content of the partial element:

<!-- card.partial.html -->
<div>
    <p>${inner}</p>
</div>

<!-- index.html -->
<div>
    <card>The quick brown fox jumps over the lazy dog</card>
    <card>The five boxing wizards jump quickly</card>
    <card>How vexingly quick daft zebras jump</card>
</div>

<!-- output.html -->
<div>
    <div>
        <p>The quick brown fox jumps over the lazy dog</p>
    </div>
    <div>
        <p>The five boxing wizards jump quickly</p>
    </div>
    <div>
        <p>How vexingly quick daft zebras jump</p>
    </div>
</div>

Examples

This GitHub repo provides a set of minimal examples:

Acknowledgements

Thanks to..

  • commander for the command line interface
  • glob for pattern based file searching
  • xml2js for some minimal HTML parsing

Road Map

  • Optional end tags when including partials - i.e. allow <greeting> in place of <greeting></greeting>.