BlingBlingJS
like bling.js, but more bling
Getting Started
Installation
npm i blingblingjs
Importing
import $ from 'blingblingjs'
const $ = require('blingblingjs')
Syntax
Quick Overview
$()
$().on
$().off
$().attr
$().map
Queries
const btns = $('button')
const [first_btn] = $('button[primary]')
const btn_spans = $('span', btns)
const [sugared_single] = $(document.querySelector('button'))
const sugared_buttons = $(document.querySelectorAll('button'))
Array Methods
$('button').forEach(...)
$('button').map(...)
const btns = $('button')
btns.filter(...)
btns.reduce(...)
btns.flatMap(...)
...
Events
first_btn.on('click', ({target}) => console.log(target))
$('button[primary]').on('click', e => console.log(e))
$('h1').on('click touchend', ({target}) => console.log(target))
const log_event = e => console.warn(e)
main_btn.on('contextmenu', log_event)
main_btn.off('contextmenu', log_event)
Attributes
$('button.rad').attr('rad', true)
const [rad_btn] = $('button.rad')
rad_btn.attr({
test: 'foo',
hi: 'bye',
})
rad_btn.attr('rad')
rad_btn.attr('hi')
$('button').map(btn => ({
tests: btn.attr('tests'),
hi: btn.attr('hi'),
}))
rad_btn.attr('hi', null)
rad_btn.attr('hi')
btns.attr({
test: null,
hi: null,
})
What for?
Developer ergonomics!
If you agree with any of the following, you may appreciate this micro library:
- Love vanilla js, want to keep your code close to it
- Chaining is fun, Arrays are fun, essentially a functional programming fan
- Hate typing
document.querySelector
over.. and over.. - Hate typing
addEventListener
over.. and over.. - Really wish
document.querySelectorAll
had array methods on it.. - Confused that there is no
node.setAttributes({...})
or even better nodeList.setAttributes({...})
- Liked jQuery selector syntax
Why BlingBling?
- Minimal at 0.6kb (636 bytes)
- BlingBling supports ES6 module importing and common module loading
- Supports chaining
- Worth it's weight (should save more characters than it loads)
- Only enhances the nodes you query with it
- ES6 version of popular bling.js by Paul Irish
- Tested