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

hta

v1.3.1

Published

The tiny framework for building Hyper Text Application with ease

Downloads

13

Readme

HTA

The tiny framework for building Hyper Text Application with ease

Why HTA ?

  • Write less do more
  • No compiler or bundler needed
  • Easy to convert HTML template to HTA
  • Extremely fast DOM updating
  • Built-in store and router

Installation

npm install hta --save

Comparison with Other Frameworks

Syntax

Let's create simple counter app

HTA

import { $, render } from "hta";

const initialState = { count: 0 };
const Increase = ({ count }) => ({ count: count + 1 });
const CounterValue = (props, select) => $`<h1>${select("count")}</h1>`;
const CounterAction = () =>
  $`<button ${{ onclick: [Increase] }}>Increase</button>`;
const App = () => $`
  ${CounterValue}
  ${CounterAction}`;
render(App, { state: initialState });

React + Redux Toolkit

import React from "react";
import { render } from "react-dom";
import { connect, Provider } from "react-redux";
import { configureStore, createAction, createReducer } from "@reduxjs/toolkit";

const increment = createAction("INCREMENT");
const reducer = createReducer(0, {
  [increment.type]: (state) => state + 1,
});
const store = configureStore({ reducer });

const CounterValue = connect((state) => ({ count: state }))(({ count }) => (
  <h1>{count}</h1>
));
const CounterAction = connect(null, { increment })(({ increment }) => (
  <button onClick={increment}>Increase</button>
));
const App = () => (
  <>
    <Provider store={store}>
      <CounterValue />
      <CounterAction />
    </Provider>
  </>
);
render(<App />, document.body);

Features

| Feature | HTA | React | Vue | Angular | | :------------------------ | :-----: | :-----: | :-----: | :-----: | | Compiler / Bundler needed | | ☑ | ☑ | ☑ | | Async Rendering | ☑ | | | | | Two Way Binding | ☑ | | ☑ | ☑ | | SVG Supported | ☑ | | ☑ | ☑ | | Directive | ☑ | | ☑ | ☑ | | Built-in Router | ☑ | | | ☑ | | Built-in Store | ☑ | | | | | Suspense | ☑ | ☑ | | | | Declarative | ☑ | ☑ | | | | Component | ☑ | ☑ | ☑ | ☑ | | Functional Hooks | ☑ | ☑ | ☑ | | | Lazy Component | ☑ | ☑ | ☑ | ☑ | | Shared Context | ☑ | ☑ | ☑ | ☑ |

Basic Usages

Render simple HTML

import { $, render } from "hta";
render($`<h1>Hello World</h1>`);

Using substitutions

import { $, render } from "hta";
render($`<h1>It is ${new Date().toLocaleTimeString()}.</h1>`);

If the substitution is:

  • string/number/Date: It will be rendered as text node
  • boolean/undefined/null: It will not be rendered
  • Function: HTA understands the function is component and render the component content/result
  • Tuple [Function, object]: HTA renders component with specified props (the second item of tuple)
  • Promise/Plain object: By default HTA renders these text node, and the node value is toString() result, but you can add extras (please refer JSON tag extras) to handle plain object rendering.

Using element binding

import { $, render } from "hta";
render(
  // add style attribute and textContent property bindings to DIV element
  $`<div ${{ style: "font-weight: bold", textContent: "Hello World" }}></div>`
);

The binding must be placed in open tag. You can bind any element property / attribute.

Handling element event

import { $, render } from "hta";
render($`<button ${{ onclick: () => alert("Hello World") }}>Click me</button>`);

HTA treats the binding which starts with on*** as event handler.

If you want to bind some element property/attribute which starts with on*** ? Using { attr: { attrName: value } } for attribute binding and { prop: { propName: value } } for property binding

Updating element text

There are 2 ways to update element text

  1. Using text / textContent binding
  2. Using substitution is more flexible than above
import { $, render } from "hta";
render($`
  <button ${{ text: "Button 1" }}></button>
  <button ${{ textContext: "Button 2" }}></button>
  <button>${"Button 3"} ${"Other text"}</button>
`);

Updating element HTML

There are 2 ways to update element HTML

  1. Using text / textContent binding
  2. Using substitution is more flexible than above
import { $, render } from "hta";
render($`
  <button ${{ html: "<strong>Button 1</strong>" }}></button>
  <button ${{ innerHTML: "<strong>Button 2</strong>" }}></button>
  <button>${$`<strong>Button 3</strong>`} ${$("Other HTML")}</button>
`);

Component

HTA component is pure function, that receives component props and return component content

function MyComponent(props) {
  return $`<h2>Hello ${props.name}</h2>`;
}

function App() {
  return $`
    <h1>Component Demo</h1>
    <!-- passing tuple to substitution to render MyComponent with specified props  -->
    ${[MyComponent, { name: "World" }]}
  `;
}

render(App);

Component content is anything, it is the same as substitution

Advanced Usages

Examples

API references