specificity
Advanced tools
Comparing version 0.1.3 to 0.1.4
{ | ||
"name" : "specificity", | ||
"version" : "0.1.3", | ||
"version" : "0.1.4", | ||
"description" : "Calculate the specificity of a CSS selector", | ||
@@ -26,4 +26,4 @@ "keywords" : ["CSS", "specificity"], | ||
"devDependencies": { | ||
"mocha": "1.3.x" | ||
"mocha": "1.11.x" | ||
} | ||
} |
# Specificity Calculator | ||
A JavaScript module for calculating the [specificity of CSS selectors](http://www.w3.org/TR/css3-selectors/#specificity). | ||
A JavaScript module for calculating 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. | ||
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. Specificity Calculator doesn’t support [CSS character escape sequences](http://mathiasbynens.be/notes/css-escapes). | ||
## Front-end usage | ||
@@ -55,2 +58,7 @@ | ||
*/ | ||
``` | ||
``` | ||
## Testing | ||
To test this package, install dependencies: `npm install` | ||
Run: `npm test` |
@@ -48,3 +48,6 @@ /** | ||
classRegex = /(\.[^\s\+>~\.\[:]+)/g, | ||
pseudoElementRegex = /(::[^\s\+>~\.\[:]+|:first-line|:first-letter|:before|:after)/g, | ||
pseudoElementRegex = /(::[^\s\+>~\.\[:]+|:first-line|:first-letter|:before|:after)/gi, | ||
// A regex for pseudo classes with brackets - :nth-child(), :nth-last-child(), :nth-of-type(), :nth-last-type(), :lang() | ||
pseudoClassWithBracketsRegex = /(:[\w-]+\([^\)]*\))/gi, | ||
// A regex for other pseudo classes, which don't have brackets | ||
pseudoClassRegex = /(:[^\s\+>~\.\[:]+)/g, | ||
@@ -110,2 +113,3 @@ elementRegex = /([^\s\+>~\.\[:]+)/g; | ||
// Add pseudo-class selectors to parts collection (type b) | ||
findMatch(pseudoClassWithBracketsRegex, 'b'); | ||
findMatch(pseudoClassRegex, 'b'); | ||
@@ -112,0 +116,0 @@ |
var specificity = require('../'), | ||
assert = require('assert'), | ||
tests; | ||
tests, | ||
testSelector; | ||
@@ -19,5 +20,26 @@ tests = [ | ||
{ selector: 'p.message', expected: '0,0,1,1' }, | ||
{ selector: 'p', expected: '0,0,0,1' } | ||
{ selector: 'p', expected: '0,0,0,1' }, | ||
// Test pseudo-element with uppercase letters | ||
{ selector: 'li:bEfoRE', expected: '0,0,0,2' }, | ||
// Pseudo-class tests | ||
{ selector: 'li:first-child+p', expected: '0,0,1,2'}, | ||
{ selector: 'li:nth-child(even)+p', expected: '0,0,1,2'}, | ||
{ selector: 'li:nth-child(2n+1)+p', expected: '0,0,1,2'}, | ||
{ selector: 'li:nth-child( 2n + 1 )+p', expected: '0,0,1,2'}, | ||
{ selector: 'li:nth-child(2n-1)+p', expected: '0,0,1,2'}, | ||
{ selector: 'li:nth-child(2n-1) p', expected: '0,0,1,2'}, | ||
{ selector: ':lang(nl-be)', expected: '0,0,1,0'} | ||
]; | ||
testSelector = function(test) { | ||
describe('#calculate("' + test.selector + '")', function() { | ||
it ('should return a specificity of "' + test.expected + '"', function() { | ||
var result = specificity.calculate(test.selector); | ||
assert.equal(result[0].specificity, test.expected); | ||
}); | ||
}); | ||
}; | ||
describe('specificity', function() { | ||
@@ -27,9 +49,4 @@ var i, len, test; | ||
test = tests[i]; | ||
describe('#calculate("' + test.selector + '")', function() { | ||
it ('should return a specificity of "' + test.expected + '"', function() { | ||
var result = specificity.calculate(test.selector); | ||
assert.equal(test.expected, result[0].specificity); | ||
}); | ||
}); | ||
testSelector(test); | ||
} | ||
}); |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Non-existent author
Supply chain riskThe package was published by an npm account that no longer exists.
Found 1 instance in 1 package
9344
170
64
0
1