select-dom
Advanced tools
Comparing version 9.1.1 to 9.2.0
@@ -40,2 +40,9 @@ import type { ParseSelector } from 'typed-query-selector/parser.js'; | ||
declare function $$<Selected extends Element = HTMLElement>(selectors: string | readonly string[], baseElements?: BaseElements): Selected[]; | ||
export { $, $$, lastElement, elementExists, expectElement }; | ||
/** | ||
* @param selectors One or more CSS selectors separated by commas | ||
* @param [baseElements] The element or list of elements to look inside of | ||
* @return An array of elements found | ||
*/ | ||
declare function expectElements<Selector extends string, Selected extends Element = ParseSelector<Selector, HTMLElement>>(selectors: Selector | readonly Selector[], baseElements?: BaseElements): Selected[]; | ||
declare function expectElements<Selected extends Element = HTMLElement>(selectors: string | readonly string[], baseElements?: BaseElements): Selected[]; | ||
export { $, $$, lastElement, elementExists, expectElement, expectElements }; |
13
index.js
@@ -65,2 +65,13 @@ // Type predicate for TypeScript | ||
} | ||
export { $, $$, lastElement, elementExists, expectElement }; | ||
function expectElements(selectors, baseElements) { | ||
// Shortcut with specified-but-null baseElements | ||
if (arguments.length === 2 && !baseElements) { | ||
throw new ElementNotFoundError('Expected elements not found because the base is specified but null'); | ||
} | ||
const elements = $$(selectors, baseElements); | ||
if (elements.length > 0) { | ||
return elements; | ||
} | ||
throw new ElementNotFoundError(`Expected elements not found: ${String(selectors)}`); | ||
} | ||
export { $, $$, lastElement, elementExists, expectElement, expectElements }; |
{ | ||
"name": "select-dom", | ||
"version": "9.1.1", | ||
"version": "9.2.0", | ||
"description": "Extra lightweight DOM selector helper", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -80,6 +80,10 @@ # select-dom [![][badge-gzip]][link-npm] [![npm downloads][badge-downloads]][link-npm] | ||
```ts | ||
import {$, $optional} from 'select-dom/strict.js'; | ||
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]'); | ||
``` | ||
@@ -86,0 +90,0 @@ |
@@ -1,1 +0,1 @@ | ||
export { $ as $optional, expectElement as $ } from './index.js'; | ||
export { $ as $optional, $$ as $$optional, expectElement as $, expectElements as $$, } from './index.js'; |
@@ -1,1 +0,1 @@ | ||
export { $ as $optional, expectElement as $ } from './index.js'; | ||
export { $ as $optional, $$ as $$optional, expectElement as $, expectElements as $$, } from './index.js'; |
11676
125
94