select-dom
Advanced tools
Comparing version 7.1.1 to 8.0.0
@@ -1,3 +0,3 @@ | ||
import type { ParseSelector } from 'typed-query-selector/parser'; | ||
declare type BaseElements = ParentNode | Iterable<ParentNode>; | ||
import type { ParseSelector } from 'typed-query-selector/parser.js'; | ||
type BaseElements = ParentNode | Iterable<ParentNode>; | ||
/** | ||
@@ -8,3 +8,4 @@ * @param selectors One or more CSS selectors separated by commas | ||
*/ | ||
declare function select<Selector extends string, TElement extends Element = ParseSelector<Selector, HTMLElement>>(selectors: Selector | Selector[], baseElement?: ParentNode): TElement | undefined; | ||
declare function select<Selector extends string, Selected extends Element = ParseSelector<Selector, HTMLElement>>(selectors: Selector | Selector[], baseElement?: ParentNode): Selected | undefined; | ||
declare function select<Selected extends Element = HTMLElement>(selectors: string | string[], baseElement?: ParentNode): Selected | undefined; | ||
declare namespace select { | ||
@@ -15,8 +16,2 @@ var last: typeof selectLast; | ||
} | ||
declare function select<TElement extends Element = HTMLElement>(selectors: string | string[], baseElement?: ParentNode): TElement | undefined; | ||
declare namespace select { | ||
var last: typeof selectLast; | ||
var exists: typeof selectExists; | ||
var all: typeof selectAll; | ||
} | ||
/** | ||
@@ -27,4 +22,4 @@ * @param selectors One or more CSS selectors separated by commas | ||
*/ | ||
declare function selectLast<Selector extends string, TElement extends Element = ParseSelector<Selector, HTMLElement>>(selectors: Selector | Selector[], baseElement?: ParentNode): TElement | undefined; | ||
declare function selectLast<TElement extends Element = HTMLElement>(selectors: string | string[], baseElement?: ParentNode): TElement | undefined; | ||
declare function selectLast<Selector extends string, Selected extends Element = ParseSelector<Selector, HTMLElement>>(selectors: Selector | Selector[], baseElement?: ParentNode): Selected | undefined; | ||
declare function selectLast<Selected extends Element = HTMLElement>(selectors: string | string[], baseElement?: ParentNode): Selected | undefined; | ||
/** | ||
@@ -41,4 +36,4 @@ * @param selectors One or more CSS selectors separated by commas | ||
*/ | ||
declare function selectAll<Selector extends string, TElement extends Element = ParseSelector<Selector, HTMLElement>>(selectors: Selector | Selector[], baseElements?: BaseElements): TElement[]; | ||
declare function selectAll<TElement extends Element = HTMLElement>(selectors: string | string[], baseElements?: BaseElements): TElement[]; | ||
declare function selectAll<Selector extends string, Selected extends Element = ParseSelector<Selector, HTMLElement>>(selectors: Selector | Selector[], baseElements?: BaseElements): Selected[]; | ||
declare function selectAll<Selected extends Element = HTMLElement>(selectors: string | string[], baseElements?: BaseElements): Selected[]; | ||
export default select; |
@@ -6,3 +6,2 @@ // Type predicate for TypeScript | ||
function select(selectors, baseElement) { | ||
var _a; | ||
// Shortcut with specified-but-null baseElement | ||
@@ -12,3 +11,3 @@ if (arguments.length === 2 && !baseElement) { | ||
} | ||
return (_a = (baseElement !== null && baseElement !== void 0 ? baseElement : document).querySelector(String(selectors))) !== null && _a !== void 0 ? _a : undefined; | ||
return (baseElement ?? document).querySelector(String(selectors)) ?? undefined; | ||
} | ||
@@ -20,3 +19,3 @@ function selectLast(selectors, baseElement) { | ||
} | ||
const all = (baseElement !== null && baseElement !== void 0 ? baseElement : document).querySelectorAll(String(selectors)); | ||
const all = (baseElement ?? document).querySelectorAll(String(selectors)); | ||
return all[all.length - 1]; | ||
@@ -34,3 +33,3 @@ } | ||
} | ||
return Boolean((baseElement !== null && baseElement !== void 0 ? baseElement : document).querySelector(String(selectors))); | ||
return Boolean((baseElement ?? document).querySelector(String(selectors))); | ||
} | ||
@@ -44,3 +43,3 @@ function selectAll(selectors, baseElements) { | ||
if (!baseElements || isQueryable(baseElements)) { | ||
const elements = (baseElements !== null && baseElements !== void 0 ? baseElements : document).querySelectorAll(String(selectors)); | ||
const elements = (baseElements ?? document).querySelectorAll(String(selectors)); | ||
return [...elements]; | ||
@@ -47,0 +46,0 @@ } |
{ | ||
"name": "select-dom", | ||
"version": "7.1.1", | ||
"version": "8.0.0", | ||
"description": "Extra lightweight DOM selector helper", | ||
@@ -16,7 +16,9 @@ "keywords": [ | ||
"repository": "fregante/select-dom", | ||
"funding": "https://github.com/sponsors/fregante", | ||
"license": "MIT", | ||
"author": "Federico Brigante <me@fregante.com> (https://fregante.com)", | ||
"type": "module", | ||
"main": "index.js", | ||
"module": "index.js", | ||
"exports": "./index.js", | ||
"main": "./index.js", | ||
"types": "./index.d.ts", | ||
"files": [ | ||
@@ -39,14 +41,17 @@ "index.js", | ||
"dependencies": { | ||
"typed-query-selector": "^2.4.1" | ||
"typed-query-selector": "^2.11.0" | ||
}, | ||
"devDependencies": { | ||
"@sindresorhus/tsconfig": "^1.0.1", | ||
"@sindresorhus/tsconfig": "^3.0.1", | ||
"browserify": "^17.0.0", | ||
"esmify": "^2.1.1", | ||
"tape": "^5.2.2", | ||
"tape-run": "^8.0.0", | ||
"tsd": "^0.14.0", | ||
"typescript": "^4.2.3", | ||
"xo": "^0.38.2" | ||
"tape": "^5.6.4", | ||
"tape-run": "^10.0.0", | ||
"tsd": "^0.28.1", | ||
"typescript": "^5.1.6", | ||
"xo": "^0.54.2" | ||
}, | ||
"engines": { | ||
"node": ">=16" | ||
} | ||
} |
@@ -80,2 +80,1 @@ # select-dom [![][badge-gzip]][link-npm] [![npm downloads][badge-downloads]][link-npm] | ||
- [doma](https://github.com/fregante/doma) - Parse an HTML string into `DocumentFragment` or one `Element`, in a few bytes. | ||
- [Refined GitHub](https://github.com/sindresorhus/refined-github) - Uses this module. |
Sorry, the diff of this file is not supported yet
8821
88
80
Updatedtyped-query-selector@^2.11.0