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

domali

v2.1.1

Published

Alias library for using the DOM API

Downloads

104

Readme

Alias Library for the DOM API

Build Status npm version

The goal of domali is to provide a more readable DOM API while keeping the core functionality intact. You can use all of the native JavaScript DOM functions and objects with domali.

Usage

import dom from 'domali'

const [ foo, bar, baz ] = dom.getId('foo', 'bar', 'baz')

console.log(foo, bar, baz)

Install domali with npm npm install --save domali

Or install domali with jspm jspm install domali

Load domali through a module loader for the browser. Popular choices for module loading include webpack, jspm, and browserify. Destructuring requires ES6.

API

dom.getId (string) - Get an element by its id

const foo = dom.getId('foo')

dom.getId (strings) - Get multiple elements by their ids

const [ foo, bar, baz ] = dom.getId('foo', 'bar', 'baz')

dom.getClass (string) - Get multiple elements by their class name

const bar = dom.getClass('bar')

dom.getTags (string) - Get multiple elements by their tag name

const divs = dom.getTags('div')

dom.select (string) - Select an element with a query

const foo = dom.select('#foo')

dom.selectAll (string) - Select multiple elements with a query

const baz = dom.selectAll('.baz')

dom.create (string) - Create a new element

const div = dom.create('div')

console.log(div === '<div></div>') // true

dom.create (strings) - Create multiple new elements

const [ p, a, img ] = dom.create('p', 'a', 'img')

console.log(p === '<p></p>') // true
console.log(a === '<a></a>') // true
console.log(img === '<img></img>') // true

dom.clone (element) - Clone an existing element to a new element

const div = dom.create('div').text('hey')
      
const newDiv = dom.clone(div)

console.log(newDiv) // <div>hey</div>

dom.render (element) - Render an element to the DOM

const div = dom.create('div').text('Hello, domali!')

dom.render(div)

dom.clear () - Clear everything from the DOM

dom.clear()

element.text (string) - Add or update an element's text

const div = dom.create('div').text('hello')

console.log(div.textContent === 'hello') // true

element.push (element) - Append a child element after an element's children

const div = dom.create('div')

div.push(dom.create('div'))
div.push(dom.create('i'))
div.push(dom.create('span'))

console.log(div.firstChild === '<div></div>') // true

element.unshift (element) - Insert a child element before an element's children

const div = dom.create('div')

div.unshift(dom.create('div'))
div.unshift(dom.create('i'))
div.unshift(dom.create('span'))

console.log(div.firstChild === '<span></span>') // true

element.map (fn (element)) - Transform an element's children

const rootDiv = dom.create('div')

rootDiv.push(dom.create('div'))
rootDiv.push(dom.create('div'))
rootDiv.push(dom.create('div'))

const newDiv = rootDiv.map(div => {

  console.log(div) // <div></div>
    
  return dom.create('a')
})

console.log(newDiv)
// <div>
//   <a></a>
//   <a></a>
//   <a></a>
// </div>

element.set (object) - Set an element's attribute

const div = dom
  .create('div')
  .set({ id: 'foo' })
  
console.log(div) // <div id="foo"></div>

element.get (string) - Get an element's attribute

const divId = dom
  .create('div')
  .set({ id: 'foo' })
  .get('id') 
  
console.log(divId) // foo

element.set (object) - Set multiple element attributes

const a = dom
  .create('a')
  .set({ 
    id: 'my-link',
    href: 'https://google.com',
    class: 'link'
  }) 
  
console.log(a) // <a id="my-link" href="https://google.com" class="link"></a>

element.get (strings) - Get multiple element attributes

const [imgId, imgSrc, imgClass] = dom
  .create('img')
  .set({ 
    id: 'my-image',
    src: 'some-image.png',
    class: 'photo'
  })
  .get('id', 'src', 'class')
  
console.log(imgId) // my-image
console.log(imgSrc) // some-image.png
console.log(imgClass) // photo