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

microhtml

v0.1.5

Published

Simple library to generate HTML in JavaScript.

Downloads

3

Readme

Introduction

Github Downloads (total) Github Downloads (total) Github Downloads (total) Github Downloads (total)

Let's connect library

const { createElement } = require('microhtml');

Firstly you must have AST

The syntax is pretty simple.

const AST = {
   tagName: 'h1', // Any
   type: 'paired', // 'single' or 'paired'
   attr: {
      variant: 'bold'
   },
   children: [
      {...},
      {...},
   ],
   body: 'Hello world!'
};

And now we can create our element, then transform it to HTML code.

const element = createElement(AST).transform();
console.log(element);

// output: <h1 variant="bold">Hello world!</h1>

A few words about AST

AST is an object that can contain tagName type attr children and body fields and nothing more! Elements created as the "single" type cannot have "children" and "body", only attributes, so you can leave these fields as empty object and array respectively. children field must be an array of the same objects as above.

Classes

Functions

HTMLElement

Kind: global class
Summary: Create an instance of HTMLElement
Access: public

new HTMLElement(tagName, type, props, body)

Returns: HTMLElement - HTMLElement instance

| Param | Type | Description | | --- | --- | --- | | tagName | String | tag definition | | type | String | tag type (can be 'single' or 'paired') | | props | Object | expects object with two fields: children (ARRAY), attribute (OBJECT) | | body | String | inner body text. |

Example

const element = new HTMLElement(
      'h1',
      'paired',
      { attributes: {...}, children: [...] },
      'Hello world!',
    );

htmlElement.transform()

Kind: instance method of HTMLElement
Summary: transform
Access: public
Example

const element = new HTMLElement(
      'h1',
      'paired',
      { attributes: {...}, children: [...] },
      'Hello world!',
    );
element.transform();
> '<h1>Hello world!</h1>'

createDocument() ⇒ True

Creates document from certain content, like HTML tags.

Kind: global function
Returns: True - - if operation succeed.

| Type | Description | | --- | --- | | String | HTML document file name. | | String | HTML document content. |

createElement() ⇒ HTMLElement

Recursive function that generates "HTMLElement" object from given AST.

Kind: global function

| Type | Description | | --- | --- | | Object | AST |

Example

const AST = {
  tagName: 'html',
  type: 'paired',
  attr: {
    lang: 'ru',
  },
  children: [
    {
      tagName: 'body',
      type: 'paired',
      attr: {},
      children: [],
      body: ''
    },
    {
      tagName: 'img',
      type: 'single',
      attr: {},
      children: [],
      body: ''
    }
  ],
  body: '',
};
const elem = createElement(AST).transform();
createDocument('index', elem);