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 🙏

© 2026 – Pkg Stats / Ryan Hefner

create-elements

v1.1.9

Published

Create Elements

Readme

Build Status

Welcome to Cr.elm Library - think of it as document.create

The easy way to go from HTML to Javascript and back again!

This library is designed to make it easy to turn a static block of HTML into a dynamic Javascript wonderhorse.

This library is great if you

  1. want to dynamically create elements in javascript
  2. wish to avoid innerHTML or document.write
  3. wish to populate node properties dynamically

Here is what the transition looks like: link

Harnessing the power of javascript to internationalize the chrome extension example above: link

The javascript grew by only 1KB in size from HTML, everything is in the same place it was... And now you can do neat things with it!

For Example: Call internationalization functions while creating the elements you need.

  Cr.elm('div',{'event':['click',doSomething]},[
    Cr.txt(chrome.i18n.getMessage('buttonTextTranslation'))
  ],document.body);

The HTML into Cr.elm nested javascript converter can be found here: http://vidsbee.com/Cr.elm/fromhtml/

Event Listeners - - History - Present

About Cr-Legacy and Cr-img

Cr Js - Installation

npm install create-elements

var Cr = require('./node_modules/create-elements/Cr.js')(document); // client side you may omit document

More Examples of HTML to Javascript

Cr Node - Server Side

  var Cr = require('create-elements')(); // creates a new Cr-document using Cr-node.js
  var document = Cr.doc;

or

  var Cr = require('./node_modules/create-elements/Cr-node.js')();
  var document = Cr.doc;

oorr use a custom document

  var CrDocument = require('./node_modules/create-elements/DOM/Cr-document.js');
  var document = new CrDocument();
  var Cr = require('create-elements')(document);

ooorrr

  var document = new (require('./node_modules/create-elements/DOM/Cr-document.js'));
  var Cr = require('create-elements')(document);
(how to extend)

If you need to use Cr-json.js you'll have to require it.

  Cr = require('./node_modules/create-elements/Cr-json.js')(Cr);

or simply

  require('./node_modules/create-elements/Cr-json.js')(Cr);

include shortcuts including only Cr.div, Cr.span, Cr.a

  require('./node_modules/create-elements/Cr-shortcuts.js')(Cr);

See Cr-node.js - See that file for recommendations.

(how to render)

Turns out it's a lot faster to try to re-use the same document between requests

  var elm1 = Cr.elm('div',{class:'cssrules'},[
    Cr.elm('a',{'href':'#freshLinks'},[Cr.txt('Click Me '), Cr.ent(' ')])
  ],document.body);

  var link2 = Cr.elm('a',{'href':'#link2'},[
    Cr.txt("You Know What to Do!"),
    Cr.elm('br'),
    Cr.txt("Make text")
  ],elm1);

  Cr.insertNode(link2, document.body, elm1);

  Cr.elm('title',{},[
    Cr.txt("Document Title")
  ],document.head);

  var headerFrag = Cr.frag([
    Cr.elm("script",{src:"Cr.js"}),
    Cr.elm("script",{src:"Cr-json.js"}),
    Cr.elm("link",{href:"test.css", type:'text/css', rel:'stylesheet'})
  ]);

  document.head.appendChild(headerFrag);

a special attribute childNodes may be used, and you may then omit the 3rd argument - this provides superior indentation:

  var elm1 = Cr.elm('div',{
    class:'cssrules',
    childNodes: [
      Cr.elm('a',{
        href:'#freshLinks',
        childNodes: [Cr.txt('Click Me '), Cr.ent(' ')]
      })
    ]
  },document.body);

  var link2 = Cr.elm('a',{
    href:'#link2',
    childNodes: [
      Cr.txt("You Know What to Do!"),
      Cr.elm('br'),
      Cr.txt("Make text")
    ]
  },elm1);

  Cr.insertNode(link2, document.body, elm1);

  Cr.elm('title',{
    childNodes: [Cr.txt("Document Title")]
  },document.head);

(coffeescript)

It works, used in tests for more examples

  myDiv = Cr.elm 'div',
    style: "color:blue;"
    class: Cr.list ["magic"]
    [
      Cr.elm 'span', {href:"defined", class:"wildtest"}, [Cr.txt(string1)]
      Cr.elm 'span', {class:"word"}, [
        Cr.elm 'span', {class:"wildtest"}, [Cr.txt(string1)]
        Cr.elm 'span', {class:"word2 word"}, [Cr.txt(string2)]
      ]
      Cr.elm 'span', {class:"wildtest"}, [Cr.txt(string3)]
      Cr.elm 'span', {class:"up"},
        [Cr.elm 'span', {id:"woah",class:"woah1"}, [Cr.txt(string3)]]
      Cr.elm 'span', {class:"word2-yourmom word word3"}, [Cr.txt(string3)]
      Cr.elm 'span', {},
        [
          Cr.elm 'h3', {},
            [Cr.elm 'span', {id:"woah",class:"woah1"}, [Cr.txt(string1)]]
        ]
    ]
    document.body

a special attribute childNodes may be used, and you may then omit the 3rd argument child nodes array

(really how to render)
  document.outerHTML; // with doctype

or

  document.html.outerHTML; // without doctype

or

  document.body.outerHTML; // just the body

etc.

that should give you everything you would expect to send to the client. You may set document.doctype as needed. keep in mind document is not completely what you expect client side, it is a trimmed down version with only essential functionality for Cr and basic querySelectAll to retrieve "lost" node references. The outer most node is returned.

See Cr-node-test-server.js
See Cr-node-test-server-fast.js
See Cr-node-test.js
See Cr-node.js to see how its initialized - this is what is required by default

License

You can use this in your projects. There are no guarantees. If you make money using this then you or those who profit should share the wealth. If you use this it is your responsibility to make sure that the use of this code is fair to it's developers. This may include attribution and/or direct payment. Otherwise see LICENSE file.

Contact or Paypal: samlarison [at] gmail [dot] com