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

uncss

Package Overview
Dependencies
Maintainers
1
Versions
60
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

uncss - npm Package Compare versions

Comparing version 0.3.0-0 to 0.4.0-0

69

lib/uncss.js

@@ -5,2 +5,3 @@ /*jslint node: true */

var css = require('css'),
csso = require('csso'),
htmlparser = require('htmlparser2'),

@@ -18,3 +19,3 @@ path = require('path'),

var i, node;
if (!memo) {
if (memo === undefined) {
memo = [];

@@ -51,2 +52,8 @@ }

/* If 'files' is a string, it should represent an HTML page. */
if (typeof files === 'string') {
doms = [files];
} else {
doms = utility.mapReadFiles(files);
}
if (typeof opt === 'function') {

@@ -65,9 +72,2 @@ /* There were no options,

/* If 'files' is a string, it should represent an HTML page. */
if (typeof files === 'string') {
doms = [files];
} else {
doms = utility.mapReadFiles(files);
}
handler = new htmlparser.DomHandler();

@@ -92,30 +92,41 @@ parser = new htmlparser.Parser(handler);

css_files = doms.map(function (html) { return extract_css(html); });
/* Now we have:
* files = ['some_file.html', 'some_other_file.html']
* css_files = [['relative_css_path.css', ...], ['maybe_a_duplicate.css', ...]]
* We need to - make the paths relative to the current one,
* - flatten the array,
* - remove duplicates
*/
css_files = css_files.map(function (arr, i) {
return arr.map(function (el) {
return path.join(path.dirname(files[i]), el);
if (css_files[0].length === 0) {
/* Could not extract a css file */
callback('');
} else {
/* Now we have:
* files = ['some_file.html', 'some_other_file.html']
* css_files = [['relative_css_path.css', ...], ['maybe_a_duplicate.css', ...]]
* We need to - make the paths relative to the current one,
* - flatten the array,
* - remove duplicates
*/
css_files = css_files.map(function (arr, i) {
return arr.map(function (el) {
return path.join(path.dirname(files[i]), el);
});
});
});
css_files = css_files.concat.apply([], css_files);
css_files = css_files.filter(function (e, i, arr) {
return arr.lastIndexOf(e) === i;
});
css_files = css_files.concat.apply([], css_files);
css_files = css_files.filter(function (e, i, arr) {
return arr.lastIndexOf(e) === i;
});
css_files = utility.mapReadFiles(css_files);
parsed_css = css.parse(css_files.join('\n'));
css_files = utility.mapReadFiles(css_files);
parsed_css = css.parse(css_files.join('\n'));
doms = doms.concat.apply([], doms);
used_css = { stylesheet: utility.filterUnusedRules(doms, parsed_css.stylesheet) };
doms = doms.concat.apply([], doms);
used_css = utility.filterUnusedRules(doms, parsed_css.stylesheet);
used_css = css.stringify(used_css, { compress: options.compress || false });
callback(used_css);
used_css = css.stringify(used_css, { compress: options.compress || false });
/* Minify? */
if (options.compress) {
used_css = csso.justDoIt(used_css);
}
callback(used_css);
}
}
module.exports = uncss;

@@ -57,3 +57,3 @@ /*jslint node: true, plusplus: true, stupid: true */

} else if (rule.media) {
rule.rules = filterUnusedRules(dom, { rules: rule.rules }).rules;
rule.rules = filterUnusedRules(dom, { rules: rule.rules }).stylesheet.rules;
}

@@ -72,3 +72,3 @@ });

return { rules: rules };
return { stylesheet: { rules: rules } };
}

@@ -75,0 +75,0 @@

{
"name": "uncss",
"version": "0.3.0-0",
"version": "0.4.0-0",
"description": "Remove unused CSS styles",

@@ -31,2 +31,3 @@ "main": "lib/uncss.js",

"css": ">= 1.1.0",
"csso": ">= 1.3.7",
"htmlparser2": ">= 3.0.5",

@@ -33,0 +34,0 @@ "soupselect": ">= 0.2.0"

@@ -48,3 +48,4 @@ # UnCSS #

## TODO: ##
- Add some better minification
- See TODO comments
- Switch to a newer css selector engine
- See TODO comments
- Feedback appreciated!
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