# selector-lite

> DEPRECATED! It is merged into dom-lite! A small pure-JavaScript CSS selector engine

Latest version **23.1.0** (published 2023-01-22) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install selector-lite
pnpm add selector-lite
yarn add selector-lite
bun add selector-lite
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 23.1.0 |
| Published | 2023-01-22 |
| First published | 2015-02-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 3.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 5 |
| Author | Lauri Rooden |
| Maintainers | lauriro |
| Keywords | browser, css, selector, matches, closest, litejs |

## Links

- npm: https://www.npmjs.com/package/selector-lite
- Repository: https://github.com/litejs/selector-lite
- Homepage: https://github.com/litejs/selector-lite#readme
- Issues: https://github.com/litejs/selector-lite/issues
- npm.io page: https://npm.io/package/selector-lite

## Dependencies (1)

- [dom-lite](https://npm.io/package/dom-lite.md) 23.1.0

## Alternatives

- [style-dictionary](https://npm.io/package/style-dictionary.md) — 2.0M weekly downloads
- [postcss-merge-idents](https://npm.io/package/postcss-merge-idents.md) — 1.7M weekly downloads
- [@fontsource/noto-sans](https://npm.io/package/@fontsource/noto-sans.md) — 93.0K weekly downloads
- [uglifycss](https://npm.io/package/uglifycss.md) — 71.6K weekly downloads
- [mat4-interpolate](https://npm.io/package/mat4-interpolate.md) — 23.3K weekly downloads

## Recent versions

- 23.1.0 (latest) — 2023-01-22
- 22.10.1 — 2022-10-27
- 22.10.0 — 2022-10-27
- 20.2.0 — 2020-02-05
- 19.11.0 — 2019-11-28
- 0.1.1 — 2015-05-10
- 0.1.0 — 2015-02-19

## README

[3]: https://badgen.net/coveralls/c/github/litejs/selector-lite
[4]: https://coveralls.io/r/litejs/selector-lite
[5]: https://badgen.net/packagephobia/install/selector-lite
[6]: https://packagephobia.now.sh/result?p=selector-lite
[7]: https://badgen.net/badge/icon/Buy%20Me%20A%20Tea/orange?icon=kofi&label
[8]: https://www.buymeacoffee.com/lauriro


Selector lite &ndash; [![Coverage][3]][4] [![Size][5]][6] [![Buy Me A Tea][7]][8]
=============

## DEPRECATED! It is merged into dom-lite. Use `require('dom-lite/selector')`

A small pure-JavaScript CSS selector engine.

 - no library dependencies
 - CSS 3 Selector support
 - only 2KB minified and 1KB gzipped

Examples
--------

```javascript
var selector = require("selector-lite")

// Can be used to implement browser built-in functions.

function getElementById(id) {
    return selector.find(this, "#" + id, true)
}
function getElementsByTagName(tag) {
    return selector.find(this, tag)
}
function getElementsByClassName(sel) {
    return selector.find(this, "." + sel.replace(/\s+/g, "."))
}
function querySelector(sel) {
    return selector.find(this, sel, true)
}
function querySelectorAll(sel) {
    return selector.find(this, sel)
}
```

Methods
-------

 - selector.`find(node, selector, returnFirstMatch)` - Find matching elements like querySelector.
 - selector.`matches(node, selector)` - Returns a Boolean indicating whether or not
   the element would be selected by the specified selector string.
 - selector.`closest(selector)` - Returns the Element, descendant of this element
   (or this element itself), that is the closest ancestor of the elements
   selected by the selectors given in parameter.
 - selector.`next(selector)` - Retrieves the next sibling that matches selector.
 - selector.`prev(selector)` - Retrieves the preceding sibling that matches selector.


Custom selectors
----------------

Custom selector can be added to selector.selectorMap,
where method shortcuts are available (m->matches, c->closest, n->next, p->prev).

 - `_` - node.
 - `v` - part between `()` in `:nth-child(2n+1)`.
 - `a` and `b` can be used as temp variables.

```javascript
// Add `:input` selector
selector.selectorMap.input = "_.tagName=='INPUT'"

// Add `:val()` selector
selector.selectorMap.val = "_.value==v"
```

## Contributing

Follow [Coding Style Guidelines](https://github.com/litejs/litejs/wiki/Style-Guidelines)

Run tests

```
npm install
npm test
```

## External links

[GitHub repo](https://github.com/litejs/selector-lite) |
[npm package](https://npmjs.org/package/selector-lite) |
[DOM spec](https://dom.spec.whatwg.org/) |
[Selectors Level 3](http://www.w3.org/TR/selectors/) |
[Coveralls coverage](https://coveralls.io/github/litejs/selector-lite)  
[Buy Me A Tea][8]


## Licence

Copyright (c) 2015-2021 Lauri Rooden &lt;lauri@rooden.ee&gt;  
[The MIT License](http://lauri.rooden.ee/mit-license.txt)

---
_Source: https://npm.io/package/selector-lite · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
