An open API service indexing awesome lists of open source software.

https://github.com/lbenie/qselector

Aliases for querySelector & querySelectorAll
https://github.com/lbenie/qselector

browser dom javascript javascript-library node nodejs nodejs-modules query query-selector query-selector-all

Last synced: 3 months ago
JSON representation

Aliases for querySelector & querySelectorAll

Awesome Lists containing this project

README

        

# qselector

[![Build Status](https://travis-ci.org/lbenie/qselector.svg?branch=master)](https://travis-ci.org/lbenie/qselector)
[![Mutation testing badge](https://badge.stryker-mutator.io/github.com/lbenie/qselector/master)](https://stryker-mutator.github.io)
[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)
[![license](https://img.shields.io/github/license/lbenie/qselector.svg)](https://github.com/lbenie/qselector)
[![Known Vulnerabilities](https://snyk.io/test/github/lbenie/qselector/badge.svg?targetFile=package.json)](https://snyk.io/test/github/lbenie/qselector?targetFile=package.json)
[![npm](https://img.shields.io/npm/v/qselector.svg)](https://github.com/lbenie/qselector)
[![npm bundle size (minified)](https://img.shields.io/bundlephobia/min/qselector.svg)](https://github.com/lbenie/qselector)
[![npm bundle size (minified + gzip)](https://img.shields.io/bundlephobia/minzip/qselector.svg)](https://github.com/lbenie/qselector) [![Greenkeeper badge](https://badges.greenkeeper.io/lbenie/qselector.svg)](https://greenkeeper.io/)

qselector (query selector) is just a small package to create aliases for
`querySelector` and `querySelectorAll` to `$` and `$$` respectively.

## API

The api is pretty simple. Each functions receive a DOMElement and returns either
the node or a list of node.

**Example**

```html


s
t

u


```

**$(el, selector)**

Returns the first match of `selector` on `el` and its children

```js
let node = $('div');
/* node value


s
t

u


*/

node = $('span', '.test');
/* node value
s
*/
```

**$$(el, selector)**

Returns the list of all matches of `selector` on `el` and its children

```js
let node = $$('div');
/* node value
[div.test, div.retest]
*/

node = $$('.test', 'span');
/* node value
[span, span]
*/
```

## Installation

```bash
$ yarn add qselector
```

or

```bash
$ npm install qselector --save
```

### Usage

```node
const qselector = require('qselector/dist/cjs')
```

```ts
import qselector from 'qselector/dist/es2015')
```

## License

(MIT)

Copyright (c) 2018 Lucien Bénié

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.