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

tagr-json-to-html

v0.0.6

Published

JSON to HTML elements with function passing IE9+

Downloads

1

Readme

tagr

create elements from JSON objects, compat with IE9+

a quick tour:

Check it out, start a server, open in browser. index.html (which has an empty body) loads the app. js/bundle.js (compiled from breakr.js, config.js, tagr.js, & walkr.js) gets json/mock.json Look at js/mock.json, this gets converted into the HTML that populates the index.html body

how it works:

tagr makes DOM elements from formatted JSON via "_element_" and "_contains_" properties

"_element_" values are valid HTML elements, including div, span, input, etc. Assign id's, classes, events and otherwise use $ object creation syntax.

{
  __element__: "div"
  click: function(){alert("TAGR ELEMENT CLICKED")},
  id: "test",
  addClass: "clickable"
}

Note: this example uses a JS native object, JSON format differs slightly:

  1. double quotes are required for property names, inner double quotes must be escaped
  2. passing functions requires a different syntax, detailed below in 'passing functions'

"_contains_" values should be another array of objects formatted like the above, where the parent object will contain the child in the rendered HTML (pretty obvious)

Then tagr walks the object and assigns "_parent_" property for contained elements if no "_parent_" property exists, the parent is $(document.body)

passing functions

NOTE: Passing functions from JSON is disabled by default. Enable this in js/config.js if you dare.

Passing functions with JS objects is easy and uses $ object creation syntax as above. JSON is a transport layer where functions are not allowed as a native transport object like numbers or booleans. Passing functions via JSON can be accomplished without using eval. Here is an example that uses the handler, similar to above, but it's value is an object with a "_function_" property and a value that is a string representation of a function.

"click" : {
      "__function__": "function(e) {console.log(e.currentTarget);}"
    },

Alternatively a single statement can be passed as follows.

"click" : {
      "__function__": "alert('TAGR JSON EVENT')"
    },

The full list of supported events is available at the top of tagr.js. Adding an item to this array and recompiling will add support for that event. Be careful not to list events that have HTML attribute names as this will block those attributes from being created properly.