hachescript
TypeScript icon, indicating that this package has built-in type declarations

1.2.0 • Public • Published

hachescript

Create HTML strings using JavaScript, anywhere. Like Hyperscript but faster, and without the overhead of creating actual HTML elements.

Installation

Using npm, npm i hachescript.

Using yarn, yarn add hachescript.

Usage

Using import

import { h } from 'hachescript';

const str = h(
  'div#myId.myClass', // the selector. supports ID and multiple classes
  'hello world', // The content. Can be a simple string, another HTML tag created by hachescript, or an array of them
  {
    dataIndex: 'hello',
    class: ['text-muted', 'text-primary'],
  } // Additional attributes. camelCase will be converted to kebab-case
);

// str is '<div id="myId" class="myClass text-muted text-primary" data-index="hello">hello world</div>'

In a CommonJS environment

const { h } = require('hachescript');

const str = h(
  'img', // self closing tags will be detected
  '', // Always provide a content nevertheless
  {
    src: 'dog.png',
    class: 'rounded',
  }
);

// str is '<img class="rounded" src="dog.png"/>'

Documentation

See DOCS

Readme

Keywords

Package Sidebar

Install

npm i hachescript

Weekly Downloads

47

Version

1.2.0

License

MIT

Unpacked Size

90 kB

Total Files

31

Last publish

Collaborators

  • alrico88