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 🙏

© 2026 – Pkg Stats / Ryan Hefner

j2ht

v1.1.0

Published

Javascript to html template engine.

Readme

J2ht (Under Development)

J2ht is a Javascript to html template Engine

The idea came when I stumbled upon this library html-creator, and before then i have always wanted to extend html without using any template engine just some codes, and I ended up with a template engine lol.

It may feel weird when you think about it but I find it kinda fun and hope you do too.

Installation

Npm

npm i j2ht

Yarn

yarn add j2ht

Demo

If you clone this repo there are some examples you can examine using your I.D.E

  • npm run test:basic - A basic console example
  • npm run test:server - A server example using Xpresser
  • npm run test:merge - An example showing how to import views and merge them.

Basic Usage

const {pretty, RawHtml, Elements} = require('j2ht');
const {Doctype, Html, Head, Title, Body, H2, H5} = require('j2ht/js/elements');

const user = 'paul';

const template = Elements(
    Doctype(),
    Html(
        Head(Title('My First App')),
        Body(
            H2('Hello World'),
            RawHtml(`<h5>A message from RawHtml</h5>`),
            
            // Conditional views. 
            user === 'paul' ?
                H5('Hey Paul 👋') : H5('Hey unknown user! 😏')
        ),
    )
)

console.log(pretty(template));

This will return

<!DOCTYPE html>
<html>
  <head>
    <title>My First App</title>
  </head>

  <body>
    <h2>Hello World</h2>
    <h5>A message from RawHtml</h5>
    <h5>Hey Paul 👋</h5>
  </body>

</html>

For Merging Views only

File Structure

-html
    -footer.html
    -header.html
    -Home.html
app.js

app.js

const {pretty, Elements, FromFile} = require('j2ht');

const template2 = Elements(
    FromFile(__dirname + '/html/header.html'),
    FromFile(__dirname + '/html/Home.html'),
    FromFile(__dirname + '/html/footer.html'),
)

console.log(pretty(template2));

Elements

For now only few html elements are out of the box. i will add new ones in the near future. But adding yours is not difficult.

if you take a look at the elements.ts file you can see how default elements are created. For example <div> was created using the following line

const {HtmlElement} = require('j2ht');
exports.Div = (...contents) => new HtmlElement('div').content(contents);

// To create a table element
exports.Table = (...contents) => new HtmlElement('table').content(contents);

Every HtmlElement instance has a render() method that builds it and returns html data

const {Div, H1} = require('j2ht/js/elements');

const component = Div(H1('Hello World'))

console.log(component.render());

Calling .render() will render and return


<div><h1>Hello World</h1></div>

Components

j2ht being javascript can be easily extendable.

Lets make a bulma buttons component bulma-buttons.js

const {Button} = require('j2ht/js/elements');

exports.PrimaryButton = (...content) => Button(...content).class('button is-primary');
exports.SuccessButton = (...content) => Button(...content).class('button is-success');

Notice how we always use spread operators? this is because of the syntax concept where Elements are functions, and their arguments are child contents.

const {Div} = require('j2ht/js/elements');
const {PrimaryButton, SuccessButton} = require('./bulma-buttons');

Div(
    PrimaryButton('Save'),
    SuccessButton('Cancel')
)

Div is a function while it's children are arguments. you can also pass them as an array.

Div([
    PrimaryButton('Save'),
    SuccessButton('Cancel')
])

Both will render

<div>
    <button class="button is-primary">Save</button>
    <button class="button is-danger">Cancel</button>
</div>

I will keep adding more features and maybe along the line i will find more use for it. Feel free to contribute if you like this project.