Security News
New Python Packaging Proposal Aims to Solve Phantom Dependency Problem with SBOMs
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.
select-dom
Advanced tools
Lightweight
querySelector
/All
wrapper that outputs an Array
npm install select-dom
import {$, $$, lastElement, elementExists} from 'select-dom';
// And a stricter version
import {$, $optional} from 'select-dom/strict.js';
Note: if a falsy value is passed as baseElement
, you'll always get an empty result (bd578b9)
$(selector[, baseElement = document])
Maps to baseElement.querySelector(selector)
, except it returns undefined
if it's not found
$('.foo a[href=bar]');
// => <Element>
$('.foo a[href=bar]', baseElement);
// => <Element>
$('.non-existent', baseElement);
// => undefined
lastElement(selector[, baseElement = document])
Like $()
, except that it returns the last matching item on the page instead of the first one.
elementExists(selector[, baseElement = document])
Tests the existence of one or more elements matching the selector. It's like $()
, except it returns a boolean
.
elementExists('.foo a[href=bar]');
// => true/false
elementExists('.foo a[href=bar]', baseElement);
// => true/false
countElements(selector[, baseElement = document])
Counts the number of elements found on the page or in the base element. Just a shortcut over $$(selector).length
countElements('a');
// => 3
$$(selector[, baseElements = document])
Maps to baseElements.querySelectorAll(selector)
plus:
baseElements
can be a list of elements to query$$('.foo');
// => [<Element>, <Element>, <Element>]
$$('.foo', baseElement);
// => [<Element>, <Element>, <Element>]
$$('.foo', [baseElement1, baseElement2]);
// => [<Element>, <Element>, <Element>]
// This is similar to jQuery([baseElement1, baseElement2]).find('.foo')
The strict export will throw an error if the element is not found, instead of returning undefined
. This is also reflected in the types, which are non-nullable:
import {$, $optional, $$, $$optional} from 'select-dom/strict.js';
const must: HTMLAnchorElement = $('.foo a[href=bar]'); //
const optional: HTMLAnchorElement | undefined = $optional('.foo a[href=bar]');
const oneOrMore: HTMLAnchorElement[] = $$('.foo a[href=bar]'); //
const zeroOrMore: HTMLAnchorElement[] = $$optional('.foo a[href=bar]');
DocumentFragment
or one Element
, in a few bytes.FAQs
Extra lightweight DOM selector helper
The npm package select-dom receives a total of 703 weekly downloads. As such, select-dom popularity was classified as not popular.
We found that select-dom demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.
Security News
Socket CEO Feross Aboukhadijeh discusses open source security challenges, including zero-day attacks and supply chain risks, on the Cyber Security Council podcast.
Security News
Research
Socket researchers uncover how threat actors weaponize Out-of-Band Application Security Testing (OAST) techniques across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.