UNPKG

656 BJavaScriptView Raw
1"use strict";
2
3/**
4 * Detect not minified CSS
5 *
6 * @param { import("../lib/css-analyzer") } analyzer
7 */
8function rule(analyzer) {
9 analyzer.setMetric("notMinified");
10
11 /**
12 * A simple CSS minification detector
13 *
14 * @param {string} css
15 * @return {boolean}
16 */
17 function isMinified(css) {
18 // analyze the first 1024 characters
19 css = css.trim().substring(0, 1024);
20
21 // there should be no newline in minified file
22 return /\n/.test(css) === false;
23 }
24
25 analyzer.on("css", (css) => {
26 analyzer.setMetric("notMinified", isMinified(css) ? 0 : 1);
27 });
28}
29
30rule.description = "Reports not minified CSS ";
31module.exports = rule;