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 🙏

© 2025 – Pkg Stats / Ryan Hefner

blue-js

v3.0.2

Published

A super lightweight functional commonjs dom & events library

Downloads

53

Readme

blue-js

Build Status npm version Greenkeeper badge codecov gzip size

blue-js is a super lightweight commonjs javascript dom & events library

This library is developed and maintained internally at bluegrassdigital

Installation

npm install blue-js

Upgrading from V2

The top level module exports dom , events and ps are gone, all methods are exported directly from the root module, muvh like lodash.

The pubsub implementation ps has been removed as it was somewhat outside the scope of this library - please use something like https://github.com/developit/mitt instead.

API

blue

A collection of dom utility functions

blue.addClass(el, cls)

Add a class to an element

| Param | Type | Description | | --- | --- | --- | | el | HTMLElement | The dom node | | cls | String | The class to add |

blue.each(els, fn)

Iterate over a dom NodeList

| Param | Type | Description | | --- | --- | --- | | els | NodeList | The NodeList (created using getElementsByTagName or getElementsByClassName or querySelectorAll) to loop over | | fn | function | The function to run against each element. Arguments passed are the same as Array.forEach |

blue.filter(els, fn) ⇒ Array

Filters a dom NodeList, returning an array of only those elements which match the predicate function

Returns: Array - A filtered array of dom elements

| Param | Type | Description | | --- | --- | --- | | els | NodeList | The NodeList (created using getElementsByTagName or getElementsByClassName or querySelectorAll) to filter | | fn | function | The predicate function to test each Element against |

Example
Filter only foo links with class 'bar':

import { filter } from 'blue-js'

const fooLinks = document.querySelectorAll('a.foo')
const filteredLinks = filter(fooLinks, el => dom.hasClass(el, 'bar'))

Filter only visible filteredLinks:

import { filter } from 'blue-js'

const fooLinks = document.querySelectorAll('a.foo')
const newFilteredLinks = filter(filteredLinks, dom.isVisible)

blue.getWindowDimensions([w], [d]) ⇒ windowDimensions

Cross browser funtion for getting the dimensions of the window

Returns: windowDimensions - The window dimensions

| Param | Type | Default | Description | | --- | --- | --- | --- | | [w] | object | window | The window element | | [d] | object | document | The document element |

blue.hasClass(el, cls)

Check if an element has a class

| Param | Type | Description | | --- | --- | --- | | el | HTMLElement | The dom node | | cls | String | The classname to check |

blue.isHidden(el) ⇒ Boolean

Check whether an element is hidden

Returns: Boolean - True if el is visibly hidden, otherwise false

| Param | Type | Description | | --- | --- | --- | | el | HTMLElement | The dom node |

blue.isVisible(el) ⇒ Boolean

Check whether an element is visible

Returns: Boolean - True if el is visible, otherwise false

| Param | Type | Description | | --- | --- | --- | | el | HTMLElement | The dom node |

blue.onReady(fn)

A callback that fires when the document is ready - roughly equaivalent to jQuery document ready

| Param | Type | Description | | --- | --- | --- | | fn | function | The callback to fire |

blue.removeClass(el, cls)

Remove a class from an element

| Param | Type | Description | | --- | --- | --- | | el | HTMLElement | The dom node | | cls | String | The class to remove |

blue.toggleClass(el, cls)

Toggle a class on an element

| Param | Type | Description | | --- | --- | --- | | el | HTMLElement | The dom node | | cls | String | The class to toggle |

blue.wrap(el, argument1, [argument2])

Wrap an html element with another element or with a wrap function

| Param | Type | Description | | --- | --- | --- | | el | HTMLElement | The dom node | | argument1 | function | HTMLElement | string | A callback function which is passed el.outerHTML as its only function parameter OR a dom node to wrap around the element OO the first of two string arguments to go before and after the element | | [argument2] | string | The string to use for after the dom element (both argument1 and argument2 should be strings) |

Example
Using a wrapper function:

import { wrap } from 'blue-js'

const foo = document.querySelector('#foo')
wrap(foo, html => `<div class="wrapper">${html}</div>`)

Example
Using an html element:

import { wrap } from 'blue-js'

