Comparing version 5.1.9 to 5.2.0
@@ -10,13 +10,7 @@ type Pathname = string | ||
/** | ||
* Adds a rule rules to the current manager. | ||
* @param {string | Ignore} pattern | ||
* @returns IgnoreBase | ||
*/ | ||
add(pattern: string | Ignore): this | ||
/** | ||
* Adds several rules to the current manager. | ||
* Adds one or several rules to the current manager. | ||
* @param {string[]} patterns | ||
* @returns IgnoreBase | ||
*/ | ||
add(patterns: (string | Ignore)[]): this | ||
add(patterns: string | Ignore | readonly (string | Ignore)[]): this | ||
@@ -29,3 +23,4 @@ /** | ||
*/ | ||
filter(pathnames: Pathname[]): Pathname[] | ||
filter(pathnames: readonly Pathname[]): Pathname[] | ||
/** | ||
@@ -54,2 +49,5 @@ * Creates a filter function which could filter | ||
ignorecase?: boolean | ||
// For compatibility | ||
ignoreCase?: boolean | ||
allowRelativePaths?: boolean | ||
} | ||
@@ -56,0 +54,0 @@ |
31
index.js
@@ -33,2 +33,4 @@ // A simple implementation of make-array | ||
const RETURN_FALSE = () => false | ||
// Sanitize the range of a regular expression | ||
@@ -292,3 +294,3 @@ // The cases are complicated, see test cases for details | ||
// @param {pattern} | ||
const makeRegex = (pattern, ignorecase) => { | ||
const makeRegex = (pattern, ignoreCase) => { | ||
let source = regexCache[pattern] | ||
@@ -304,3 +306,3 @@ | ||
return ignorecase | ||
return ignoreCase | ||
? new RegExp(source, 'i') | ||
@@ -336,3 +338,3 @@ : new RegExp(source) | ||
const createRule = (pattern, ignorecase) => { | ||
const createRule = (pattern, ignoreCase) => { | ||
const origin = pattern | ||
@@ -355,3 +357,3 @@ let negative = false | ||
const regex = makeRegex(pattern, ignorecase) | ||
const regex = makeRegex(pattern, ignoreCase) | ||
@@ -402,3 +404,5 @@ return new IgnoreRule( | ||
constructor ({ | ||
ignorecase = true | ||
ignorecase = true, | ||
ignoreCase = ignorecase, | ||
allowRelativePaths = false | ||
} = {}) { | ||
@@ -408,3 +412,4 @@ define(this, KEY_IGNORE, true) | ||
this._rules = [] | ||
this._ignorecase = ignorecase | ||
this._ignoreCase = ignoreCase | ||
this._allowRelativePaths = allowRelativePaths | ||
this._initCache() | ||
@@ -427,3 +432,3 @@ } | ||
if (checkPattern(pattern)) { | ||
const rule = createRule(pattern, this._ignorecase) | ||
const rule = createRule(pattern, this._ignoreCase) | ||
this._added = true | ||
@@ -507,3 +512,9 @@ this._rules.push(rule) | ||
checkPath(path, originalPath, throwError) | ||
checkPath( | ||
path, | ||
originalPath, | ||
this._allowRelativePaths | ||
? RETURN_FALSE | ||
: throwError | ||
) | ||
@@ -566,6 +577,4 @@ return this._t(path, cache, checkUnignored, slices) | ||
const returnFalse = () => false | ||
const isPathValid = path => | ||
checkPath(path && checkPath.convert(path), path, returnFalse) | ||
checkPath(path && checkPath.convert(path), path, RETURN_FALSE) | ||
@@ -572,0 +581,0 @@ factory.isPathValid = isPathValid |
@@ -38,5 +38,10 @@ "use strict"; | ||
var REGEX_REGEXP_RANGE = /([0-z])-([0-z])/g; // Sanitize the range of a regular expression | ||
var REGEX_REGEXP_RANGE = /([0-z])-([0-z])/g; | ||
var RETURN_FALSE = function RETURN_FALSE() { | ||
return false; | ||
}; // Sanitize the range of a regular expression | ||
// The cases are complicated, see test cases for details | ||
var sanitizeRange = function sanitizeRange(range) { | ||
@@ -209,3 +214,3 @@ return range.replace(REGEX_REGEXP_RANGE, function (match, from, to) { | ||
var makeRegex = function makeRegex(pattern, ignorecase) { | ||
var makeRegex = function makeRegex(pattern, ignoreCase) { | ||
var source = regexCache[pattern]; | ||
@@ -220,3 +225,3 @@ | ||
return ignorecase ? new RegExp(source, 'i') : new RegExp(source); | ||
return ignoreCase ? new RegExp(source, 'i') : new RegExp(source); | ||
}; | ||
@@ -247,3 +252,3 @@ | ||
var createRule = function createRule(pattern, ignorecase) { | ||
var createRule = function createRule(pattern, ignoreCase) { | ||
var origin = pattern; | ||
@@ -262,3 +267,3 @@ var negative = false; // > An optional prefix "!" which negates the pattern; | ||
.replace(REGEX_REPLACE_LEADING_EXCAPED_HASH, '#'); | ||
var regex = makeRegex(pattern, ignorecase); | ||
var regex = makeRegex(pattern, ignoreCase); | ||
return new IgnoreRule(origin, pattern, negative, regex); | ||
@@ -304,3 +309,7 @@ }; | ||
_ref$ignorecase = _ref.ignorecase, | ||
ignorecase = _ref$ignorecase === void 0 ? true : _ref$ignorecase; | ||
ignorecase = _ref$ignorecase === void 0 ? true : _ref$ignorecase, | ||
_ref$ignoreCase = _ref.ignoreCase, | ||
ignoreCase = _ref$ignoreCase === void 0 ? ignorecase : _ref$ignoreCase, | ||
_ref$allowRelativePat = _ref.allowRelativePaths, | ||
allowRelativePaths = _ref$allowRelativePat === void 0 ? false : _ref$allowRelativePat; | ||
@@ -311,3 +320,4 @@ _classCallCheck(this, Ignore); | ||
this._rules = []; | ||
this._ignorecase = ignorecase; | ||
this._ignoreCase = ignoreCase; | ||
this._allowRelativePaths = allowRelativePaths; | ||
@@ -334,3 +344,3 @@ this._initCache(); | ||
if (checkPattern(pattern)) { | ||
var rule = createRule(pattern, this._ignorecase); | ||
var rule = createRule(pattern, this._ignoreCase); | ||
this._added = true; | ||
@@ -406,3 +416,3 @@ | ||
&& checkPath.convert(originalPath); | ||
checkPath(path, originalPath, throwError); | ||
checkPath(path, originalPath, this._allowRelativePaths ? RETURN_FALSE : throwError); | ||
return this._t(path, cache, checkUnignored, slices); | ||
@@ -470,8 +480,4 @@ } | ||
var returnFalse = function returnFalse() { | ||
return false; | ||
}; | ||
var isPathValid = function isPathValid(path) { | ||
return checkPath(path && checkPath.convert(path), path, returnFalse); | ||
return checkPath(path && checkPath.convert(path), path, RETURN_FALSE); | ||
}; | ||
@@ -478,0 +484,0 @@ |
{ | ||
"name": "ignore", | ||
"version": "5.1.9", | ||
"version": "5.2.0", | ||
"description": "Ignore is a manager and filter for .gitignore rules, the one used by eslint, gitbook and many others.", | ||
@@ -5,0 +5,0 @@ "files": [ |
@@ -301,4 +301,16 @@ <table><thead> | ||
## `options.ignorecase` since 4.0.0 | ||
## static `ignore.isPathValid(pathname): boolean` since 5.0.0 | ||
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 | ||
ignore.isPathValid('./foo') // false | ||
``` | ||
## ignore(options) | ||
### `options.ignorecase` since 4.0.0 | ||
Similar as the `core.ignorecase` option of [git-config](https://git-scm.com/docs/git-config), `node-ignore` will be case insensitive if `options.ignorecase` is set to `true` (the default value), otherwise case sensitive. | ||
@@ -316,10 +328,16 @@ | ||
## static `ignore.isPathValid(pathname): boolean` since 5.0.0 | ||
### `options.ignoreCase?: boolean` since 5.2.0 | ||
Check whether the `pathname` is an valid `path.relative()`d path according to the [convention](#1-pathname-should-be-a-pathrelatived-pathname). | ||
Which is alternative to `options.ignoreCase` | ||
This method is **NOT** used to check if an ignore pattern is valid. | ||
### `options.allowRelativePaths?: boolean` since 5.2.0 | ||
This option brings backward compatibility with projects which based on `ignore@4.x`. If `options.allowRelativePaths` is `true`, `ignore` will not check whether the given path to be tested is [`path.relative()`d](#pathname-conventions). | ||
However, passing a relative path, such as `'./foo'` or `'../foo'`, to test if it is ignored or not is not a good practise, which might lead to unexpected behavior | ||
```js | ||
ignore.isPathValid('./foo') // false | ||
ignore({ | ||
allowRelativePaths: true | ||
}).ignores('../foo/bar.js') // And it will not throw | ||
``` | ||
@@ -333,4 +351,6 @@ | ||
Since `5.0.0`, if an invalid `Pathname` passed into `ig.ignores()`, an error will be thrown, while `ignore < 5.0.0` did not make sure what the return value was, as well as | ||
Since `5.0.0`, if an invalid `Pathname` passed into `ig.ignores()`, an error will be thrown, unless `options.allowRelative = true` is passed to the `Ignore` factory. | ||
While `ignore < 5.0.0` did not make sure what the return value was, as well as | ||
```ts | ||
@@ -337,0 +357,0 @@ .ignores(pathname: Pathname): boolean |
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
48870
976
413