From 55ecc53f23e4ba787fce051a2bcd9d863aacc1f6 Mon Sep 17 00:00:00 2001 From: Kael Zhang Date: Fri, 22 May 2020 23:14:52 +0800 Subject: [PATCH] 5.1.6: better algo --- index.js | 13 +++++++------ package.json | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index f48b1cc..9dcee20 100644 --- a/index.js +++ b/index.js @@ -6,6 +6,7 @@ function makeArray (subject) { } const EMPTY = '' +const SPACE = ' ' const ESCAPE = '\\' const REGEX_TEST_BLANK_LINE = /^\s+$/ const REGEX_REPLACE_LEADING_EXCAPED_EXCLAMATION = /^\\!/ @@ -41,10 +42,10 @@ const sanitizeRange = range => range.replace( ) // See fixtures #59 -const cleanRangeBackSlash = slashes => slashes.slice( - 0, - parseInt(slashes.length / 2, 10) * 2 -) +const cleanRangeBackSlash = slashes => { + const {length} = slashes + return slashes.slice(0, length - length % 2) +} // > If the pattern ends with a slash, // > it is removed for the purpose of the following description, @@ -66,14 +67,14 @@ const REPLACERS = [ // (a \ ) -> (a ) /\\?\s+$/, match => match.indexOf('\\') === 0 - ? ' ' + ? SPACE : EMPTY ], // replace (\ ) with ' ' [ /\\\s/g, - () => ' ' + () => SPACE ], // Escape metacharacters diff --git a/package.json b/package.json index 92413a4..cffe0c4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ignore", - "version": "5.1.5", + "version": "5.1.6", "description": "Ignore is a manager and filter for .gitignore rules, the one used by eslint, gitbook and many others.", "files": [ "legacy.js",