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

jquery.elemental

v1.1.0

Published

Jquery element creator

Downloads

1

Readme

jQuery.Elemental!

A javascript utility for easy and pretty creation of DOM elements using CSS syntax.

Usage

import elemental from 'Elemental'

const $divElement = elemental('div.class-one.class-two#myId');
// '<div class="class-one class-two" id="myId"><div>

const $list = elemental('ul#theList.list-unstyled')
    .append([
        elemental('li#one')
            .text('Item one')
            .css('background-color', 'blue'),
        elemental('li#two.red')
            .html(elemental('img', {
                src: '//path/to/my/image'
            }),
        elemental('li#three', {
            style: 'background-color: green;',
        })
            .text('Item three'),
]);
// <ul class="list-unstyled" id="theList">
//      <li id="one" style="background-color: blue;">
//          Item one
//      </li>
//      <li class="red" id="two">
//          <img src="//path/to/my/image"/>
//      </li>
//      <li id="three" style="background-color: green;">
//          Item three
//      </li>
//  </ul>


const $dataSpan = elemental('span', {}, {
    foo: 'bar'
});
console.log($dataSpan.data('foo'));
// 'bar'

Methods

constructor ( string string = 'div', object attr = {}, object data = {} ) jQuery Parses a given string and returns a jQuery object containing the element

  • string: The string to be parsed. This should be in the format tagName.class.class.class#id. tagName must be first, class(es) and id can be in any order. tagName defaults to div, class and id default to null.
  • attr: An object containing attributes that will be attached to the element. Note that if an ID is supplied in both the string and the attr, the string ID will be used.
  • data: An object to be passed to the element's dataset.

Notes

  • Classes and ID specified in the string argument are limited to alphanumeric characters and hyphens i.e they should match /[\w-]+/. If you want to have more complex characters you can pass them as properties in the attr object.
  • For convenience, The default export is a factory function that returns a new instance of the Elemental object. If you want to access the class itself you can import { Elemental } from 'jquery.elemental'.
  • Although the examples above use elemental as the function name, you can call it whatever you wish - I find $$ works nicely: import $$ from 'jquery.elemental'; const myDiv = $$('div#myDiv);.
  • This package is designed to be used with webpack and babel. The main entry in package json points to the ES6 module in /src. If this causes problems with your build process you can find the transpiled and bundled code in the /dist folder.