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

daton

v1.0.0

Published

A parser for object notations embedded in the dom via data attributes

Downloads

2

Readme

DATON

[Demo] [Tests]

DATON (Data ATtribute Object Notation) is a javascript parser for object notations embedded in the dom via data attributes. The main use case for this is to allow progressive enhancement such that a sever could render standard markup decorated with DATON specific attributes and then these can be easily parsed and accessed in javascript as plain old objects.

Usage

Include DATON in your page

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

In your markup render DATON specific attributes to represent data that should be parsed

<div id="data">
  <ul data-dtn-array="people">
    <li data-dtn-object>
      <a href="http://www.google.com" data-dtn-attr="{ 'link' : 'href' }">
        <img src="/img/joe.png" width="400" data-dtn-attr="{ 'image' : 'src', 'size' : 'width'  }" />
        <h4 data-dtn-value="name">Joe blogs</h4>
        <p>Job Role: <span data-dtn-value="role">Director</span></p>
        <p>Email: <span data-dtn-value="email">[email protected]</span></p>
        <div data-dtn-object="address">
          <p data-dtn-value="line1">10 Some St</p>
          <p data-dtn-value="town">Barnsley</p>
          <p data-dtn-value="postcode">S75 1RE</p>
        </div>
      </a>
    </li>
    <li data-dtn-object>
        <a href="http://www.yahoo.com" data-dtn-attr="{ 'link' : 'href' }">
        <img src="/img/jane.png" width="400" data-dtn-attr="{ 'image' : 'src', 'size' : 'width' }"  />
        <h4 data-dtn-value="name">Jane blogs</h4>
        <p>Job Role: <span data-dtn-value="role">Director</span></p>
        <p>Email: <span data-dtn-value="email">[email protected]</span></p>
      </a>
    </li>
  </ul>
</div>

In your javascript, call DATON.parse on your root dom node

var div = document.getElementById('data');
var result = DATON.parse(div);
console.log(result);

// Output
{
    "people":[
        {
            "link":"http://www.google.com",
            "image":"/img/joe.png",
            "size":"400",
            "name":"Joe blogs",
            "role":"Director",
            "email":"[email protected]",
            "address":{
                "line1":"10 Some St",
                "town":"Barnsley",
                "postcode":"S75 1RE"
            }
        },{
            "link":"http://www.yahoo.com",
            "image":"/img/jane.png",
            "size":"400",
            "name":"Jane blogs",
            "role":"Director",
            "email":"[email protected]"
        }
    ]
}

Supported attributes are

  • data-dtn-array Denotes the start of an array
  • data-dtn-object Denotes the start of an object
  • data-dtn-attr Defines an attribute map where the object key denotes the target property name, and the value denotes the attribute value to extract
  • data-dtn-value Denotes a value entry taking the inner text content of the dom node

For attributes data-dtn-array, data-dtn-object and data-dtn-value the value of the attribute denotes the object key within the parsed parent object context. If the parent object context is an array, the value can be ommitted and the parsed child objects / values will be pushed into the array in order of occurance.