https://github.com/jonkemp/style-selector
CSS selector constructor
https://github.com/jonkemp/style-selector
inline-css slick
Last synced: 2 months ago
JSON representation
CSS selector constructor
- Host: GitHub
- URL: https://github.com/jonkemp/style-selector
- Owner: jonkemp
- License: mit
- Created: 2015-01-21T01:17:41.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2020-10-09T02:00:51.000Z (over 5 years ago)
- Last Synced: 2025-02-19T21:38:56.222Z (about 1 year ago)
- Topics: inline-css, slick
- Language: JavaScript
- Size: 146 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# style-selector [](https://travis-ci.org/jonkemp/style-selector) [](https://coveralls.io/github/jonkemp/style-selector?branch=master)
[](https://nodei.co/npm/style-selector/)
> CSS selector constructor
Uses [Slick](https://github.com/subtleGradient/slick) to parse and tokenize the CSS selectors.
## Install
Install with [npm](https://npmjs.org/package/style-selector)
```
npm install --save style-selector
```
## Usage v2
```js
var selector = require('style-selector'),
bodySelector = selector('body', [ 0, 0, 0, 1 ]);
console.log(bodySelector); // { text: 'body', spec: [ 0, 0, 0, 1 ] }
console.log(bodySelector.parsed()); // { '0': { combinator: ' ', tag: 'body' }, length: 1 }
console.log(bodySelector.specificity()); // [ 0, 0, 0, 1 ]
```
## Usage v1
```js
var Selector = require('style-selector'),
bodySelector = new Selector('body', [ 0, 0, 0, 1 ]);
console.log(bodySelector); // { text: 'body', spec: [ 0, 0, 0, 1 ] }
console.log(bodySelector.parsed()); // { '0': { combinator: ' ', tag: 'body' }, length: 1 }
console.log(bodySelector.specificity()); // [ 0, 0, 0, 1 ]
```
## v2 API
### selector(text, spec)
CSS selector constructor
#### text
Type: `String`
Default: `none`
Selector text
#### spec
Type: `Array`
Default: `none`
Optional, precalculated specificity
### selector.parsed()
Get parsed selector
### selector.specificity()
Lazy specificity getter
## v1 API
### Selector(text, spec)
CSS selector constructor
#### text
Type: `String`
Default: `none`
Selector text
#### spec
Type: `Array`
Default: `none`
Optional, precalculated specificity
### Selector.prototype.parsed()
Get parsed selector
### Selector.prototype.specificity()
Lazy specificity getter
## Credit
The code for this module was originally taken from the [Juice](https://github.com/Automattic/juice) library.
## License
MIT