Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/keupoz/strict-queryselector
A simple typeguard wrapper around document.querySelector for TypeScript
https://github.com/keupoz/strict-queryselector
Last synced: about 1 month ago
JSON representation
A simple typeguard wrapper around document.querySelector for TypeScript
- Host: GitHub
- URL: https://github.com/keupoz/strict-queryselector
- Owner: keupoz
- License: mit
- Created: 2020-06-29T05:39:04.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2020-07-10T15:44:40.000Z (over 4 years ago)
- Last Synced: 2024-09-21T07:28:53.395Z (about 2 months ago)
- Language: TypeScript
- Size: 15.6 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# strict-queryselector
## Usage
```typescript
import { querySelector } from "@keupoz/strict-queryselector";// Same examples applies to querySelectorAll
// Gets body element with type of HTMLBodyElement
const body = querySelector("body", HTMLBodyElement);// Throws TypeError as body element is not instance of HTMLDivElement
const bodyDiv = querySelector("body", HTMLDivElement);// Throws Error if element doesn't exist
// If it exists, checks if it's instance of specified type
const meaningOfLife = querySelector(".life-meaning", HTMLDivElement);
```### Wrappers
There are wrapper functions that allows to wrap the type guard around custom element. And they return the same function as regular `querySelector`.
```typescript
const bodyQuerySelector = wrapQuerySelector(document.body);
```