From 1de8ec2cd9e000429e2bcf38f99c3807a88dfbf1 Mon Sep 17 00:00:00 2001 From: weyusi Date: Tue, 23 Apr 2019 12:25:17 +0930 Subject: [PATCH] refactor: use nanomatch.some() .some supports string and array patterns, so no need for loop. https://github.com/micromatch/nanomatch#some --- lib/filter.js | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/lib/filter.js b/lib/filter.js index f934cff..53f9114 100644 --- a/lib/filter.js +++ b/lib/filter.js @@ -15,12 +15,10 @@ function logicHtml (str, data) { let path = data.path let exclude = options.exclude - if (exclude && !Array.isArray(exclude)) exclude = [exclude] + // Return if a path matches exclusion pattern if (path && exclude && exclude.length) { - for (let i = 0, len = exclude.length; i < len; i++) { - if (nanomatch.isMatch(path, exclude[i], { matchBase: true })) return str - } + if (nanomatch.some(path, exclude, { matchBase: true })) return str } let result = Htmlminifier(str, options) @@ -40,12 +38,10 @@ function logicCss (str, data) { let path = data.path let exclude = options.exclude - if (exclude && !Array.isArray(exclude)) exclude = [exclude] + // Return if a path matches exclusion pattern if (path && exclude && exclude.length) { - for (let i = 0, len = exclude.length; i < len; i++) { - if (nanomatch.isMatch(path, exclude[i], { matchBase: true })) return str - } + if (nanomatch.some(path, exclude, { matchBase: true })) return str } return new Promise(function (resolve, reject) { @@ -69,12 +65,10 @@ function logicJs (str, data) { let path = data.path let exclude = options.exclude - if (exclude && !Array.isArray(exclude)) exclude = [exclude] + // Return if a path matches exclusion pattern if (path && exclude && exclude.length) { - for (let i = 0, len = exclude.length; i < len; i++) { - if (nanomatch.isMatch(path, exclude[i], { matchBase: true })) return str - } + if (nanomatch.some(path, exclude, { matchBase: true })) return str } // Terser doesn't like unsupported options