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

xneek-crel

v2.4.0

Published

A small constructor for generated DOM elements

Downloads

7

Readme

crEl

A small constructor for generated DOM elements

Readme RU-ru

Features

  • Cross-browser
  • Lightweight
  • Dependencies free
  • Events
  • Data-* attributes
  • Shortcut for most usable attributes (e,c,s,d)

##How it works ###What you need to get

<a href="#" class="btn">Click me</a>

###In the past

var a = document.createElement('a');
    a.setAttribute('href','#');
    a.setAttribute('class','btn');
    a.appendChild(document.createTextNode("Click me"))

###Right now


var a = crEl('a',{href:'#', c:'btn'}, "Click me")

##Docs

crEl(tagName,[attr, child-1,... child-n]) // return DOM element

c - is alias for "class" attribute s - is alias for "style" attribute d - for set data-* attributes e - for attach events

Required is only the first, it is a name tag . Attributes can be transmitted anywhere, but bestpractice would give them just behind the tag name. Nesting child elements is limited only by your needs.

###Events

Events can be attached to any of the created elements . Events are attached cross-browser , and you do not need to think about it . The called function is passed as a context element itself , so can be used to access the item this

var myFunc = function(){
	alert(this.innerHTML)
}
crEl('a',{href:'#', e:{click:myFunc}}, "Click me")

or use anonimous function

crEl('a',{href:'#', e:{click:function(){alert(this.innerHTML)}}}, "Click me");

or use inline syntax

crEl('a',{ onclick: function(){alert(this.innerHTML);}, href:'#'}, "Click me");
crEl('a',{ onclick: myFunc, href:'#'}, "Click me");

###Styles

You can use the classic inline styles , and specify them as properties of the object js

crEl('a',{href:'#', s:'color:red; font-weight:bold'}, "Click me")

or

crEl('a',{href:'#', s:{color:'red', fontWeight:'bold'}}, "Click me")

##Examples

    crEl('hr'); // return <hr> DOM element
    crEl('div',{c:'jumbotron'}); // return <div> DOM element with class jumbotron
    crEl('a',{href:'#'}, "link", crEl('sup',{ d:{role:'badge'}, s:'color:red'},"NEW")); 
    // return <a href="#">link<sup data-role="badge" style="color:red">NEW</sup></a>
    crEl("button",{e:{click:function(){alert('Ololo');}}},"Click Me"); // button with event click
    crEl('ul',{c:'menu', id:'menu'},
            crEl('li', crEl('a', {href:'#1'},"Link-1")),
            crEl('li', crEl('a', {href:'#2'},"Link-2")),
            crEl('li', crEl('a', {href:'#3'},"Link-3")),
    ); // typical menu
    var i = 0, menu = document.getElementById('menu');
    while(i<=100500){//to add 100500 items to the menu
        menu.appendChild( crEl('li', crEl('a', {href:'#'+i},"Link-"+i)) ); 
        i++;
    }

##Install ###Bower

    bower i https://github.com/xneek/crEl

##Simple converter HTML⇨crEl http://fednik.ru/f/crel/