.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / specificity / readme.md
1 # Specificity Calculator
2
3 A JavaScript module for calculating and comparing the [specificity of CSS selectors](http://www.w3.org/TR/css3-selectors/#specificity). The module is used on the [Specificity Calculator](http://specificity.keegan.st/) website.
4
5 Specificity Calculator is built for CSS Selectors Level 3. Specificity Calculator isn’t a CSS validator. If you enter invalid selectors it will return incorrect results. For example, the [negation pseudo-class](http://www.w3.org/TR/css3-selectors/#negation) may only take a simple selector as an argument. Using a psuedo-element or combinator as an argument for `:not()` is invalid CSS3 so Specificity Calculator will return incorrect results.
6
7
8 ## Front-end usage
9
10 ```js
11 SPECIFICITY.calculate('ul#nav li.active a');   // [{ specificity: '0,1,1,3' }]
12 ```
13
14 ## Node.js usage
15
16 ```js
17 var specificity = require('specificity');
18 specificity.calculate('ul#nav li.active a');   // [{ specificity: '0,1,1,3' }]
19 ```
20
21 ## Passing in multiple selectors
22
23 You can use comma separation to pass in multiple selectors:
24
25 ```js
26 SPECIFICITY.calculate('ul#nav li.active a, body.ie7 .col_3 h2 ~ h2');   // [{ specificity: '0,1,1,3' }, { specificity: '0,0,2,3' }]
27 ```
28
29 ## Return values
30
31 The `specificity.calculate` function returns an array containing a result object for each selector input. Each result object has the following properties:
32
33   * `selector`: the input
34   * `specificity`: the result as a string e.g. `0,1,0,0`
35   * `specificityArray`: the result as an array of numbers e.g. `[0, 1, 0, 0]`
36   * `parts`: array with details about each part of the selector that counts towards the specificity
37
38 ## Example
39
40 ```js
41 var specificity = require('../'),
42     result = specificity.calculate('ul#nav li.active a');
43
44 console.log(result);
45
46 /* result =
47 [ {
48     selector: 'ul#nav li.active a',
49     specificity: '0,1,1,3',
50     specificityArray: [0, 1, 1, 3],
51     parts: [
52       { selector: 'ul', type: 'c', index: 0, length: 2 },
53       { selector: '#nav', type: 'a', index: 2, length: 4 },
54       { selector: 'li', type: 'c', index: 5, length: 2 },
55       { selector: '.active', type: 'b', index: 8, length: 7 },
56       { selector: 'a', type: 'c', index: 13, length: 1 }
57     ]
58 } ]
59 */
60 ```
61
62 ## Comparing two selectors
63
64 Specificity Calculator also exposes a `compare` function. This function accepts two CSS selectors or specificity arrays, `a` and `b`.
65
66   * It returns `-1` if `a` has a lower specificity than `b`
67   * It returns `1` if `a` has a higher specificity than `b`
68   * It returns `0` if `a` has the same specificity than `b`
69
70 ```js
71 SPECIFICITY.compare('div', '.active');         // -1
72 SPECIFICITY.compare('#main', 'div');           // 1
73 SPECIFICITY.compare('span', 'div');            // 0
74 SPECIFICITY.compare('span', [0,0,0,1]);        // 0
75 SPECIFICITY.compare('#main > div', [0,1,0,1]); // 0
76 ```
77
78 ## Ordering an array of selectors by specificity
79
80 You can pass the `SPECIFICITY.compare` function to `Array.prototype.sort` to sort an array of CSS selectors by specificity.
81
82 ```js
83 ['#main', 'p', '.active'].sort(SPECIFICITY.compare);   // ['p', '.active', '#main']
84 ```
85
86 ## Command-line usage
87
88 Run `npm install specificity` to install the module locally, or `npm install -g specificity` for global installation. You may need to elevate permissions by `sudo` for the latter. Run `specificity` without arguments to learn about its usage:
89
90 ```bash
91 $ specificity
92 Usage: specificity <selector>
93 Computes specificity of a CSS selector.
94 ```
95
96 Pass a selector as the first argument to get its specificity computed:
97
98 ```bash
99 $ specificity "ul#nav li.active a"
100 0,1,1,3
101 ```
102
103 ## Testing
104
105 To install dependencies, run: `npm install`
106
107 Then to test, run: `npm test`