Skip to content

Commit

Permalink
Meta fixes; Output ES2020
Browse files Browse the repository at this point in the history
  • Loading branch information
fregante committed Jul 7, 2023
1 parent 93c4880 commit a475ba4
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 51 deletions.
11 changes: 7 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Test
name: CI

on:
- pull_request
Expand All @@ -8,22 +8,25 @@ jobs:
Lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- run: npm install
- run: npx xo

Types:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- run: npm install
- run: npm run build
- run: npx tsd

Test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- run: npm install
- run: npm run build
- run: sudo apt-get install xvfb
Expand Down
56 changes: 28 additions & 28 deletions index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type {ParseSelector} from 'typed-query-selector/parser';
import type {ParseSelector} from 'typed-query-selector/parser.js';

// WARNING: Overloads have to repeated in that fashion because the actual function’s signature is discarded; Only the 2 overloads are brought into the .d.ts file. Tests pass because `tsd` reads from this file instead of `.d.ts`

Expand All @@ -15,49 +15,49 @@ function isQueryable(object: BaseElements): object is ParentNode {
* @param [baseElement] The element to look inside of
* @return The element found, if any
*/
function select<Selector extends string, TElement extends Element = ParseSelector<Selector, HTMLElement>>(
function select<Selector extends string, Selected extends Element = ParseSelector<Selector, HTMLElement>>(
selectors: Selector | Selector[],
baseElement?: ParentNode
): TElement | undefined;
function select<TElement extends Element = HTMLElement>(
): Selected | undefined;
function select<Selected extends Element = HTMLElement>(
selectors: string | string[],
baseElement?: ParentNode
): TElement | undefined;
function select<TElement extends Element>(
): Selected | undefined;
function select<Selected extends Element>(
selectors: string | string[],
baseElement?: ParentNode
): TElement | undefined {
baseElement?: ParentNode,
): Selected | undefined {
// Shortcut with specified-but-null baseElement
if (arguments.length === 2 && !baseElement) {
return;
}

return (baseElement ?? document).querySelector<TElement>(String(selectors)) ?? undefined;
return (baseElement ?? document).querySelector<Selected>(String(selectors)) ?? undefined;
}

/**
* @param selectors One or more CSS selectors separated by commas
* @param [baseElement] The element to look inside of
* @return The element found, if any
*/
function selectLast<Selector extends string, TElement extends Element = ParseSelector<Selector, HTMLElement>>(
function selectLast<Selector extends string, Selected extends Element = ParseSelector<Selector, HTMLElement>>(
selectors: Selector | Selector[],
baseElement?: ParentNode
): TElement | undefined;
function selectLast<TElement extends Element = HTMLElement>(
): Selected | undefined;
function selectLast<Selected extends Element = HTMLElement>(
selectors: string | string[],
baseElement?: ParentNode
): TElement | undefined;
function selectLast<TElement extends Element>(
): Selected | undefined;
function selectLast<Selected extends Element>(
selectors: string | string[],
baseElement?: ParentNode
): TElement | undefined {
baseElement?: ParentNode,
): Selected | undefined {
// Shortcut with specified-but-null baseElement
if (arguments.length === 2 && !baseElement) {
return undefined;
}

const all = (baseElement ?? document).querySelectorAll<TElement>(String(selectors));
const all = (baseElement ?? document).querySelectorAll<Selected>(String(selectors));
return all[all.length - 1];
}

Expand All @@ -68,7 +68,7 @@ function selectLast<TElement extends Element>(
*/
function selectExists(
selectors: string | string[],
baseElement?: ParentNode
baseElement?: ParentNode,
): boolean {
// Shortcut with specified-but-null baseElement
if (arguments.length === 2 && !baseElement) {
Expand All @@ -83,32 +83,32 @@ function selectExists(
* @param [baseElements] The element or list of elements to look inside of
* @return An array of elements found
*/
function selectAll<Selector extends string, TElement extends Element = ParseSelector<Selector, HTMLElement>>(
function selectAll<Selector extends string, Selected extends Element = ParseSelector<Selector, HTMLElement>>(
selectors: Selector | Selector[],
baseElements?: BaseElements
): TElement[];
function selectAll<TElement extends Element = HTMLElement>(
): Selected[];
function selectAll<Selected extends Element = HTMLElement>(
selectors: string | string[],
baseElements?: BaseElements
): TElement[];
function selectAll<TElement extends Element>(
): Selected[];
function selectAll<Selected extends Element>(
selectors: string | string[],
baseElements?: BaseElements
): TElement[] {
baseElements?: BaseElements,
): Selected[] {
// Shortcut with specified-but-null baseElements
if (arguments.length === 2 && !baseElements) {
return [];
}

// Can be: select.all('selectors') or select.all('selectors', singleElementOrDocument)
if (!baseElements || isQueryable(baseElements)) {
const elements = (baseElements ?? document).querySelectorAll<TElement>(String(selectors));
const elements = (baseElements ?? document).querySelectorAll<Selected>(String(selectors));
return [...elements];
}

const queried = new Set<TElement>();
const queried = new Set<Selected>();
for (const baseElement of baseElements) {
for (const element of baseElement.querySelectorAll<TElement>(String(selectors))) {
for (const element of baseElement.querySelectorAll<Selected>(String(selectors))) {
queried.add(element);
}
}
Expand Down
2 changes: 1 addition & 1 deletion license
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) Federico Brigante Federico Brigante <[email protected]> (bfred.it)
Copyright (c) Federico Brigante Federico Brigante <[email protected]> (https://fregante.com)

Copyright (c) 2014 Azer Koçulu <[email protected]>

Expand Down
23 changes: 14 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@
"selector"
],
"repository": "fregante/select-dom",
"funding": "https://github.com/sponsors/fregante",
"license": "MIT",
"author": "Federico Brigante <[email protected]> (https://fregante.com)",
"type": "module",
"main": "index.js",
"module": "index.js",
"exports": "./index.js",
"main": "./index.js",
"types": "./index.d.ts",
"files": [
"index.js",
"index.d.ts"
Expand All @@ -35,16 +37,19 @@
]
},
"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"
}
}
1 change: 0 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,3 @@ select.all('.foo', [baseElement1, baseElement2]);

- [delegate-it](https://github.com/fregante/delegate-it) - DOM event delegation, in <1KB.
- [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.
8 changes: 0 additions & 8 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
{
"extends": "@sindresorhus/tsconfig",
"compilerOptions": {
"target": "es2015",
"module": "es2015",
"lib": [
"dom",
"DOM.Iterable"
]
},
"files": [
"index.ts"
]
Expand Down

0 comments on commit a475ba4

Please sign in to comment.