basic-devtools

Social Media Photo by Basic Moto France on Unsplash
Exports $
, $$
, and $x
utilities as described in Chrome Console Utilities API reference, all in 242 bytes once "minzipped" or 206 bytes once "minbrotlied".
import {$, $$, $x} from 'basic-devtools';
$('nope') === null;
$('body') === document.body;
$$('body').length === 1;
$$('body')[0] === document.body;
$x('//body').length === 1;
$x('//body')[0] === document.body;
What's the deal with XPath?
It's extremely powerful but also generally faster than a TreeWalker, as you can test live.
As example, let's consider this Question:
"How would I grab all data-* attributes and reach their element with a single-pass query?"
Answer
const allDataAttributes = $x('//@*[starts-with(name(), "data-")]');
for (const {name, value, ownerElement} of allDataAttributes) {
}
You can have a gist of various other features via this awesome Xpath cheatsheet.