MCPcopy Index your code
hub / github.com/purifycss/purifycss / purify

Function purify

lib/purifycss.js:997–1035  ·  view source on GitHub ↗
(searchThrough, css, options, callback)

Source from the content-addressed store, hash-verified

995};
996
997var purify = function purify(searchThrough, css, options, callback) {
998 if (typeof options === "function") {
999 callback = options;
1000 options = {};
1001 }
1002 options = getOptions(options);
1003 var cssString = FileUtil.filesToSource(css, "css"),
1004 content = FileUtil.filesToSource(searchThrough, "content");
1005 PrintUtil.startLog(minify(cssString).length);
1006 var wordsInContent = getAllWordsInContent(content),
1007 selectorFilter = new SelectorFilter(wordsInContent, options.whitelist),
1008 tree = new CssTreeWalker(cssString, [selectorFilter]);
1009 tree.beginReading();
1010 var source = tree.toString();
1011
1012 source = options.minify ? minify(source, options.cleanCssOptions) : source;
1013
1014 // Option info = true
1015 if (options.info) {
1016 if (options.minify) {
1017 PrintUtil.printInfo(source.length);
1018 } else {
1019 PrintUtil.printInfo(minify(source, options.cleanCssOptions).length);
1020 }
1021 }
1022
1023 // Option rejected = true
1024 if (options.rejected && selectorFilter.rejectedSelectors.length) {
1025 PrintUtil.printRejected(selectorFilter.rejectedSelectors);
1026 }
1027
1028 if (options.output) {
1029 fs.writeFile(options.output, source, function (err) {
1030 if (err) return err;
1031 });
1032 } else {
1033 return callback ? callback(source) : source;
1034 }
1035};
1036
1037module.exports = purify;

Callers 1

index.jsFile · 0.50

Calls 5

beginReadingMethod · 0.95
toStringMethod · 0.95
getOptionsFunction · 0.70
minifyFunction · 0.70
getAllWordsInContentFunction · 0.70

Tested by

no test coverage detected