Comparing version 3.1.3 to 3.1.4
110
ignore.js
@@ -109,9 +109,8 @@ 'use strict'; | ||
value: function _createRule(pattern) { | ||
var rule_object = { | ||
origin: pattern | ||
}; | ||
var origin = pattern; | ||
var negative = false; | ||
// > An optional prefix "!" which negates the pattern; | ||
if (pattern.indexOf('!') === 0) { | ||
rule_object.negative = true; | ||
negative = true; | ||
pattern = pattern.substr(1); | ||
@@ -126,6 +125,10 @@ } | ||
rule_object.pattern = pattern; | ||
rule_object.regex = regex(pattern); | ||
var regex = make_regex(pattern, negative); | ||
return rule_object; | ||
return { | ||
origin: origin, | ||
pattern: pattern, | ||
negative: negative, | ||
regex: regex | ||
}; | ||
} | ||
@@ -202,3 +205,3 @@ }, { | ||
var REPLACERS = [ | ||
var DEFAULT_REPLACER_PREFIX = [ | ||
@@ -215,3 +218,3 @@ // > Trailing spaces are ignored unless they are quoted with backslash ("\") | ||
// replace (\ ) with ' ' | ||
[/\\\s/g, function (match) { | ||
[/\\\s/g, function () { | ||
return ' '; | ||
@@ -266,27 +269,5 @@ }], | ||
return '^(?:.*\\/)?'; | ||
}], | ||
}]]; | ||
// 'f' | ||
// matches | ||
// - /f(end) | ||
// - /f/ | ||
// - (start)f(end) | ||
// - (start)f/ | ||
// doesn't match | ||
// - oof | ||
// - foo | ||
// pseudo: | ||
// -> (^|/)f(/|$) | ||
// ending | ||
[ | ||
// 'js' will not match 'js.' | ||
// 'ab' will not match 'abc' | ||
/(?:[^*\/])$/, function (match) { | ||
// 'js*' will not match 'a.js' | ||
// 'js/' will not match 'a.js' | ||
// 'js' will match 'a.js' and 'a.js/' | ||
return match + '(?=$|\\/)'; | ||
}], | ||
var DEFAULT_REPLACER_SUFFIX = [ | ||
// starting | ||
@@ -296,3 +277,3 @@ [ | ||
// If starts with '**', adding a '^' to the regular expression also works | ||
/^(?=[^\^])/, function (match) { | ||
/^(?=[^\^])/, function () { | ||
return !/\/(?!$)/.test(this) | ||
@@ -314,5 +295,5 @@ // > If the pattern does not contain a slash /, Git treats it as a shell glob pattern | ||
// should not use '*', or it will be replaced by the next replacer | ||
function (m, index, str) { | ||
// Check if it is not the last `'/**'` | ||
// Check if it is not the last `'/**'` | ||
function (match, index, str) { | ||
return index + 6 < str.length | ||
@@ -340,5 +321,7 @@ | ||
// 'abc.*' -> skip this rule | ||
/(^|[^\\]+)\\\*(?=.+)/g, function (match, p1) { | ||
// '*.js' matches '.js' | ||
// '*.js' doesn't match 'abc' | ||
/(^|[^\\]+)\\\*(?=.+)/g, | ||
// '*.js' matches '.js' | ||
// '*.js' doesn't match 'abc' | ||
function (match, p1) { | ||
return p1 + '[^\\/]*'; | ||
@@ -348,3 +331,3 @@ }], | ||
// trailing wildcard | ||
[/(\\\/)?\\\*$/, function (m, p1) { | ||
[/(\\\/)?\\\*$/, function (match, p1) { | ||
return p1 === '\\/' | ||
@@ -364,2 +347,43 @@ // 'a/*' does not match 'a/' | ||
var POSITIVE_REPLACERS = [].concat(DEFAULT_REPLACER_PREFIX, [ | ||
// 'f' | ||
// matches | ||
// - /f(end) | ||
// - /f/ | ||
// - (start)f(end) | ||
// - (start)f/ | ||
// doesn't match | ||
// - oof | ||
// - foo | ||
// pseudo: | ||
// -> (^|/)f(/|$) | ||
// ending | ||
[ | ||
// 'js' will not match 'js.' | ||
// 'ab' will not match 'abc' | ||
/(?:[^*\/])$/, | ||
// 'js*' will not match 'a.js' | ||
// 'js/' will not match 'a.js' | ||
// 'js' will match 'a.js' and 'a.js/' | ||
function (match) { | ||
return match + '(?=$|\\/)'; | ||
}]], DEFAULT_REPLACER_SUFFIX); | ||
var NEGATIVE_REPLACERS = [].concat(DEFAULT_REPLACER_PREFIX, [ | ||
// #24 | ||
// The MISSING rule of [gitignore docs](https://git-scm.com/docs/gitignore) | ||
// A negative pattern without a trailing wildcard should not | ||
// re-include the things inside that directory. | ||
// eg: | ||
// ['node_modules/*', '!node_modules'] | ||
// should ignore `node_modules/a.js` | ||
[/(?:[^*\/])$/, function (match) { | ||
return match + '(?=$|\\/$)'; | ||
}]], DEFAULT_REPLACER_SUFFIX); | ||
// A simple cache, because an ignore rule only has only one certain meaning | ||
@@ -369,3 +393,3 @@ var cache = {}; | ||
// @param {pattern} | ||
function regex(pattern) { | ||
function make_regex(pattern, negative) { | ||
var r = cache[pattern]; | ||
@@ -376,3 +400,5 @@ if (r) { | ||
var source = REPLACERS.reduce(function (prev, current) { | ||
var replacers = negative ? NEGATIVE_REPLACERS : POSITIVE_REPLACERS; | ||
var source = replacers.reduce(function (prev, current) { | ||
return prev.replace(current[0], current[1].bind(pattern)); | ||
@@ -379,0 +405,0 @@ }, pattern); |
{ | ||
"name": "ignore", | ||
"version": "3.1.3", | ||
"version": "3.1.4", | ||
"description": "Ignore is a manager and filter for .gitignore rules.", | ||
@@ -5,0 +5,0 @@ "main": "./ignore.js", |
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
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
19174
4
340
0
189