tealight
ES2015 module for DOM queries.
Installation
Browser
A simple and fast way to get started is to include this script on your page:
<script src="https://unpkg.com/tealight"></script>
This will create the global variable tealight
.
Module
$ npm install tealight
CommonJS
const tealight = require('tealight')
ES2015
import tealight from 'tealight'
Usage
tealight
accepts a single argument, target
, and will always return an array of 0 or more DOM nodes.
tealight(target) => Array<Node>
For the examples below, assume we have this HTML fragment to query against:
<div id="jar">
<div class="chocolate-chip cookie"></div>
<div class="peanut-butter cookie"></div>
<div class="short-bread cookie"></div>
</div>
tealight(String<Selector>)
String
arguments will be used as DOM query selectors.
tealight('#jar')
tealight('.cookie')
Keep in mind that document.querySelectorAll
throws an error when passed an invalid selector (requiring a try/catch block), whereas tealight
will swallow the error and return an empty array.
tealight(Node)
Node
arguments will be wrapped in an Array
.
const node = document.querySelector('#jar')
tealight(node)
tealight(NodeList)
NodeList
arguments will be converted to Array
.
const nodeList = document.querySelectorAll('.cookie')
tealight(nodeList)
tealight(Array)
Array
arguments will be filtered, leaving only Node
items.
const node = document.querySelector('#jar')
const array = [node, null, '.cookie']
tealight(array)
© 2018 FISSSION, LLC.
Open source under the MIT License.