瀏覽代碼

removed duplicate code

Gildas 7 年之前
父節點
當前提交
ccf2c86ec4
共有 1 個文件被更改,包括 12 次插入4 次删除
  1. 12 4
      lib/single-file/css-fonts-minifier.js

+ 12 - 4
lib/single-file/css-fonts-minifier.js

@@ -337,27 +337,35 @@ this.fontsMinifier = this.fontsMinifier || (() => {
 		if (fontWeight >= 400 && fontWeight <= 500) {
 			foundWeight = fontWeights.find(weight => weight >= fontWeight && weight <= 500);
 			if (!foundWeight) {
-				foundWeight = fontWeights.slice().reverse().find(weight => weight < fontWeight);
+				foundWeight = findDescendingFontWeight(fontWeight, fontWeights);
 			}
 			if (!foundWeight) {
-				foundWeight = fontWeights.find(weight => weight > fontWeight);
+				foundWeight = findAscendingFontWeight(fontWeight, fontWeights);
 			}
 		}
 		if (fontWeight < 400) {
 			foundWeight = fontWeights.slice().reverse().find(weight => weight <= fontWeight);
 			if (!foundWeight) {
-				foundWeight = fontWeights.find(weight => weight > fontWeight);
+				foundWeight = findAscendingFontWeight(fontWeight, fontWeights);
 			}
 		}
 		if (fontWeight > 500) {
 			foundWeight = fontWeights.find(weight => weight >= fontWeight);
 			if (!foundWeight) {
-				foundWeight = fontWeights.slice().reverse().find(weight => weight < fontWeight);
+				foundWeight = findDescendingFontWeight(fontWeight, fontWeights);
 			}
 		}
 		return foundWeight;
 	}
 
+	function findDescendingFontWeight(fontWeight, fontWeights) {
+		return fontWeights.slice().reverse().find(weight => weight < fontWeight);
+	}
+
+	function findAscendingFontWeight(fontWeight, fontWeights) {
+		return fontWeights.find(weight => weight > fontWeight);
+	}
+
 	function getPseudoElementsContent(doc, rules) {
 		if (rules) {
 			return Array.from(rules).map(rule => {