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

@liskadan/tstags

v0.1.0

Published

Simply generate HTML tags

Downloads

3

Readme

tsTags: typescript HTML generator

npm

Simply and quickly generate HTML. No need to write HTML directly.

What it does?

Turns this:

section([
  h1(article.title),
  h2(article.subtitle),
  div({ class: 'my-class' }, p(article.text)),
]);

Into this:

<section>
  <h1>Title</h1>
  <h2>Subtitle</h2>
  <div class="my-class">
    <p>Lorem ipsum dolor sit amet consectetur adipisicing elit.</p>
  </div>
</section>

Custom tags

You can also use custom tags:

tag('outer-tag', tag('inner-tag'));

And generate:

<outer-tag><inner-tag></inner-tag></outer-tag>

CSS-like class and id specifiers

With tag you can also specify class and id in the selector.

tag('div.wrap', tag('div#id123'));
<div class="wrap"><div id="id123"></div></div>

tag might also be better, that you don't need to import a separate function for each tag type.

Syntax

Empty elements:

title();
// or
tag('title');

Both become the same:

<title></title>

Attributes:

a({ href: 'url' });
// or
tag('a', { href: 'url' });
<a href="url"></a>

Inner data:

String:

div('Content');
// or
tag('div', 'Content');
<div>Content</div>

Element:

div(button());
// or
tag('div', tag('button'));
<div><button></button></div>

Or multiple inner elements:

ul([
  li('Apples'),
  li('Bees'),
  li('Cider'),
  li('Deer'),
  li('Egg'),
  li('Fruit'),
  li('Gorilla'),
]);
// or
tag('ul', [
  tag('li', 'Apples'),
  tag('li', 'Bees'),
  tag('li', 'Cider'),
  tag('li', 'Deer'),
  tag('li', 'Egg'),
  tag('li', 'Fruit'),
  tag('li', 'Gorilla'),
]);
<ul>
  <li>Apples</li>
  <li>Bees</li>
  <li>Cider</li>
  <li>Deer</li>
  <li>Egg</li>
  <li>Fruit</li>
  <li>Gorilla</li>
</ul>

Of course you can combine the syntax in any reasonable way. The advantage of tag is that you need to import only one function, which may or may not matter, depending on your use-case.

Generated HTML is not formatted.

If you want to write the result to a file, simply use something like:

fs = require('fs');

fs.writeFileSync('index.html', myGeneratedHtml);

Tag description

MDN description in tooltip.

Description