Socket
Socket
Sign inDemoInstall

analyze-css

Package Overview
Dependencies
Maintainers
1
Versions
195
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

analyze-css - npm Package Compare versions

Comparing version 0.4.1 to 0.5.0

examples/_reset.scss

24

lib/index.js

@@ -9,2 +9,3 @@ /**

fs = require('fs'),
preprocessors = new (require('./preprocessors'))(),
slickParse = require('slick').parse,

@@ -22,2 +23,5 @@ VERSION = require('./../package').version;

this.options = options;
debug('opts: %j', this.options);
if (typeof css !== 'string') {

@@ -28,3 +32,18 @@ callback(new Error('css parameter passed is not a string!'), null);

// preprocess the CSS (issue #3)
if (typeof options.preprocessor === 'string') {
debug('Using "%s" preprocessor', options.preprocessor);
var preprocessor = preprocessors.get(options.preprocessor);
try {
css = preprocessor.process(css, options);
}
catch(ex) {
throw new Error('Preprocessing failed: ' + ex);
}
debug('Preprocessing completed');
}
res = this.analyze(css);

@@ -219,2 +238,7 @@

break;
// {"type":"import","import":"url('/css/styles.css')"}
case 'import':
this.emit('import', rule.import);
break;
}

@@ -221,0 +245,0 @@ }, this);

15

lib/runner.js

@@ -13,2 +13,3 @@ /**

analyzer = require('./index'),
preprocessors = new (require('./preprocessors'))(),
url = require('url');

@@ -52,4 +53,8 @@

// call CommonJS module
var analyzerOpts = {
preprocessor: false
};
function analyze(css) {
new analyzer(css, callback);
new analyzer(css, analyzerOpts, callback);
}

@@ -86,2 +91,10 @@

else {
// find the matching preprocessor and use it
if (analyzerOpts.preprocessor === false) {
analyzerOpts.preprocessor = preprocessors.findMatchingByFileName(options.file);
}
// pass the name of the file being analyzed
analyzerOpts.file = options.file;
analyze(css);

@@ -88,0 +101,0 @@ }

8

package.json
{
"name": "analyze-css",
"version": "0.4.1",
"version": "0.5.0",
"author": "Maciej Brencz <maciej.brencz@gmail.com> (https://github.com/macbre)",

@@ -26,2 +26,4 @@ "description": "CSS selectors complexity and performance analyzer",

"fast-stats": "0.0.x",
"glob": "^4.0.5",
"node-sass": "^0.9.3",
"optimist": "0.6.x",

@@ -34,2 +36,3 @@ "slick": "~1.12.1",

"glob": "~4.0.5",
"istanbul": "^0.3.0",
"jshint": "~2.5.2",

@@ -42,3 +45,4 @@ "mocha": "~1.21.3"

"test": "mocha -R spec",
"lint": "jshint --verbose bin/ lib/ rules/ test/"
"lint": "jshint --verbose bin/ lib/ rules/ test/",
"coverage": "istanbul cover _mocha -- -R spec"
},

@@ -45,0 +49,0 @@ "jshintConfig": {

@@ -49,2 +49,12 @@ analyze-css

### [grunt task](https://www.npmjs.org/package/grunt-contrib-analyze-css)
> Created by @DeuxHuitHuit
```
npm i grunt-contrib-analyze-css
```
It uses configurable threshold and compares the analyze-css result with it.
### Results

@@ -54,3 +64,3 @@

{
"generator": "analyze-css v0.3.0",
"generator": "analyze-css v0.4.1",
"metrics": {

@@ -67,2 +77,3 @@ "base64Length": 9308,

"oldIEFixes": 51,
"imports": 0,
"importants": 3,

@@ -109,2 +120,3 @@ "mediaQueries": 0,

* **oldIEFixes**: number of fixes for old versions of Internet Explorer (e.g. ``* html .foo {}`` and ``.foo { *zoom: 1 }``, [read](http://blogs.msdn.com/b/ie/archive/2005/09/02/460115.aspx) [more](http://www.impressivewebs.com/ie7-ie8-css-hacks/))
* **imports** number of ``@import`` rules
* **importants**: number of properties with value forced by ``!important``

@@ -111,0 +123,0 @@ * **mediaQueries**: number of media queries (e.g. ``@media screen and (min-width: 1370px)``)

@@ -7,4 +7,6 @@ 'use strict';

analyzer.on('selector', function(rule, selector, expressions) {
var noExpressions = expressions.length;
// check more complex selectors only
if (expressions.length < 2) {
if (noExpressions < 2) {
return;

@@ -14,2 +16,3 @@ }

var firstTag = expressions[0].tag,
lastTag = expressions[noExpressions-1].tag,
isDescendantCombinator = (expressions[1].combinator === '>'),

@@ -22,2 +25,6 @@ isRedundant = false;

}
// matches html.modal-popup-mode body (issue #44)
else if (firstTag === 'html' && lastTag === 'body' && noExpressions === 2) {
isRedundant = false;
}
// matches "body .foo", but not "body > .bar' nor "body.foo .bar"

@@ -24,0 +31,0 @@ else if (firstTag === 'body' && !isDescendantCombinator && !expressions[0].classList) {

@@ -20,3 +20,3 @@ /*global describe, it */

it('should emit "' + metric + '" metric with a valid value - #' + (testId + 1), function() {
assert.strictEqual(metricsActual[metric], metricsExpected[metric]);
assert.strictEqual(metricsActual[metric], metricsExpected[metric], "Testing metric against: " + test.css);
});

@@ -23,0 +23,0 @@ });

@@ -49,3 +49,9 @@ exports.tests = [

}
},
{
css: 'html.modal-popup-mode body {}',
metrics: {
redundantBodySelectors: 0
}
}
];

Sorry, the diff of this file is not supported yet

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