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

jsonhtml

v1.0.0

Published

JSON goes in, HTML comes out

Downloads

43

Readme

JSONHTML

JSON goes in HTML comes out, pretty straightforward ;) It might seen like a lot of JSON for some HTML, but it's better then having HTML in your javascript.

JSONHTML is only 1,22kb so why not just use it and keep your code clean.

Installation

Bower

bower install jsonhtml

NPM

<script src="dist/jsonhtml.min.js" type="application/javascript"></script>

Usage

Define your JSON object, nest away!

var json = {
    dom: {
        children: [
            {
                tag: 'body',
                children: [
                    {
                        tag: 'h1',
                        inner: 'Your page title',
                    }
                ]
            }
        ]
    }
};

Adding attributes to elements

{
    tag: 'a',
    inner: 'Go to page',
    attr: {
        href: '/your-page',
        class: 'btn'
    }
}

Output:

<a href="/your-page" class="btn">Go to page</a>

Multiple classes

{
    tag: 'a',
    attr: {
        href: '/your-page',
        class: ['btn', 'green', 'large']
    }
}

Output:

<a href="/your-page" class="btn green large">Go to page</a>

Inner text replacement

{
    tag: 'h1',
    inner: ['Change this %s because I like %s', ['text', 'stuff']]
}

Output:

<h1>Change this text because I like stuff</h1>

Callbacks

var json = {
    dom: {},
    onBefore: function () { // Call an inline function, or 
    
    },
    onComplete: 'otherFunction' // Call function by string
};

Examples

Here are a few examples that could be useful

Table

{
    tag: 'table',
    children: [
        {
            tag: 'tr',
            children: [
                { tag: 'th', inner: 'Name' },
                { tag: 'th', inner: 'Age' },
                { tag: 'th', inner: 'County' }
            ]
        },
        {
            tag: 'tr',
            children: [
                { tag: 'td', inner: 'Gus' },
                { tag: 'td', inner: '23' },
                { tag: 'td', inner: 'The Netherlands' }
            ]
        },
        {
            tag: 'tr',
            children: [
                { tag: 'td', inner: 'Steven' },
                { tag: 'td', inner: '54' },
                { tag: 'td', inner: 'Columbia' }
            ]
        },
        {
            tag: 'tr',
            children: [
                { tag: 'td', inner: 'Esther' },
                { tag: 'td', inner: '28' },
                { tag: 'td', inner: 'Germany' }
            ]
        }
    ]
}

Output:

<table>
    <tr>
        <th>Name</th>
        <th>Age</th>
        <th>County</th>
    </tr>
    <tr>
        <td>Gus</td>
        <td>23</td>
        <td>The Netherlands</td>
    </tr>
    <tr>
        <td>Steven</td>
        <td>54</td>
        <td>Columbia</td>
    </tr>
    <tr>
        <td>Esther</td>
        <td>28</td>
        <td>Germany</td>
    </tr>
</table>

Form

{
    tag: 'form',
    attr: {
        method: 'post',
        action: '/some-page'
    },
    children: [
        {
            tag: 'div',
            attr: { class: 'input-container' },
            children: [
                {
                    tag: 'label',
                    inner: 'Name',
                    attr: {
                        for: 'Name'
                    }
                },
                {
                    tag: 'input',
                    attr: {
                        type: 'text',
                        id: 'Name',
                        placeholder: 'Enter your name'
                    }
                }
            ]
        },
        {
            tag: 'div',
            attr: { class: 'input-container' },
            children: [
                {
                    tag: 'label',
                    inner: 'E-mail',
                    attr: {
                        for: 'Email'
                    }
                },
                {
                    tag: 'input',
                    attr: {
                        type: 'email',
                        id: 'Email'
                    }
                }
            ]
        },
        {
            tag: 'div',
            attr: { class: 'input-container' },
            children: [
                {
                    tag: 'input',
                    attr: {
                        type: 'submit',
                    }
                }
            ]
        }
    ]
}

Output:

<form action="/some-page" method="post">
    <div class="input-container">
        <label for="Name">Name</label><input id="Name" placeholder="Enter your name" type="text">
    </div>
    <div class="input-container">
        <label for="Email">E-mail</label><input id="Email" type="email">
    </div>
    <div class="input-container">
        <input type="submit">
    </div>
</form>

Changelog

1.0 Inital version