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

hummersmyth

v1.1.0

Published

Hummersmyth is a tiny and simple yet powerful HTML renderer and DOM creator for Node.js and the browser.

Downloads

3

Readme

Hummersmyth

Hummersmyth is a tiny and simple yet powerful HTML renderer and DOM creator for Node.js and the browser. Hummersmyth has no dependencies.

Getting started

Node.js

Install hummersmyth using npm.

npm install hummersmyth --save

Then require it into any module.

const Hummersmyth = require('hummersmyth');

Browser

Hummersmyth has no dependencies, which makes it easy to include in a browser.

You can download the latest release from the repository

Use a script tag to directly add Hummersmyth to the global scope.

<script src="hummersmyth.min.js"></script>

Usage

const 
  ul = Hummersmyth.ul,
  li = Hummersmyth.li,  
  p = Hummersmyth.p,
  input = Hummersmyth.input,
  div = Hummersmyth.div;

// Render HTML snippet. Attributes are specified as plain JSON objects.
// Each tag function supports a variable list of arguments. 
// Attributes descriptors should be passed before 'content' for better readability,
// but can also be mixed with element content.

var html = 
  ul({ id: 'the-list', class: "list" },
    li({ class: 'first-item'}, "First item"),
    li("Second item"),
    li("Third item")
  );

// -> html === <ul id="the-list" class="list"><li class="first-item">First item</li><li>Second item</li><li>Third item</li></ul>'

html = 
  p(
    input({ id: 'uid', type: 'text', value: "abc123" }),

    // Multiple attributes descriptors will be merged.
    input({ type: 'password' }, { id: 'pw' }, { class: 'password' })
  );

// -> html === <p><input id="uid" type="text" value="abc123"><input type="password" id="pw" class="password"></p>


// Attributes descriptors and element content can also be given as an array.
html = 
  div(
    [ 
      { id: "i1" }, 
      p("abc"), 
      { class: 'xyz' } 
    ]
  );

// -> html === <div id="i1" class="xyz"><p>abc</p></div>

Examples

Render complete HTML page

const 
  html = Hummersmyth.html,
  head = Hummersmyth.head,
  meta = Hummersmyth.meta,
  title = Hummersmyth.title,
  link = Hummersmyth.link,
  body = Hummersmyth.body,
  div = Hummersmyth.div,
  script = Hummersmyth.script;

var page = 
  html(
    head(
      meta({ charset: 'utf-8' }),
      meta({ 
        'http-equiv': 'X-UA-Compatible', 
        content: 'IE=edge'
      }),
      meta({
        name: 'viewport',
        content: 'width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0'
      }),	
      title("My page"),
      link({ 
        href: 'https://fonts.googleapis.com/css?family="Source+Sans+Pro"', 
        rel: 'stylesheet' 
      })
    ),
    body(
      div({ id: 'main' }),
      script({ 
        src: 'https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js', 
        language: 'javascript', 
        type: 'text/javascript' 
      }),
      script({ 
        src: '/static/index.js', 
        language: 'javascript', 
        type: 'text/javascript' 
      })
    )
  );

Dynamically update DOM

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Hummersmyth example</title>
</head>
<body>
    <script src="hummersmyth.min.js"></script>
    <script>
      document.addEventListener('DOMContentLoaded', function()
      {
        // div is just a shortcut ...
        const div = Hummersmyth.div;

        var snippet = div({ id: 'main' }, "Blah");

        // Hummersmyth exports 2 methods to add html snippets to an existing DOM element.
        // - appendTo(element, html)
        // - prependTo(element, html)
        Hummersmyth.appendTo(document.body, snippet);
      });
    </script>
</body>
</html>

Dynamically update DOM using jQuery

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Hummersmyth example</title>
</head>
<body>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <script src="hummersmyth.min.js"></script>
    <script>
        $(document).ready(function()
        {
          // div is just a shortcut ...
          const div = Hummersmyth.div;

          var snippet = div({ id: 'main' }, "Blah");

          $('body').append(snippet);
        });
    </script>
</body>
</html>

More examples

Please refer to the test spec for more examples.

API

Hummersmyth exports the following list of HTML tags as functions

  • a, abbr, address, area, article, aside, audio
  • b, base, bdi, bdo, blockquote, body, br, button
  • canvas, caption, cite, code, col, colgroup
  • data, datalist, dd, del, details, dfn, div, dl, dt
  • em, embed
  • fieldset, figcaption, figure, footer, form
  • h1, h2, h3, h4, h5, h6, head, header, hr, html
  • i, iframe, img, input, ins
  • kbd, keygen
  • label, legend, li, link
  • main, map, mark, menu, menuitem, meta, meter
  • nav, noscript
  • object, ol, optgroup, option, output
  • p, param, pre, progress
  • q
  • rp, rt, ruby
  • s, samp, script, section, select, small, source, span, strong, style, sub, summary, sup
  • table, tbody, td, textarea, tfoot, th, thead, time, title, tr, track
  • u, ul
  • var, video
  • wbr

In the browser 2 more methods are available to add html snippets to an existing DOM element.

  • Hummersmyth.appendTo(element, html)
  • Hummersmyth.prependTo(element, html)

Parameter element can be an existing DOM element, a string like #id-of-element or id-of-element to reference the target element by id, or a jQuery object.

Testing

We use

Steps to be taken

  • Clone or download the repository.
  • Change into the project directory.
  • Use npm install to install all development dependencies.
  • Use npm runt lint to run static code analysis.
  • Use npm test to run the tests.
  • Use npm run coverage to track test coverage.
  • The output should display successful execution results and a code coverage map.

Build

  • Clone or download the repository.
  • Change into project directory.
  • Use npm run build in project directory to build hummersmyth.min.js from hummersmyth.js.

Contribution

Please use Github issues for requests.

Pull requests are welcome.

Issues

We use GitHub issues to track bugs. Please ensure your bug description is clear and has sufficient instructions to be able to reproduce the issue.

The absolute best way to report a bug is to submit a pull request including a new failing test which describes the bug. When the bug is fixed, your pull request can then be merged.

The next best way to report a bug is to provide a reduced test case on jsFiddle or jsBin or produce exact code inline in the issue which will reproduce the bug.

Support

Changelog

v1.1.0

  • Update npm modules.
  • Update and extend test environment.
  • Add static code analysis tool JSHint.
  • Add Karma test runner.
  • Fix JSHint issues.
  • Replace uglify-js by terser for minification.
  • Update README.

v1.0.3

  • Update npm modules.

v1.0.2

  • Update npm modules.

v1.0.1

  • Update npm modules.

v1.0.0

  • Initial public release

License

Copyright (c) 2013-present, Belexos. Hummersmyth is licensed under the MIT License.