Comparing version 5.1.4 to 5.1.5
118
index.js
@@ -8,2 +8,4 @@ // A simple implementation of make-array | ||
const EMPTY = '' | ||
const ESCAPE = '\\' | ||
const REGEX_TEST_BLANK_LINE = /^\s+$/ | ||
@@ -39,5 +41,11 @@ const REGEX_REPLACE_LEADING_EXCAPED_EXCLAMATION = /^\\!/ | ||
// fatal for JavaScript regular expression, so eliminate it. | ||
: '' | ||
: EMPTY | ||
) | ||
// See fixtures #59 | ||
const cleanRangeBackSlash = slashes => slashes.slice( | ||
0, | ||
parseInt(slashes.length / 2, 10) * 2 | ||
) | ||
// > If the pattern ends with a slash, | ||
@@ -64,3 +72,3 @@ // > it is removed for the purpose of the following description, | ||
? ' ' | ||
: '' | ||
: EMPTY | ||
], | ||
@@ -92,3 +100,3 @@ | ||
[ | ||
/[\\^$.|*+(){]/g, | ||
/[\\$.|*+(){^]/g, | ||
match => `\\${match}` | ||
@@ -98,11 +106,2 @@ ], | ||
[ | ||
// > [abc] matches any character inside the brackets | ||
// > (in this case a, b, or c); | ||
/\[([^\]/]*)($|\])/g, | ||
(match, p1, p2) => p2 === ']' | ||
? `[${sanitizeRange(p1)}]` | ||
: `\\${match}` | ||
], | ||
[ | ||
// > a question mark (?) matches a single character | ||
@@ -142,27 +141,2 @@ /(?!\\)\?/g, | ||
// ending | ||
[ | ||
// 'js' will not match 'js.' | ||
// 'ab' will not match 'abc' | ||
/(?:[^*])$/, | ||
// WTF! | ||
// https://git-scm.com/docs/gitignore | ||
// changes in [2.22.1](https://git-scm.com/docs/gitignore/2.22.1) | ||
// which re-fixes #24, #38 | ||
// > If there is a separator at the end of the pattern then the pattern | ||
// > will only match directories, otherwise the pattern can match both | ||
// > files and directories. | ||
// 'js*' will not match 'a.js' | ||
// 'js/' will not match 'a.js' | ||
// 'js' will match 'a.js' and 'a.js/' | ||
match => /\/$/.test(match) | ||
// foo/ will not match 'foo' | ||
? `${match}$` | ||
// foo matches 'foo' and 'foo/' | ||
: `${match}(?=$|\\/$)` | ||
], | ||
// starting | ||
@@ -236,2 +210,62 @@ [ | ||
[ | ||
// unescape, revert step 3 except for back slash | ||
// For example, if a user escape a '\\*', | ||
// after step 3, the result will be '\\\\\\*' | ||
/\\\\\\(?=[$.|*+(){^])/g, | ||
() => ESCAPE | ||
], | ||
[ | ||
// '\\\\' -> '\\' | ||
/\\\\/g, | ||
() => ESCAPE | ||
], | ||
[ | ||
// > The range notation, e.g. [a-zA-Z], | ||
// > can be used to match one of the characters in a range. | ||
// `\` is escaped by step 3 | ||
/(\\)?\[([^\]/]*?)(\\*)($|\])/g, | ||
(match, leadEscape, range, endEscape, close) => leadEscape === ESCAPE | ||
// '\\[bar]' -> '\\\\[bar\\]' | ||
? `\\[${range}${cleanRangeBackSlash(endEscape)}${close}` | ||
: close === ']' | ||
? endEscape.length % 2 === 0 | ||
// A normal case, and it is a range notation | ||
// '[bar]' | ||
// '[bar\\\\]' | ||
? `[${sanitizeRange(range)}${endEscape}]` | ||
// Invalid range notaton | ||
// '[bar\\]' -> '[bar\\\\]' | ||
: '[]' | ||
: '[]' | ||
], | ||
// ending | ||
[ | ||
// 'js' will not match 'js.' | ||
// 'ab' will not match 'abc' | ||
/(?:[^*])$/, | ||
// WTF! | ||
// https://git-scm.com/docs/gitignore | ||
// changes in [2.22.1](https://git-scm.com/docs/gitignore/2.22.1) | ||
// which re-fixes #24, #38 | ||
// > If there is a separator at the end of the pattern then the pattern | ||
// > will only match directories, otherwise the pattern can match both | ||
// > files and directories. | ||
// 'js*' will not match 'a.js' | ||
// 'js/' will not match 'a.js' | ||
// 'js' will match 'a.js' and 'a.js/' | ||
match => /\/$/.test(match) | ||
// foo/ will not match 'foo' | ||
? `${match}$` | ||
// foo matches 'foo' and 'foo/' | ||
: `${match}(?=$|\\/$)` | ||
], | ||
// trailing wildcard | ||
@@ -243,3 +277,3 @@ [ | ||
// '\^': | ||
// '/*' does not match '' | ||
// '/*' does not match EMPTY | ||
// '/*' does not match everything | ||
@@ -258,8 +292,2 @@ | ||
], | ||
[ | ||
// unescape | ||
/\\\\\\/g, | ||
() => '\\' | ||
] | ||
] | ||
@@ -357,3 +385,3 @@ | ||
// We don't know if we should ignore '', so throw | ||
// We don't know if we should ignore EMPTY, so throw | ||
if (!path) { | ||
@@ -360,0 +388,0 @@ return doThrow(`path must not be empty`, TypeError) |
@@ -14,2 +14,4 @@ "use strict"; | ||
var EMPTY = ''; | ||
var ESCAPE = '\\'; | ||
var REGEX_TEST_BLANK_LINE = /^\s+$/; | ||
@@ -43,4 +45,9 @@ var REGEX_REPLACE_LEADING_EXCAPED_EXCLAMATION = /^\\!/; | ||
// fatal for JavaScript regular expression, so eliminate it. | ||
: ''; | ||
: EMPTY; | ||
}); | ||
}; // See fixtures #59 | ||
var cleanRangeBackSlash = function cleanRangeBackSlash(slashes) { | ||
return slashes.slice(0, parseInt(slashes.length / 2, 10) * 2); | ||
}; // > If the pattern ends with a slash, | ||
@@ -63,3 +70,3 @@ // > it is removed for the purpose of the following description, | ||
/\\?\s+$/, function (match) { | ||
return match.indexOf('\\') === 0 ? ' ' : ''; | ||
return match.indexOf('\\') === 0 ? ' ' : EMPTY; | ||
}], // replace (\ ) with ' ' | ||
@@ -84,8 +91,4 @@ [/\\\s/g, function () { | ||
// > These special characters are often called "metacharacters". | ||
[/[\\^$.|*+(){]/g, function (match) { | ||
[/[\\$.|*+(){^]/g, function (match) { | ||
return "\\".concat(match); | ||
}], [// > [abc] matches any character inside the brackets | ||
// > (in this case a, b, or c); | ||
/\[([^\]/]*)($|\])/g, function (match, p1, p2) { | ||
return p2 === ']' ? "[".concat(sanitizeRange(p1), "]") : "\\".concat(match); | ||
}], [// > a question mark (?) matches a single character | ||
@@ -112,19 +115,2 @@ /(?!\\)\?/g, function () { | ||
return '^(?:.*\\/)?'; | ||
}], // ending | ||
[// 'js' will not match 'js.' | ||
// 'ab' will not match 'abc' | ||
/(?:[^*])$/, // WTF! | ||
// https://git-scm.com/docs/gitignore | ||
// changes in [2.22.1](https://git-scm.com/docs/gitignore/2.22.1) | ||
// which re-fixes #24, #38 | ||
// > If there is a separator at the end of the pattern then the pattern | ||
// > will only match directories, otherwise the pattern can match both | ||
// > files and directories. | ||
// 'js*' will not match 'a.js' | ||
// 'js/' will not match 'a.js' | ||
// 'js' will match 'a.js' and 'a.js/' | ||
function (match) { | ||
return /\/$/.test(match) // foo/ will not match 'foo' | ||
? "".concat(match, "$") // foo matches 'foo' and 'foo/' | ||
: "".concat(match, "(?=$|\\/$)"); | ||
}], // starting | ||
@@ -174,6 +160,42 @@ [// there will be no leading '/' | ||
return "".concat(p1, "[^\\/]*"); | ||
}], [// unescape, revert step 3 except for back slash | ||
// For example, if a user escape a '\\*', | ||
// after step 3, the result will be '\\\\\\*' | ||
/\\\\\\(?=[$.|*+(){^])/g, function () { | ||
return ESCAPE; | ||
}], [// '\\\\' -> '\\' | ||
/\\\\/g, function () { | ||
return ESCAPE; | ||
}], [// > The range notation, e.g. [a-zA-Z], | ||
// > can be used to match one of the characters in a range. | ||
// `\` is escaped by step 3 | ||
/(\\)?\[([^\]/]*?)(\\*)($|\])/g, function (match, leadEscape, range, endEscape, close) { | ||
return leadEscape === ESCAPE // '\\[bar]' -> '\\\\[bar\\]' | ||
? "\\[".concat(range).concat(cleanRangeBackSlash(endEscape)).concat(close) : close === ']' ? endEscape.length % 2 === 0 // A normal case, and it is a range notation | ||
// '[bar]' | ||
// '[bar\\\\]' | ||
? "[".concat(sanitizeRange(range)).concat(endEscape, "]") // Invalid range notaton | ||
// '[bar\\]' -> '[bar\\\\]' | ||
: '[]' : '[]'; | ||
}], // ending | ||
[// 'js' will not match 'js.' | ||
// 'ab' will not match 'abc' | ||
/(?:[^*])$/, // WTF! | ||
// https://git-scm.com/docs/gitignore | ||
// changes in [2.22.1](https://git-scm.com/docs/gitignore/2.22.1) | ||
// which re-fixes #24, #38 | ||
// > If there is a separator at the end of the pattern then the pattern | ||
// > will only match directories, otherwise the pattern can match both | ||
// > files and directories. | ||
// 'js*' will not match 'a.js' | ||
// 'js/' will not match 'a.js' | ||
// 'js' will match 'a.js' and 'a.js/' | ||
function (match) { | ||
return /\/$/.test(match) // foo/ will not match 'foo' | ||
? "".concat(match, "$") // foo matches 'foo' and 'foo/' | ||
: "".concat(match, "(?=$|\\/$)"); | ||
}], // trailing wildcard | ||
[/(\^|\\\/)?\\\*$/, function (_, p1) { | ||
var prefix = p1 // '\^': | ||
// '/*' does not match '' | ||
// '/*' does not match EMPTY | ||
// '/*' does not match everything | ||
@@ -186,5 +208,2 @@ // '\\\/': | ||
return "".concat(prefix, "(?=$|\\/$)"); | ||
}], [// unescape | ||
/\\\\\\/g, function () { | ||
return '\\'; | ||
}]]; // A simple cache, because an ignore rule only has only one certain meaning | ||
@@ -258,3 +277,3 @@ | ||
return doThrow("path must be a string, but got `".concat(originalPath, "`"), TypeError); | ||
} // We don't know if we should ignore '', so throw | ||
} // We don't know if we should ignore EMPTY, so throw | ||
@@ -285,5 +304,3 @@ | ||
var Ignore = | ||
/*#__PURE__*/ | ||
function () { | ||
var Ignore = /*#__PURE__*/function () { | ||
function Ignore() { | ||
@@ -290,0 +307,0 @@ var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, |
{ | ||
"name": "ignore", | ||
"version": "5.1.4", | ||
"version": "5.1.5", | ||
"description": "Ignore is a manager and filter for .gitignore rules, the one used by eslint, gitbook and many others.", | ||
@@ -51,17 +51,17 @@ "files": [ | ||
"devDependencies": { | ||
"@babel/cli": "^7.5.5", | ||
"@babel/core": "^7.5.5", | ||
"@babel/preset-env": "^7.5.5", | ||
"codecov": "^3.5.0", | ||
"@babel/cli": "^7.8.4", | ||
"@babel/core": "^7.9.6", | ||
"@babel/preset-env": "^7.9.6", | ||
"codecov": "^3.7.0", | ||
"debug": "^4.1.1", | ||
"eslint": "^6.1.0", | ||
"eslint": "^7.0.0", | ||
"eslint-config-ostai": "^3.0.0", | ||
"eslint-plugin-import": "^2.18.2", | ||
"mkdirp": "^0.5.1", | ||
"eslint-plugin-import": "^2.20.2", | ||
"mkdirp": "^1.0.4", | ||
"pre-suf": "^1.1.1", | ||
"rimraf": "^2.7.0", | ||
"rimraf": "^3.0.2", | ||
"spawn-sync": "^2.0.0", | ||
"tap": "^14.6.1", | ||
"tmp": "0.1.0", | ||
"typescript": "^3.5.3" | ||
"tap": "^14.10.7", | ||
"tmp": "0.2.1", | ||
"typescript": "^3.9.3" | ||
}, | ||
@@ -68,0 +68,0 @@ "engines": { |
@@ -38,3 +38,3 @@ <table><thead> | ||
`ignore` is a manager, filter and parser which implemented in pure JavaScript according to the .gitignore [spec](http://git-scm.com/docs/gitignore). | ||
`ignore` is a manager, filter and parser which implemented in pure JavaScript according to the [.gitignore spec 2.22.1](http://git-scm.com/docs/gitignore). | ||
@@ -314,4 +314,6 @@ `ignore` is used by eslint, gitbook and [many others](https://www.npmjs.com/browse/depended/ignore). | ||
Check whether the `pathname` is valid according to the [convention](#1-pathname-should-be-a-pathrelatived-pathname). | ||
Check whether the `pathname` is an valid `path.relative()`d path according to the [convention](#1-pathname-should-be-a-pathrelatived-pathname). | ||
This method is **NOT** used to check if an ignore pattern is valid. | ||
```js | ||
@@ -318,0 +320,0 @@ ignore.isPathValid('./foo') // false |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
48691
967
389