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

adarna

v3.0.7

Published

A suite of javascript classes and functions that will help you build dynamic user interfaces.

Downloads

26

Readme

Adarna

Adarna is a suite of classes and functions that enable the development of dynamic web user interfaces, using purely javascript syntax.


Template Class

The Template class is the primary object in Adarna that is used to generate and manipulate DOM elements.

1.) The example code below will produce the corresponding HTML DOM elements:

import {Template} from './adarna.js';

const t = new Template();

t.div({class:'row'},()=>{

    t.div({class:'col6'},()=>{

        t.input({type:'text',id:'username'});
    });

    t.div({class:'col6'},()=>{

        t.input({type:'password',id:'password'});

    });
});

Result:

    <div class="row">
        <div class="col6">
            <input type="text" id="username"/>
        </div>
        <div class="col6">
            <input type="password" id="password"/>
        </div>
    </div>

2.) In order for the Template object to be visible, we use the render() function to attach the object onto the HTML

<html>
    <head></head>
    <body>
        <div id="app"></div>

        <script type="module">
            import {Template,render,$el,$q} from './adarna.js';

            const app   = $q('#app').first();
            const t     = new Template();

            let ui = t.div({class:'row'},()=>{

                t.div({class:'col6'},()=>{

                    t.input({type:'text',id:'username'});
                });

                t.div({class:'col6'},()=>{

                    t.input({type:'password',id:'password'});

                });
            });

            $el.append(ui).to(app);

        </script>
    </body>
</html>

3.) You can use the compile() method of the Template class to combined all generated elements in one parent document fragment.

    import {Template,render} from './adarna.js';

    const app   = document.querySelector('#app');
    const t     = new Template();

    let data = {1:'yes',0:'no'};

    t.div({class:'row'},()=>{

        t.div({class:'col6'},()=>{
            t.input({type:'text',id:'username'});
        });//div

        t.div({class:'col6'},()=>{
            t.input({type:'password',id:'password'});
        });//div

    });//div

    /******************************************/

    t.div({class:'row'},()=>{

        t.div({class:'col12'},()=>{

            t.select(()=>{

                for(let key in data){

                    let text = data[key];
                    t.option({value:key},text);
                }

            });//div

        });//div

    });//div


    //Combined all DOM elements into one document fragment
    let ui = t.compile();

    render(ui).to(app);

this will result into a document fragment that contains the HTML elements below.

     <div class="row">
        <div class="col6">
            <input type="text" id="username"/>
        </div>
        <div class="col6">
            <input type="password" id="password"/>
        </div>
    </div>

    <div class="row">
        <div class="col12">
            <select>
                <option value="1">Yes</option>
                <option value="0">No</option>
            </select>
        </div>
    </div>

4.) You can use a JSON object with camelcase notion as parameter for the in-line style attribute.

    import {Template} from './adarna.js';

    const t = new Template();

    t.div({
        style:{
            backgroundColor:'blue',
            color:'white'
        }
    },'Hello World');

This will generate the HTML element:

    <div style="background-color:'blue';color:'white'">
        Hello World
    </div>

5.) DOM elements are generated by calling the tag name as a method of the Template object. This will return an HTML object with additional custom properties and methods. The paramters used in the method can be arranged in the following configuration below.

Type 1


    /*
        Parameter 1: Object for attributes
        Parameter 2: Arrow function callback for inner HTML 
    */
    t.div({},(el)=>{

    });

Type 2

    /* 
        Parameter 1: Object for attributes
        Parameter 2: String for inner text
    */
     t.div({},'Inner text');

Type 3

    /*
        Parameter 1: Arrow function callback for inner HTML 
    */
    t.div((el)=>{

    });

Type 4

    /*  
        Parameter 1: String for inner text 
    */
    t.div('Inner text');

6.) Handling of events can be done using regular javascript methods


    let button = t.button('I am a button');

    button.onclick = (e)=>{
        alert('Hello World');
    }

    button.addEventListener('click',(e)=>{
        alert('Hello again!');
    });

7.) In order to create an independent text node a special method is available called txt().


    t.span(()=>{
        t.txt('Hello World');
    });

This will produce the result

    <span>Hello World</span>

8.) You can declare conditional statements or complex logic inside the arrow callback function to produce desired results when generating an element.


    let test = Math.random() < 0.5;

    t.div(()=>{

        if(test){
            t.txt('Hello World');
        }else{
            t.h1('Hakuna Matata');
        }

    });

This code will produce either

    <div>Hello World</div>

or

    <div>
        <h1>Hakuna Matata</h1>
    </div>