Skip to content

Commit c31101c

Browse files
added: types
1 parent 9a7fc91 commit c31101c

File tree

4 files changed

+88
-49
lines changed

4 files changed

+88
-49
lines changed

index.d.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
type Scope = Element
2+
| Window
3+
| Document
4+
5+
// borrowed from DOM querySelectorAll
6+
declare function $<K extends keyof HTMLElementTagNameMap>(selectors: K, scope?: Scope): NodeListOf<HTMLElementTagNameMap[K]>;
7+
declare function $<K extends keyof SVGElementTagNameMap>(selectors: K, scope?: Scope): NodeListOf<SVGElementTagNameMap[K]>;
8+
declare function $<E extends Element = Element>(selectors: string, scope?: Scope): NodeListOf<E>;
9+
declare function $<W extends Window>(selectors: W, scope?: Scope): [W];
10+
declare function $<D extends Document>(selectors: D, scope?: Scope): [D];
11+
12+
export default $

index.next.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ import domToArray from 'bianco.dom-to-array'
33
/**
44
* Simple helper to find DOM nodes returning them as array like loopable object
55
* @param { string|DOMNodeList } selector - either the query or the DOM nodes to arraify
6-
* @param { HTMLElement } ctx - context defining where the query will search for the DOM nodes
6+
* @param { HTMLElement } scope - context defining where the query will search for the DOM nodes
77
* @returns { Array } DOM nodes found as array
88
*/
9-
export default function $(selector, ctx) {
9+
export default function $(selector, scope) {
1010
return domToArray(typeof selector === 'string' ?
11-
(ctx || document).querySelectorAll(selector) :
11+
(scope || document).querySelectorAll(selector) :
1212
selector
1313
)
1414
}

package-lock.json

Lines changed: 72 additions & 46 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"main": "index.js",
66
"jsnext:main": "index.next.js",
77
"module": "index.next.js",
8+
"types": "index.d.ts",
89
"scripts": {
910
"prepare": "npm run build && npm test",
1011
"lint": "eslint index.next.js test.js rollup.config.js",

0 commit comments

Comments
 (0)