const foo = document.querySelector('#foo')
const wrapper = document.createElement('div')
wrap(foo, wrapper)

Example
Using two strings:

import { wrap } from 'blue-js'

const foo = document.querySelector('#foo')
wrap(foo, '<div class="wrapper">', '</div>')

blue.listen(el, names, fn, capture) ⇒ Object

Listen for one or more events (custom or standard)

Returns: Object - An object with a remove method to remove the listener later

| Param | Type | Description | | --- | --- | --- | | el | HTMLElement | The dom element | | names | String | The event or events (space-separated) to listen for | | fn | function | The callback to fire when the event occurs | | capture | Boolean | Whether to capture the event or not |

Example
Add a listener:

import { listen } from 'blue-js'

const fooLink = document.querySelector('a.foo')

listen(fooLink, 'click', (event) => {
  event.preventDefault()
  const { target } = event
  target.classlist.add('.is-clicked')
})

Example
Remove listener later:

import { listen } from 'blue-js'

const fooLink = document.querySelector('a.foo')

const listener = listen(fooLink, 'click', (event) => {
  event.preventDefault()
  const { target } = event
  target.classlist.add('.is-clicked')
})
//Some time later
listener.remove()

Example
Remove listener immediately:

import { listen } from 'blue-js'

const fooLink = document.querySelector('a.foo')

const listener = listen(fooLink, 'click', (event) => {
  event.preventDefault()
  const { target } = event
  target.classlist.add('.is-clicked')
  listener.remove()
})

blue.listenCollection(els, names, fn, capture)

Same as events.listen, excpet for NodeList rather than a single Element

| Param | Type | Description | | --- | --- | --- | | els | NodeList | The dom collection | | names | String | The event or events (space-separated) to listen for | | fn | function | The callback to fire when the event occurs | | capture | Boolean | Whether to capture the event or not |

blue.removeListeners(els, names)

Remove one or more events from one or more targets

| Param | Type | Description | | --- | --- | --- | | els | HTMLElement | The dom element or any iterable containing dom elements (eg. NodeList) | | names | String | The event or events (space separated) to remove the listeners for |

Example

import { removeListeners } from 'blue-js'

const fooLinks = document.querySelectorAll('a.foo')
removeListeners(fooLinks, 'click mouseenter')

blue.trigger(el, name, [data], [eventProps])

Trigger any event on a dom element, optionally pass data

| Param | Type | Description | | --- | --- | --- | | el | HTMLElement | The dom node | | name | String | The event to trigger | | [data] | Object | The data to pass along with the event | | [eventProps] | Object | Other event properties to override the defaults, which are { bubbles: true, cancelable: true } |

Example

import { listen, trigger } from 'blue-js'

const fooLink = document.querySelector('a.foo')
trigger(fooLink, 'Link:Event', { foo: 'bar' })

// Listen for custom event and use the custom data passed to trigger
listen(fooLink, 'Link:Event', event => {
  console.log(event.detail.foo) // -> 'bar'
})

blue.windowDimensions : Object

Kind: static typedef of blue
Properties

| Name | Type | Description | | --- | --- | --- | | width | number | Window width | | height | number | Window height |

Contributing to blue-js

Standard JS applies

camelCase for function and variable names

Github Flow - branch, submit pull requests

Getting set up

  • Pull the repo
  • run npm install
  • run npm start to run all unit tests, lint the codebase, and build the API docs

Contribute

First off, thanks for taking the time to contribute! Now, take a moment to be sure your contributions make sense to everyone else.

Reporting Issues

Found a problem? Want a new feature? First of all see if your issue or idea has already been reported. If it hasn't, just open a new clear and descriptive issue.

Submitting pull requests

Pull requests are the greatest contributions, so be sure they are focused in scope, and do avoid unrelated commits.

  • Fork it!
  • Clone your fork: git clone https://github.com/<your-username>/blue-js
  • Navigate to the newly cloned directory: cd blue-js
  • Create a new branch for the new feature: git checkout -b my-new-feature
  • Install the tools necessary for development: npm install
  • Make your changes.
  • npm test to make sure your change doesn't break anything.
  • Commit your changes: git commit -am 'Add some feature'
  • Push to the branch: git push origin my-new-feature
  • Submit a pull request with full remarks documenting your changes.