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

dusk

v1.0.0

Published

A feathery, alacritous DOM abstraction, partly based on PlainJS

Downloads

4

Readme

dusk

A feathery (light), alacritous (fast), extensible DOM abstraction. (Partly based on PlainJS. And faster than jQuery)

At its core it's nothing but a selector that will return an array of HTMLElement's:

var $popup = dusk('#popup');              // will return a single-element array
var $rows  = dusk('.my-table tr');        // will return an array
var $oops  = dusk('.non-existing-class'); // will return an empty array

This means it has the same collection of methods as a native array. Pretty cool. And you can pass dusk some strange things as well:

var $itself  = dusk(dusk('div'));                      // dusk recognizes itself
var $list    = dusk(document.querySelectorAll('div')); // it turns NodeList's and HTMLCollection's into arrays
var $context = dusk('.class', '#context');             // and it can use a context

Getting Started

dusk implements the Universal Module Definition (UMD), and resides on NPM so that you can really use it any way you want. To include it in your project:

Download it...

Get it from https://github.com/mjsarfatti/dusk/blob/master/dist/dusk.js, then include it with:

HTML

<script src="path/to/dusk.js"></script>

AMD

require(['path/to/dusk.js'], function(dusk) {
	// ...
});

CommonJS

var dusk = require('path/to/dusk.js');

...or NPM it

$ npm install --save dusk, then:

CommonJS + NPM

var dusk = require('dusk');

ECMAScript 2015

import dusk from 'dusk';

Methods

At the moment it ships only one, static, method.

dusk.DOMReady

(shamelessly stolen from jQuery)

dusk.DOMReady(function() {
	// something to execute on DOM ready
});

Extend (Plugins)

But it's already apt to be extended!

const $demo = dusk('#demo');

dusk.fn.plugin1 = function () {
  // do something with `this` (remember, it's an array)
  return this;
};

dusk.fn.plugin2 = function () {
  // do something with `this`
  return this;
};

$demo.plugin1().plugin2();

The Future

Version 1.1 will include the following:

Events

  • .on()
  • .off()
  • .one()

Classes

  • .hasClass()
  • .addClass()
  • .removeClass()
  • .toggleClass()

It will also include polyfills for matches and closest.

This will cover 95% of the use cases. And remember, for all the rest you have PlainJS and the Fetch API.

Ps: of course, if you absolutely need .thirdChild() you can easily extend the core. In fact, that is the whole purpose of this: a super-lightweight extensible DOM abstraction.

Browser support

At the moment dusk has been tested on

  • IE11
  • Edge
  • Chrome
  • Firefox
  • Safari

Version 1.1 will be tested against IE9+ and mobile browsers as well.

License

dusk is released under the MIT license.