Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

specificity

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

specificity - npm Package Compare versions

Comparing version 0.1.3 to 0.1.4

4

package.json
{
"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);
}
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc