2.0.5 • Published 4 years ago

style-selector v2.0.5

Weekly downloads
805
License
MIT
Repository
github
Last release
4 years ago

style-selector Build Status Coverage Status

NPM

CSS selector constructor

Uses Slick to parse and tokenize the CSS selectors.

Install

Install with npm

npm install --save style-selector

Usage v2

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

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 library.

License

MIT

2.0.5

4 years ago

2.0.4

5 years ago

2.0.3

6 years ago

2.0.2

6 years ago

2.0.1

8 years ago

2.0.0

8 years ago

1.0.3

8 years ago

1.0.2

8 years ago

1.0.1

9 years ago

1.0.0

9 years ago