# selector-tokenizer

> Module for fast css selector tokenization from string

Latest version **0.9.5** (published 2016-12-26) · MIT license · 0 weekly downloads

## Install

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

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.9.5 |
| Published | 2016-12-26 |
| First published | 2016-12-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Eugene Ford |
| Maintainers | eugeneford |
| Keywords | css, token, tokenize, tokenizer, string, selector, grammar, parser, lexer, spec |

## Links

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

## Alternatives

- [babylon](https://npm.io/package/babylon.md) — 5.1M weekly downloads
- [csscolorparser](https://npm.io/package/csscolorparser.md) — 3.7M weekly downloads
- [expr-eval-fork](https://npm.io/package/expr-eval-fork.md) — 1.5M weekly downloads
- [@leeoniya/ufuzzy](https://npm.io/package/@leeoniya/ufuzzy.md) — 247.7K weekly downloads
- [xml-parser](https://npm.io/package/xml-parser.md) — 78.4K weekly downloads

## Recent versions

- 0.9.5 (latest) — 2016-12-26
- 0.9.3 — 2016-12-24
- 0.9.2 — 2016-12-23
- 0.9.1 — 2016-12-23
- 0.9.0 — 2016-12-23

## README

# Selector Tokenizer
Module for fast css selector tokenization from string

[![NPM](https://nodei.co/npm/selector-tokenizer.png?downloads=true)](https://nodei.co/npm/selector-tokenizer/)

## What does this repo about

The selector tokenizer allows to break a css selector string into set of tokens. 

The tokenization method is based on a set of lexer grammars rules. The full list of available token types is next:

 * \<type-selector> - for basic type selectors eg. "article", "h1", "p" etc.
 * \<class-selector> - for basic class selectors eg. ".button", ".post", etc.
 * \<universal-selector> - for basic universal selector "*"
 * \<attribute-selector> - for basic attribute selectors eg. "[attr]", "[attr=val]", "[attr^=val]" etc.
 * \<pseudo-selector> - for pseudo-element and pseudo-class-selectors eg. ":first-child", "::first-letter"
 * \<descendat-selector> - for selector's descendant combinator " "
 * \<adjacent-sibling-selector> - for selector's adjacent sibling combinator "+"
 * \<general-sibling-selector> - for selector's general sibling combinator "~"
 * \<child-selector> - for selector's child combinator ">"
 * \<scope-start> - to match the start of tokenization scopes ()
 * \<scope-end> - to match the end of tokenization scopes ()

## How to use

### Basic Example
The following example illustrates the principle the SelectorTokenizer.tokenize method
```javascript
tokenizer = new SelectorTokenizer();
tokens = tokenizer.tokenize(".page main");
tokens   //=> [{type: "class", value: ".page"}, {type: "descendant", value: " "}, {type: "type", value: "main"}]
```

### Methods
SelectorTokenizer has a set of different methods you can find to be useful.

##### tokenize(selectorText);
Create a set of tokens from target selector string
```javascript
tokenizer = new SelectorTokenizer();
tokens = tokenizer.tokenize(".page main");
tokens   //=> [{type: "class", value: ".page"}, {type: "descendant", value: " "}, {type: "type", value: "main"}]
```

##### tokenAt(selectorText, startIndex);
Read a grammar token from a string starting at target position. 

```javascript
tokenizer = new SelectorTokenizer();
token = tokenizer.tokenAt(".classname", 0);
token   //=> { type: "class", value: ".classname" }
```

### Building
```javascript
npm install
```

### Development and Testing
* `npm run gulp` will launch dist building 
* `npm run watch` will launch a watcher for dist building 
* `npm run test` will launch unit-test building 
* `npm run test-watch` will launch a watcher for unit-test building 

## License

It's all about MIT stuff. (C) 2017 Eugene Ford

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