MCPcopy Create free account
hub / github.com/purifycss/purifycss / purify

Function purify

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

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected