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

intrahtml

v1.1.3

Published

One-shot methods for vanilla and jQuery to make HTML as easy to update as it is to create

Downloads

3

Readme

intraHTML

makes HTML as easy to live-update as create

fast incremental view updates using virtual-DOM DIFFs and live DOM patching

Usage

intraHTML(element, strNewInnerHTMLContent);

Install

donwload, npm install intrahtml, or bower install intrahtml

Replace the old and busted:

main.innerHTML=myContent; $("#main").html(myContent);

With the fresh and shiny:

intraHTML(main, myContent); $("#main").intraHTML(myContent);

Demos

Useful Helper Methods

intraHTML exposes a few "static methods"

updater(elmDest, objVDOM) returns a function that accepts HTML to update the view with. elementFromString(strHTML) browser-based parser turns elements into vdom objects fromHTML(source, containerTagName) quickly parses an html string or DOM element into a vdom object parseHTML(strHTML) string-based parser turns HTML strings into vdom objects toHTML(objVDOM) turns a vdom object into an HTML string odiff(a,b) internal differ used on VDOMs by intraHTML, for testing and general use, ex: dirty checking

Options (defaults)

blnTiming (false) enable to gather performance information about parsing, diffing, and applying dom updates blnDebug (false) enable to dump detailed info to the console for debugging blnParser (true) disable (10x slower) for compat w/ HTML namespaces, funky attribs, or invalid nesting.

How does it work?

For a div with 1 sub-tag: <div id="d"><br></div> suppose we call intraHTML(d,"<hr />"); :

  1. Turns existing DOM branch into a JS-object virtual DOM <br> -> {$:"br"}
  2. Turns the new HTML content into a virtual DOM "<hr />" -> {$:"hr"}
  3. DIFFs old and new virtual DOM to make a change list [{type: "set", path: ["$"], val: "hr"}]
  4. Applies list of changes to the live DOM to update the view <div id="d"><hr></div>

The infoview demo makes the parts and workings clear.

Why use it?

It combines the user-friendliness of data-binding with the flexibility of html string generation.

Setting div.innerHTML with new content destroys form values, selections, scroll positions, and mode. Conversely, generating HTML these days is incredibly fast and convenient with everything from templates like Mustache/Handlbars/Jade, to PHP and it's cornucopia of frameworks.

If one could simply generate new HTML and show it, apps would be easy to develop. Now, it's easy to do just that. With intraHTML, you can update your entire view without the nasty side-effects. Any and all template systems can seamlessly keep a view updated.

How is intraHTML different?

intraHTML is far simpler; it's just a function that updates the DOM with a string, wherever that string might come from, even a server! Feed output into intraHTML and enjoy user-friendly live view updates without any dom-pointing CSS selectors or data binding; it really is magical.

The perf demo lets you compare many approaches, including react and vanilla.

Advantages

  • simple way to accomplish "data binding" (smooth partial updates) with an existing vanilla JS project
  • simplest virtual-dom-based view updater available
  • tiny - less to learn, break, and deliver to users
  • scanning the live DOM before DIFFing allows other tools/plugins that modify the DOM, unlike Angular and React
  • clean HTML input and output: no camelCase, invalid attributes, or unique IDs thoughout the markup

Disadvantages

  • few features compared to frameworks
  • scanning the live DOM before DIFFing potentially costs CPU compared to virtual-view memorizing frameworks
  • the DIFF algo may not be the fastest or result in the most compact set of mutations possible