https://github.com/matype/css-specificity
CSS selector specificity calculator
https://github.com/matype/css-specificity
Last synced: about 1 year ago
JSON representation
CSS selector specificity calculator
- Host: GitHub
- URL: https://github.com/matype/css-specificity
- Owner: matype
- License: other
- Created: 2014-11-24T09:22:02.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2014-11-24T16:13:40.000Z (over 11 years ago)
- Last Synced: 2025-05-18T22:35:34.604Z (about 1 year ago)
- Language: JavaScript
- Size: 137 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.markdown
- License: LICENSE
Awesome Lists containing this project
README
# css-specificity [](https://travis-ci.org/morishitter/css-specificity)
CSS3 selector specificity calculator.
css-specificity is wrapper module of [specimen](https://github.com/brettstimmerman/specimen).
## Installation
```shell
$ npm install css-specificity
```
## Example
```javascript
var specificity = require('css-specificity')
var calc = specificity.calc('.class, p.sel:after')
var winner = specificity.vs('.class', 'p.sel:after')
console.log(calc)
/*
[
{
'selector': '.class',
'specificity': [0, 0, 1, 0],
'a': 0,
'b': 1,
'c': 0
},
{
'selector': 'p.sel:after',
'specificity': [0, 0, 1, 2],
'a': 0,
'b': 1,
'c': 2
}
]
*/
console.log(winner)
// 'p.sel:after'
```
## API
### `specificity.calc(selector)`
return caluculation result.
### `specificity.vs(selector1, selector2)`
return selector has higher specificity.
## License
The MIT License (MIT)
Copyright (c) 2014 Masaaki Morishita