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

Function purify

src/purifycss.js:30–68  ·  view source on GitHub ↗
(searchThrough, css, options, callback)

Source from the content-addressed store, hash-verified

28 new CleanCss(options).minify(cssSource).styles
29
30const purify = (searchThrough, css, options, callback) => {
31 if (typeof options === "function") {
32 callback = options
33 options = {}
34 }
35 options = getOptions(options)
36 let cssString = FileUtil.filesToSource(css, "css"),
37 content = FileUtil.filesToSource(searchThrough, "content")
38 PrintUtil.startLog(minify(cssString).length)
39 let wordsInContent = getAllWordsInContent(content),
40 selectorFilter = new SelectorFilter(wordsInContent, options.whitelist),
41 tree = new CssTreeWalker(cssString, [selectorFilter])
42 tree.beginReading()
43 let source = tree.toString()
44
45 source = options.minify ? minify(source, options.cleanCssOptions) : source
46
47 // Option info = true
48 if (options.info) {
49 if (options.minify) {
50 PrintUtil.printInfo(source.length)
51 } else {
52 PrintUtil.printInfo(minify(source, options.cleanCssOptions).length)
53 }
54 }
55
56 // Option rejected = true
57 if (options.rejected && selectorFilter.rejectedSelectors.length) {
58 PrintUtil.printRejected(selectorFilter.rejectedSelectors)
59 }
60
61 if (options.output) {
62 fs.writeFile(options.output, source, err => {
63 if (err) return err
64 })
65 } else {
66 return callback ? callback(source) : source
67 }
68}
69
70export default purify

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected