Comparing version 2.2.12 to 2.2.13
452
index.js
@@ -6,37 +6,37 @@ 'use strict'; | ||
var EE = require('events').EventEmitter; | ||
var EE = require('events').EventEmitter; | ||
var node_util = require('util'); | ||
var node_fs = require('fs'); | ||
var node_fs = require('fs'); | ||
function ignore (options){ | ||
return new Ignore(options); | ||
function ignore(options) { | ||
return new Ignore(options); | ||
} | ||
var exists = node_fs.existsSync ? | ||
function (file) { | ||
return node_fs.existsSync(file); | ||
} : | ||
function(file) { | ||
return node_fs.existsSync(file); | ||
} : | ||
// if node <= 0.6, there's no fs.existsSync method. | ||
function (file) { | ||
try { | ||
node_fs.statSync(file); | ||
return true; | ||
} catch(e) { | ||
return false; | ||
} | ||
}; | ||
// if node <= 0.6, there's no fs.existsSync method. | ||
function(file) { | ||
try { | ||
node_fs.statSync(file); | ||
return true; | ||
} catch (e) { | ||
return false; | ||
} | ||
}; | ||
// Select the first existing file of the file list | ||
ignore.select = function (files) { | ||
var selected; | ||
ignore.select = function(files) { | ||
var selected; | ||
files.some(function (file) { | ||
if( exists(file) ){ | ||
selected = file; | ||
return true; | ||
} | ||
}); | ||
files.some(function(file) { | ||
if (exists(file)) { | ||
selected = file; | ||
return true; | ||
} | ||
}); | ||
return selected; | ||
return selected; | ||
}; | ||
@@ -51,18 +51,18 @@ | ||
// By default, git is case-insensitive | ||
function Ignore (options){ | ||
options = options || {}; | ||
function Ignore(options) { | ||
options = options || {}; | ||
this.options = options; | ||
this._patterns = []; | ||
this._rules = []; | ||
this._ignoreFiles = []; | ||
this.options = options; | ||
this._patterns = []; | ||
this._rules = []; | ||
this._ignoreFiles = []; | ||
options.ignore = options.ignore || [ | ||
// Some files or directories which we should ignore for most cases. | ||
'.git', | ||
'.svn', | ||
'.DS_Store' | ||
]; | ||
options.ignore = options.ignore || [ | ||
// Some files or directories which we should ignore for most cases. | ||
'.git', | ||
'.svn', | ||
'.DS_Store' | ||
]; | ||
this.addPattern(options.ignore); | ||
this.addPattern(options.ignore); | ||
} | ||
@@ -76,8 +76,8 @@ | ||
function makeArray (subject) { | ||
return Array.isArray(subject) ? | ||
subject : | ||
subject === undefined || subject === null ? | ||
[] : | ||
[subject]; | ||
function makeArray(subject) { | ||
return Array.isArray(subject) ? | ||
subject : | ||
subject === undefined || subject === null ? | ||
[] : | ||
[subject]; | ||
} | ||
@@ -88,4 +88,4 @@ | ||
Ignore.prototype.addPattern = function(pattern) { | ||
makeArray(pattern).forEach(this._addPattern, this); | ||
return this; | ||
makeArray(pattern).forEach(this._addPattern, this); | ||
return this; | ||
}; | ||
@@ -95,6 +95,6 @@ | ||
Ignore.prototype._addPattern = function(pattern) { | ||
if(this._simpleTest(pattern)){ | ||
var rule = this._createRule(pattern); | ||
this._rules.push(rule); | ||
} | ||
if (this._simpleTest(pattern)) { | ||
var rule = this._createRule(pattern); | ||
this._rules.push(rule); | ||
} | ||
}; | ||
@@ -104,3 +104,3 @@ | ||
Ignore.prototype.filter = function(paths) { | ||
return paths.filter(this._filter, this); | ||
return paths.filter(this._filter, this); | ||
}; | ||
@@ -110,27 +110,27 @@ | ||
Ignore.prototype._simpleTest = function(pattern) { | ||
var pass = | ||
// Whitespace dirs are allowed, so only filter blank pattern. | ||
pattern && | ||
// And not start with a '#' | ||
pattern.indexOf('#') !== 0 && | ||
var pass = | ||
// Whitespace dirs are allowed, so only filter blank pattern. | ||
pattern && | ||
// And not start with a '#' | ||
pattern.indexOf('#') !== 0 && | ||
! ~ this._patterns.indexOf(pattern); | ||
!~this._patterns.indexOf(pattern); | ||
this._patterns.push(pattern); | ||
this._patterns.push(pattern); | ||
if( ~ pattern.indexOf('**') ){ | ||
this.emit('warn', { | ||
code: 'WGLOBSTARS', | ||
data: { | ||
origin: pattern | ||
}, | ||
message: '`**` found, which is not compatible cross all platforms.' | ||
}); | ||
if (~pattern.indexOf('**')) { | ||
this.emit('warn', { | ||
code: 'WGLOBSTARS', | ||
data: { | ||
origin: pattern | ||
}, | ||
message: '`**` found, which is not compatible cross all platforms.' | ||
}); | ||
if(!this.options.twoGlobstars){ | ||
return false; | ||
} | ||
if (!this.options.twoGlobstars) { | ||
return false; | ||
} | ||
} | ||
return pass; | ||
return pass; | ||
}; | ||
@@ -142,22 +142,22 @@ | ||
Ignore.prototype._createRule = function(pattern) { | ||
var rule_object = { | ||
origin: pattern | ||
}; | ||
var rule_object = { | ||
origin: pattern | ||
}; | ||
var match_start; | ||
var match_start; | ||
if(pattern.indexOf('!') === 0){ | ||
rule_object.negative = true; | ||
pattern = pattern.substr(1); | ||
} | ||
if (pattern.indexOf('!') === 0) { | ||
rule_object.negative = true; | ||
pattern = pattern.substr(1); | ||
} | ||
pattern = pattern | ||
.replace(REGEX_LEADING_EXCLAMATION, '!') | ||
.replace(REGEX_LEADING_HASH, '#'); | ||
pattern = pattern | ||
.replace(REGEX_LEADING_EXCLAMATION, '!') | ||
.replace(REGEX_LEADING_HASH, '#'); | ||
rule_object.pattern = pattern; | ||
rule_object.pattern = pattern; | ||
rule_object.regex = this.makeRegex(pattern); | ||
rule_object.regex = this.makeRegex(pattern); | ||
return rule_object; | ||
return rule_object; | ||
}; | ||
@@ -173,119 +173,119 @@ | ||
// Escape metacharacters | ||
// which is written down by users but means special for regular expressions. | ||
// Escape metacharacters | ||
// which is written down by users but means special for regular expressions. | ||
// > There are 12 characters with special meanings: | ||
// > - the backslash \, | ||
// > - the caret ^, | ||
// > - the dollar sign $, | ||
// > - the period or dot ., | ||
// > - the vertical bar or pipe symbol |, | ||
// > - the question mark ?, | ||
// > - the asterisk or star *, | ||
// > - the plus sign +, | ||
// > - the opening parenthesis (, | ||
// > - the closing parenthesis ), | ||
// > - and the opening square bracket [, | ||
// > - the opening curly brace {, | ||
// > These special characters are often called "metacharacters". | ||
[ | ||
/[\\\^$.|?*+()\[{]/g, | ||
function (match) { | ||
return '\\' + match; | ||
} | ||
], | ||
// > There are 12 characters with special meanings: | ||
// > - the backslash \, | ||
// > - the caret ^, | ||
// > - the dollar sign $, | ||
// > - the period or dot ., | ||
// > - the vertical bar or pipe symbol |, | ||
// > - the question mark ?, | ||
// > - the asterisk or star *, | ||
// > - the plus sign +, | ||
// > - the opening parenthesis (, | ||
// > - the closing parenthesis ), | ||
// > - and the opening square bracket [, | ||
// > - the opening curly brace {, | ||
// > These special characters are often called "metacharacters". | ||
[ | ||
/[\\\^$.|?*+()\[{]/g, | ||
function(match) { | ||
return '\\' + match; | ||
} | ||
], | ||
// leading slash | ||
[ | ||
// leading slash | ||
[ | ||
// > A leading slash matches the beginning of the pathname. For example, "/*.c" matches "cat-file.c" but not "mozilla-sha1/sha1.c". | ||
// A leading slash matches the beginning of the pathname | ||
/^\//, | ||
'^' | ||
], | ||
// > A leading slash matches the beginning of the pathname. For example, "/*.c" matches "cat-file.c" but not "mozilla-sha1/sha1.c". | ||
// A leading slash matches the beginning of the pathname | ||
/^\//, | ||
'^' | ||
], | ||
[ | ||
/\//g, | ||
'\\/' | ||
], | ||
[ | ||
/\//g, | ||
'\\/' | ||
], | ||
[ | ||
// > A leading "**" followed by a slash means match in all directories. For example, "**/foo" matches file or directory "foo" anywhere, the same as pattern "foo". "**/foo/bar" matches file or directory "bar" anywhere that is directly under directory "foo". | ||
// Notice that the '*'s have been replaced as '\\*' | ||
/\\\*\\\*\\\//, | ||
[ | ||
// > A leading "**" followed by a slash means match in all directories. For example, "**/foo" matches file or directory "foo" anywhere, the same as pattern "foo". "**/foo/bar" matches file or directory "bar" anywhere that is directly under directory "foo". | ||
// Notice that the '*'s have been replaced as '\\*' | ||
/\\\*\\\*\\\//, | ||
// '**/foo' <-> 'foo' | ||
// just remove it | ||
'' | ||
], | ||
// '**/foo' <-> 'foo' | ||
// just remove it | ||
'' | ||
], | ||
// 'f' | ||
// matches | ||
// - /f(end) | ||
// - /f/ | ||
// - (start)f(end) | ||
// - (start)f/ | ||
// doesn't match | ||
// - oof | ||
// - foo | ||
// pseudo: | ||
// -> (^|/)f(/|$) | ||
// 'f' | ||
// matches | ||
// - /f(end) | ||
// - /f/ | ||
// - (start)f(end) | ||
// - (start)f/ | ||
// doesn't match | ||
// - oof | ||
// - foo | ||
// pseudo: | ||
// -> (^|/)f(/|$) | ||
// ending | ||
[ | ||
// 'js' will not match 'js.' | ||
/(?:[^*\/])$/, | ||
function (match) { | ||
// 'js*' will not match 'a.js' | ||
// 'js/' will not match 'a.js' | ||
// 'js' will match 'a.js' and 'a.js/' | ||
return match + '(?=$|\\/)'; | ||
} | ||
], | ||
// ending | ||
[ | ||
// 'js' will not match 'js.' | ||
/(?:[^*\/])$/, | ||
function(match) { | ||
// 'js*' will not match 'a.js' | ||
// 'js/' will not match 'a.js' | ||
// 'js' will match 'a.js' and 'a.js/' | ||
return match + '(?=$|\\/)'; | ||
} | ||
], | ||
// starting | ||
[ | ||
// there will be no leading '/' (which has been replaced by the second replacer) | ||
// If starts with '**', adding a '^' to the regular expression also works | ||
/^(?=[^\^])/, | ||
'(?:^|\\/)' | ||
], | ||
// starting | ||
[ | ||
// there will be no leading '/' (which has been replaced by the second replacer) | ||
// If starts with '**', adding a '^' to the regular expression also works | ||
/^(?=[^\^])/, | ||
'(?:^|\\/)' | ||
], | ||
// two globstars | ||
[ | ||
// > A slash followed by two consecutive asterisks then a slash matches zero or more directories. For example, "a/**/b" matches "a/b", "a/x/b", "a/x/y/b" and so on. | ||
// '/**/' | ||
/\/\\\*\\\*\//g, | ||
// two globstars | ||
[ | ||
// > A slash followed by two consecutive asterisks then a slash matches zero or more directories. For example, "a/**/b" matches "a/b", "a/x/b", "a/x/y/b" and so on. | ||
// '/**/' | ||
/\/\\\*\\\*\//g, | ||
// Zero, one or several directories | ||
// should not use '*', or it will be replaced by the next replacer | ||
'(?:\\/[^\\/]+)*\\/' | ||
], | ||
// Zero, one or several directories | ||
// should not use '*', or it will be replaced by the next replacer | ||
'(?:\\/[^\\/]+)*\\/' | ||
], | ||
// intermediate wildcards | ||
[ | ||
// Never replace escaped '*' | ||
// ignore rule '\*' will match the path '*' | ||
// intermediate wildcards | ||
[ | ||
// Never replace escaped '*' | ||
// ignore rule '\*' will match the path '*' | ||
// 'abc.*/' -> go | ||
// 'abc.*' -> skip | ||
/(^|[^\\]+)\\\*(?=.+)/g, | ||
function (match, p1) { | ||
// '*.js' matches '.js' | ||
// '*.js' doesn't match 'abc' | ||
return p1 + '[^\\/]*'; | ||
} | ||
], | ||
// 'abc.*/' -> go | ||
// 'abc.*' -> skip | ||
/(^|[^\\]+)\\\*(?=.+)/g, | ||
function(match, p1) { | ||
// '*.js' matches '.js' | ||
// '*.js' doesn't match 'abc' | ||
return p1 + '[^\\/]*'; | ||
} | ||
], | ||
// ending wildcard | ||
[ | ||
/\\\*$/, | ||
// simply remove it | ||
'' | ||
], | ||
// ending wildcard | ||
[ | ||
/\\\*$/, | ||
// simply remove it | ||
'' | ||
], | ||
[ | ||
/\\\\\\/g, | ||
'\\' | ||
] | ||
[ | ||
/\\\\\\/g, | ||
'\\' | ||
] | ||
]; | ||
@@ -296,8 +296,8 @@ | ||
Ignore.prototype.makeRegex = function(pattern) { | ||
var source = REPLACERS.reduce(function (prev, current) { | ||
return prev.replace( current[0], current[1] ); | ||
var source = REPLACERS.reduce(function(prev, current) { | ||
return prev.replace(current[0], current[1]); | ||
}, pattern); | ||
}, pattern); | ||
return new RegExp(source, this.options.matchCase ? '' : 'i'); | ||
return new RegExp(source, this.options.matchCase ? '' : 'i'); | ||
}; | ||
@@ -307,22 +307,22 @@ | ||
Ignore.prototype._filter = function(path) { | ||
var rules = this._rules; | ||
var i = 0; | ||
var length = rules.length; | ||
var matched; | ||
var rule; | ||
var rules = this._rules; | ||
var i = 0; | ||
var length = rules.length; | ||
var matched; | ||
var rule; | ||
for(; i < length; i ++){ | ||
rule = rules[i]; | ||
for (; i < length; i++) { | ||
rule = rules[i]; | ||
// if matched = true, then we only test negative rules | ||
// if matched = false, then we test non-negative rules | ||
if( !( matched ^ rule.negative ) ){ | ||
matched = rule.negative ^ rule.regex.test(path); | ||
// if matched = true, then we only test negative rules | ||
// if matched = false, then we test non-negative rules | ||
if (!(matched ^ rule.negative)) { | ||
matched = rule.negative ^ rule.regex.test(path); | ||
}else{ | ||
continue; | ||
} | ||
} else { | ||
continue; | ||
} | ||
} | ||
return !matched; | ||
return !matched; | ||
}; | ||
@@ -332,7 +332,7 @@ | ||
Ignore.prototype.createFilter = function() { | ||
var self = this; | ||
var self = this; | ||
return function (path) { | ||
return self._filter(path); | ||
}; | ||
return function(path) { | ||
return self._filter(path); | ||
}; | ||
}; | ||
@@ -343,22 +343,21 @@ | ||
Ignore.prototype.addIgnoreFile = function(files) { | ||
makeArray(files).forEach(this._addIgnoreFile, this); | ||
return this; | ||
makeArray(files).forEach(this._addIgnoreFile, this); | ||
return this; | ||
}; | ||
Ignore.prototype._addIgnoreFile = function (file) { | ||
if(this._checkRuleFile(file)){ | ||
this._ignoreFiles.push(file); | ||
Ignore.prototype._addIgnoreFile = function(file) { | ||
if (this._checkRuleFile(file)) { | ||
this._ignoreFiles.push(file); | ||
var content; | ||
var content; | ||
try { | ||
content = node_fs.readFileSync(file); | ||
} catch(e) { | ||
} | ||
try { | ||
content = node_fs.readFileSync(file); | ||
} catch (e) {} | ||
if(content){ | ||
this.addPattern( content.toString().split(/\r?\n/) ); | ||
} | ||
if (content) { | ||
this.addPattern(content.toString().split(/\r?\n/)); | ||
} | ||
} | ||
}; | ||
@@ -368,7 +367,4 @@ | ||
Ignore.prototype._checkRuleFile = function(file) { | ||
return file !== '.' && | ||
file !== '..' && | ||
! ~ this._ignoreFiles.indexOf(file); | ||
}; | ||
return file !== '.' && | ||
file !== '..' && !~this._ignoreFiles.indexOf(file); | ||
}; |
{ | ||
"name": "ignore", | ||
"version": "2.2.12", | ||
"version": "2.2.13", | ||
"description": "Ignore is a manager and filter for .gitignore rules.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -5,7 +5,7 @@ # ignore [![NPM version](https://badge.fury.io/js/ignore.png)](http://badge.fury.io/js/ignore) [![Build Status](https://travis-ci.org/kaelzhang/node-ignore.png?branch=master)](https://travis-ci.org/kaelzhang/node-ignore) [![Dependency Status](https://gemnasium.com/kaelzhang/node-ignore.png)](https://gemnasium.com/kaelzhang/node-ignore) | ||
# Installation | ||
## Installation | ||
npm install ignore --save | ||
# Usage | ||
## Usage | ||
@@ -17,3 +17,3 @@ ```js | ||
## Filter the given paths | ||
### Filter the given paths | ||
@@ -29,3 +29,3 @@ ```js | ||
## As the filter function | ||
### As the filter function | ||
@@ -36,3 +36,3 @@ ```js | ||
## With ignore files | ||
### With ignore files | ||
@@ -51,3 +51,3 @@ For most cases, we'd better use only one ignore file. We could use `ignore.select` to select the first existing file. | ||
# Why another ignore? | ||
## Why another ignore? | ||
@@ -68,5 +68,5 @@ 1. `ignore` is a standalone module, and is much simpler so that it could easy work with other programs, unlike [isaacs](https://npmjs.org/~isaacs)'s [fstream-ignore](https://npmjs.org/package/fstream-ignore) which must work with the modules of the fstream family. | ||
# Methods | ||
## Methods | ||
## .addPattern(pattern) | ||
### .addPattern(pattern) | ||
@@ -89,3 +89,3 @@ Adds a rule or several rules to the current manager. | ||
## .addIgnoreFile(path) | ||
### .addIgnoreFile(path) | ||
@@ -99,3 +99,3 @@ Adds rules from a ignore file or several files | ||
## .filter(paths) | ||
### .filter(paths) | ||
@@ -147,3 +147,3 @@ Filters the given array of pathnames, and returns the filtered array. | ||
## .createFilter() | ||
### .createFilter() | ||
@@ -157,3 +157,3 @@ Creates a filter function which could filter an array of paths with `Array.prototype.filter`. | ||
# Constructor: ignore.Ignore | ||
## Constructor: ignore.Ignore | ||
@@ -160,0 +160,0 @@ ```js |
@@ -7,175 +7,175 @@ 'use strict'; | ||
describe(".makeRegex(), normal options, pattern 'foo':", function(){ | ||
var ig = ignore(); | ||
var r_foo = ig.makeRegex('foo'); | ||
describe(".makeRegex(), normal options, pattern 'foo':", function() { | ||
var ig = ignore(); | ||
var r_foo = ig.makeRegex('foo'); | ||
it("'foo' should match 'foo'", function(){ | ||
expect( r_foo.test('foo') ).to.equal(true); | ||
}); | ||
it("'foo' should match 'foo'", function() { | ||
expect(r_foo.test('foo')).to.equal(true); | ||
}); | ||
it("'foo' should match 'foo/'", function(){ | ||
expect( r_foo.test('foo/') ).to.equal(true); | ||
}); | ||
it("'foo' should match 'foo/'", function() { | ||
expect(r_foo.test('foo/')).to.equal(true); | ||
}); | ||
it("'foo' should match '/foo'", function(){ | ||
expect( r_foo.test('/foo') ).to.equal(true); | ||
}); | ||
it("'foo' should match '/foo'", function() { | ||
expect(r_foo.test('/foo')).to.equal(true); | ||
}); | ||
it("'foo' should not match 'fooo'", function(){ | ||
expect( r_foo.test('fooo') ).to.equal(false); | ||
}); | ||
it("'foo' should not match 'fooo'", function() { | ||
expect(r_foo.test('fooo')).to.equal(false); | ||
}); | ||
it("'foo' should not match 'ofoo'", function(){ | ||
expect( r_foo.test('ofoo') ).to.equal(false); | ||
}); | ||
it("'foo' should not match 'ofoo'", function() { | ||
expect(r_foo.test('ofoo')).to.equal(false); | ||
}); | ||
}); | ||
describe(".makeRegex(), normal options, pattern '**/foo' matches 'foo' anywhere:", function(){ | ||
var ig = ignore(); | ||
var r_foo = ig.makeRegex('**/foo'); | ||
describe(".makeRegex(), normal options, pattern '**/foo' matches 'foo' anywhere:", function() { | ||
var ig = ignore(); | ||
var r_foo = ig.makeRegex('**/foo'); | ||
it("'**/foo' should match 'foo'", function(){ | ||
expect( r_foo.test('foo') ).to.equal(true); | ||
}); | ||
it("'**/foo' should match 'foo'", function() { | ||
expect(r_foo.test('foo')).to.equal(true); | ||
}); | ||
it("'**/foo' should match 'foo/'", function(){ | ||
expect( r_foo.test('foo/') ).to.equal(true); | ||
}); | ||
it("'**/foo' should match 'foo/'", function() { | ||
expect(r_foo.test('foo/')).to.equal(true); | ||
}); | ||
it("'**/foo' should match '/foo'", function(){ | ||
expect( r_foo.test('/foo') ).to.equal(true); | ||
}); | ||
it("'**/foo' should match '/foo'", function() { | ||
expect(r_foo.test('/foo')).to.equal(true); | ||
}); | ||
it("'**/foo' should not match 'fooo'", function(){ | ||
expect( r_foo.test('fooo') ).to.equal(false); | ||
}); | ||
it("'**/foo' should not match 'fooo'", function() { | ||
expect(r_foo.test('fooo')).to.equal(false); | ||
}); | ||
it("'**/foo' should not match 'ofoo'", function(){ | ||
expect( r_foo.test('ofoo') ).to.equal(false); | ||
}); | ||
it("'**/foo' should not match 'ofoo'", function() { | ||
expect(r_foo.test('ofoo')).to.equal(false); | ||
}); | ||
}); | ||
describe(".makeRegex(), normal options, pattern 'foo/':", function(){ | ||
var ig = ignore(); | ||
var r_foo_slash = ig.makeRegex('foo/'); | ||
describe(".makeRegex(), normal options, pattern 'foo/':", function() { | ||
var ig = ignore(); | ||
var r_foo_slash = ig.makeRegex('foo/'); | ||
it("'foo' should match 'foo/'", function(){ | ||
expect( r_foo_slash.test('foo/') ).to.equal(true); | ||
}); | ||
it("'foo' should match 'foo/'", function() { | ||
expect(r_foo_slash.test('foo/')).to.equal(true); | ||
}); | ||
it("'foo' should match 'foo/a'", function(){ | ||
expect( r_foo_slash.test('foo/a') ).to.equal(true); | ||
}); | ||
it("'foo' should match 'foo/a'", function() { | ||
expect(r_foo_slash.test('foo/a')).to.equal(true); | ||
}); | ||
it("'foo' should match '/foo/'", function(){ | ||
expect( r_foo_slash.test('/foo/') ).to.equal(true); | ||
}); | ||
it("'foo' should match '/foo/'", function() { | ||
expect(r_foo_slash.test('/foo/')).to.equal(true); | ||
}); | ||
it("'foo' should not match 'foo'", function(){ | ||
expect( r_foo_slash.test('foo') ).to.equal(false); | ||
}); | ||
it("'foo' should not match 'foo'", function() { | ||
expect(r_foo_slash.test('foo')).to.equal(false); | ||
}); | ||
it("'foo' should not match '/foo'", function(){ | ||
expect( r_foo_slash.test('/foo') ).to.equal(false); | ||
}); | ||
it("'foo' should not match '/foo'", function() { | ||
expect(r_foo_slash.test('/foo')).to.equal(false); | ||
}); | ||
}); | ||
describe(".makeRegex(), normal options, pattern '/.js':", function(){ | ||
var ig = ignore(); | ||
var r_slash_dot_js = ig.makeRegex('/.js'); | ||
describe(".makeRegex(), normal options, pattern '/.js':", function() { | ||
var ig = ignore(); | ||
var r_slash_dot_js = ig.makeRegex('/.js'); | ||
it("collection:", function(){ | ||
expect( r_slash_dot_js.test('.js') ).to.equal(true); | ||
expect( r_slash_dot_js.test('.js/') ).to.equal(true); | ||
expect( r_slash_dot_js.test('.js/a') ).to.equal(true); | ||
it("collection:", function() { | ||
expect(r_slash_dot_js.test('.js')).to.equal(true); | ||
expect(r_slash_dot_js.test('.js/')).to.equal(true); | ||
expect(r_slash_dot_js.test('.js/a')).to.equal(true); | ||
expect( r_slash_dot_js.test('/.js') ).to.equal(false); | ||
expect( r_slash_dot_js.test('.jsa') ).to.equal(false); | ||
}); | ||
expect(r_slash_dot_js.test('/.js')).to.equal(false); | ||
expect(r_slash_dot_js.test('.jsa')).to.equal(false); | ||
}); | ||
}); | ||
describe(".makeRegex(), normal options, pattern '/*.js':", function(){ | ||
var ig = ignore(); | ||
var r_slash_wild_dot_js = ig.makeRegex('/*.js'); | ||
describe(".makeRegex(), normal options, pattern '/*.js':", function() { | ||
var ig = ignore(); | ||
var r_slash_wild_dot_js = ig.makeRegex('/*.js'); | ||
it("collection:", function(){ | ||
expect( r_slash_wild_dot_js.test('.js') ).to.equal(true); | ||
expect( r_slash_wild_dot_js.test('.js/') ).to.equal(true); | ||
expect( r_slash_wild_dot_js.test('.js/a') ).to.equal(true); | ||
expect( r_slash_wild_dot_js.test('a.js/a') ).to.equal(true); | ||
expect( r_slash_wild_dot_js.test('a.js/a.js') ).to.equal(true); | ||
it("collection:", function() { | ||
expect(r_slash_wild_dot_js.test('.js')).to.equal(true); | ||
expect(r_slash_wild_dot_js.test('.js/')).to.equal(true); | ||
expect(r_slash_wild_dot_js.test('.js/a')).to.equal(true); | ||
expect(r_slash_wild_dot_js.test('a.js/a')).to.equal(true); | ||
expect(r_slash_wild_dot_js.test('a.js/a.js')).to.equal(true); | ||
expect( r_slash_wild_dot_js.test('/.js') ).to.equal(false); | ||
expect( r_slash_wild_dot_js.test('.jsa') ).to.equal(false); | ||
}); | ||
expect(r_slash_wild_dot_js.test('/.js')).to.equal(false); | ||
expect(r_slash_wild_dot_js.test('.jsa')).to.equal(false); | ||
}); | ||
}); | ||
describe(".makeRegex(), normal options, pattern '*.js':", function(){ | ||
var ig = ignore(); | ||
var r_wild_dot_js = ig.makeRegex('*.js'); | ||
describe(".makeRegex(), normal options, pattern '*.js':", function() { | ||
var ig = ignore(); | ||
var r_wild_dot_js = ig.makeRegex('*.js'); | ||
it("collection:", function(){ | ||
expect( r_wild_dot_js.test('.js') ).to.equal(true); | ||
expect( r_wild_dot_js.test('.js/') ).to.equal(true); | ||
expect( r_wild_dot_js.test('.js/a') ).to.equal(true); | ||
expect( r_wild_dot_js.test('a.js/a') ).to.equal(true); | ||
expect( r_wild_dot_js.test('a.js/a.js') ).to.equal(true); | ||
expect( r_wild_dot_js.test('/.js') ).to.equal(true); | ||
it("collection:", function() { | ||
expect(r_wild_dot_js.test('.js')).to.equal(true); | ||
expect(r_wild_dot_js.test('.js/')).to.equal(true); | ||
expect(r_wild_dot_js.test('.js/a')).to.equal(true); | ||
expect(r_wild_dot_js.test('a.js/a')).to.equal(true); | ||
expect(r_wild_dot_js.test('a.js/a.js')).to.equal(true); | ||
expect(r_wild_dot_js.test('/.js')).to.equal(true); | ||
expect( r_wild_dot_js.test('.jsa') ).to.equal(false); | ||
}); | ||
expect(r_wild_dot_js.test('.jsa')).to.equal(false); | ||
}); | ||
}); | ||
describe(".makeRegex(), normal options, pattern '.js*':", function(){ | ||
var ig = ignore(); | ||
var r_dot_js_wild = ig.makeRegex('.js*'); | ||
describe(".makeRegex(), normal options, pattern '.js*':", function() { | ||
var ig = ignore(); | ||
var r_dot_js_wild = ig.makeRegex('.js*'); | ||
it("collection:", function(){ | ||
expect( r_dot_js_wild.test('.js') ).to.equal(true); | ||
expect( r_dot_js_wild.test('.js/') ).to.equal(true); | ||
expect( r_dot_js_wild.test('.js/a') ).to.equal(true); | ||
it("collection:", function() { | ||
expect(r_dot_js_wild.test('.js')).to.equal(true); | ||
expect(r_dot_js_wild.test('.js/')).to.equal(true); | ||
expect(r_dot_js_wild.test('.js/a')).to.equal(true); | ||
// pay attension | ||
expect( r_dot_js_wild.test('a.js/a') ).to.equal(false); | ||
expect( r_dot_js_wild.test('a.js/a.js') ).to.equal(false); | ||
// pay attension | ||
expect(r_dot_js_wild.test('a.js/a')).to.equal(false); | ||
expect(r_dot_js_wild.test('a.js/a.js')).to.equal(false); | ||
expect( r_dot_js_wild.test('/.js') ).to.equal(true); | ||
expect( r_dot_js_wild.test('.jsa') ).to.equal(true); | ||
}); | ||
expect(r_dot_js_wild.test('/.js')).to.equal(true); | ||
expect(r_dot_js_wild.test('.jsa')).to.equal(true); | ||
}); | ||
}); | ||
describe(".makeRegex(), normal options, pattern 'foo/**/':", function(){ | ||
var ig = ignore(); | ||
var r_foo_globstar_slash = ig.makeRegex('foo/**/'); | ||
describe(".makeRegex(), normal options, pattern 'foo/**/':", function() { | ||
var ig = ignore(); | ||
var r_foo_globstar_slash = ig.makeRegex('foo/**/'); | ||
it("should match 'foo/'", function(){ | ||
expect( r_foo_globstar_slash.test('foo/') ).to.equal(true); | ||
}); | ||
it("should match 'foo/'", function() { | ||
expect(r_foo_globstar_slash.test('foo/')).to.equal(true); | ||
}); | ||
it("should match 'foo/abc/'", function(){ | ||
expect( r_foo_globstar_slash.test('foo/abc/') ).to.equal(true); | ||
}); | ||
it("should match 'foo/abc/'", function() { | ||
expect(r_foo_globstar_slash.test('foo/abc/')).to.equal(true); | ||
}); | ||
it("should match 'foo/x/y/z/'", function(){ | ||
expect( r_foo_globstar_slash.test('foo/x/y/z/') ).to.equal(true); | ||
}); | ||
it("should match 'foo/x/y/z/'", function() { | ||
expect(r_foo_globstar_slash.test('foo/x/y/z/')).to.equal(true); | ||
}); | ||
it("should match 'foo/x/y/z/'", function(){ | ||
expect( r_foo_globstar_slash.test('foo/x/y/z/') ).to.equal(true); | ||
}); | ||
it("should match 'foo/x/y/z/'", function() { | ||
expect(r_foo_globstar_slash.test('foo/x/y/z/')).to.equal(true); | ||
}); | ||
it("should not match 'foo'", function(){ | ||
expect( r_foo_globstar_slash.test('foo') ).to.equal(false); | ||
}); | ||
it("should not match 'foo'", function() { | ||
expect(r_foo_globstar_slash.test('foo')).to.equal(false); | ||
}); | ||
it("should not match '/foo'", function(){ | ||
expect( r_foo_globstar_slash.test('/foo') ).to.equal(false); | ||
}); | ||
it("should not match '/foo'", function() { | ||
expect(r_foo_globstar_slash.test('/foo')).to.equal(false); | ||
}); | ||
}); | ||
@@ -185,212 +185,197 @@ | ||
var cases = [ | ||
// description patterns paths expect | ||
// [ | ||
// 'leading hash: will treat leading # as comments', | ||
// ['#abc'], | ||
// ['#abc'], | ||
// ['#abc'] | ||
// ], | ||
// [ | ||
// '\\#', | ||
// ['\\#abc'], | ||
// ['#abc'], | ||
// [] | ||
// ], | ||
// [ | ||
// 'could filter paths', | ||
// [ | ||
// 'abc', | ||
// '!abc/b' | ||
// ], | ||
// [ | ||
// 'abc/a.js', | ||
// 'abc/b/b.js' | ||
// ], | ||
// [ | ||
// 'abc/b/b.js' | ||
// ] | ||
// ], | ||
// [ | ||
// 'ignore.select', | ||
// ignore.select([ | ||
// 'test/fixtures/.aignore', | ||
// 'test/fixtures/.fakeignore' | ||
// ]), | ||
// [ | ||
// 'abc/a.js', | ||
// 'abc/b/b.js', | ||
// '#e', | ||
// '#f' | ||
// ], | ||
// ['abc/b/b.js', '#e'] | ||
// ], | ||
// [ | ||
// 'should excape metacharacters of regular expressions', | ||
// [ | ||
// '*.js', | ||
// '!\\*.js', | ||
// '!a#b.js', | ||
// '!?.js', | ||
// description patterns paths expect | ||
// [ | ||
// 'leading hash: will treat leading # as comments', | ||
// ['#abc'], | ||
// ['#abc'], | ||
// ['#abc'] | ||
// ], | ||
// [ | ||
// '\\#', | ||
// ['\\#abc'], | ||
// ['#abc'], | ||
// [] | ||
// ], | ||
// [ | ||
// 'could filter paths', | ||
// [ | ||
// 'abc', | ||
// '!abc/b' | ||
// ], | ||
// [ | ||
// 'abc/a.js', | ||
// 'abc/b/b.js' | ||
// ], | ||
// [ | ||
// 'abc/b/b.js' | ||
// ] | ||
// ], | ||
// [ | ||
// 'ignore.select', | ||
// ignore.select([ | ||
// 'test/fixtures/.aignore', | ||
// 'test/fixtures/.fakeignore' | ||
// ]), | ||
// [ | ||
// 'abc/a.js', | ||
// 'abc/b/b.js', | ||
// '#e', | ||
// '#f' | ||
// ], | ||
// ['abc/b/b.js', '#e'] | ||
// ], | ||
// [ | ||
// 'should excape metacharacters of regular expressions', | ||
// [ | ||
// '*.js', | ||
// '!\\*.js', | ||
// '!a#b.js', | ||
// '!?.js', | ||
// // comments | ||
// '#abc', | ||
// // comments | ||
// '#abc', | ||
// '\\#abc' | ||
// ], | ||
// [ | ||
// '*.js', | ||
// 'abc.js', | ||
// 'a#b.js', | ||
// 'abc', | ||
// '#abc', | ||
// '?.js' | ||
// ], | ||
// [ | ||
// '*.js', | ||
// 'abc', | ||
// 'a#b.js', | ||
// '?.js' | ||
// ] | ||
// ], | ||
// '\\#abc' | ||
// ], | ||
// [ | ||
// '*.js', | ||
// 'abc.js', | ||
// 'a#b.js', | ||
// 'abc', | ||
// '#abc', | ||
// '?.js' | ||
// ], | ||
// [ | ||
// '*.js', | ||
// 'abc', | ||
// 'a#b.js', | ||
// '?.js' | ||
// ] | ||
// ], | ||
// [ | ||
// 'issue #2: question mark should not break all things', | ||
// 'test/fixtures/.ignore-issue-2', | ||
// [ | ||
// '.project', | ||
// // remain | ||
// 'abc/.project', | ||
// '.a.sw', | ||
// '.a.sw?', | ||
// 'thumbs.db' | ||
// ], | ||
// [ | ||
// 'abc/.project', | ||
// '.a.sw', | ||
// // 'thumbs.db' | ||
// ] | ||
// ], | ||
[ | ||
'dir ended with "*"', | ||
[ | ||
'abc/*' | ||
], | ||
{ | ||
'abc': 0 | ||
} | ||
], | ||
[ | ||
'file ended with "*"', | ||
[ | ||
'abc.js*', | ||
], | ||
{ | ||
'abc.js/': 1, | ||
'abc.js/abc': 1, | ||
'abc.jsa/': 1, | ||
'abc.jsa/abc': 1 | ||
} | ||
], | ||
[ | ||
'wildcard as filename', | ||
[ | ||
'*.b' | ||
], | ||
{ | ||
'b/a.b': 1, | ||
'b/.b': 1, | ||
'b/.ba': 0, | ||
'b/c/a.b': 1 | ||
} | ||
], | ||
[ | ||
'slash at the beginning and come with a wildcard', | ||
[ | ||
'/*.c' | ||
], | ||
{ | ||
'.c': 1, | ||
'c.c': 1, | ||
'c/c.c': 0, | ||
'c/d': 0 | ||
} | ||
], | ||
[ | ||
'dot file', | ||
[ | ||
'.d' | ||
], | ||
{ | ||
'.d': 1, | ||
'.dd': 0, | ||
'd.d': 0, | ||
'd/.d': 1, | ||
'd/d.d': 0, | ||
'd/e': 0 | ||
} | ||
], | ||
[ | ||
'dot dir', | ||
[ | ||
'.e' | ||
], | ||
{ | ||
'.e/': 1, | ||
'.ee/': 0, | ||
'e.e/': 0, | ||
'.e/e': 1, | ||
'e/.e': 1, | ||
'e/e.e': 0, | ||
'e/f': 0 | ||
} | ||
] | ||
// [ | ||
// 'issue #2: question mark should not break all things', | ||
// 'test/fixtures/.ignore-issue-2', | ||
// [ | ||
// '.project', | ||
// // remain | ||
// 'abc/.project', | ||
// '.a.sw', | ||
// '.a.sw?', | ||
// 'thumbs.db' | ||
// ], | ||
// [ | ||
// 'abc/.project', | ||
// '.a.sw', | ||
// // 'thumbs.db' | ||
// ] | ||
// ], | ||
[ | ||
'dir ended with "*"', [ | ||
'abc/*' | ||
], { | ||
'abc': 0 | ||
} | ||
], | ||
[ | ||
'file ended with "*"', [ | ||
'abc.js*', | ||
], { | ||
'abc.js/': 1, | ||
'abc.js/abc': 1, | ||
'abc.jsa/': 1, | ||
'abc.jsa/abc': 1 | ||
} | ||
], | ||
[ | ||
'wildcard as filename', [ | ||
'*.b' | ||
], { | ||
'b/a.b': 1, | ||
'b/.b': 1, | ||
'b/.ba': 0, | ||
'b/c/a.b': 1 | ||
} | ||
], | ||
[ | ||
'slash at the beginning and come with a wildcard', [ | ||
'/*.c' | ||
], { | ||
'.c': 1, | ||
'c.c': 1, | ||
'c/c.c': 0, | ||
'c/d': 0 | ||
} | ||
], | ||
[ | ||
'dot file', [ | ||
'.d' | ||
], { | ||
'.d': 1, | ||
'.dd': 0, | ||
'd.d': 0, | ||
'd/.d': 1, | ||
'd/d.d': 0, | ||
'd/e': 0 | ||
} | ||
], | ||
[ | ||
'dot dir', [ | ||
'.e' | ||
], { | ||
'.e/': 1, | ||
'.ee/': 0, | ||
'e.e/': 0, | ||
'.e/e': 1, | ||
'e/.e': 1, | ||
'e/e.e': 0, | ||
'e/f': 0 | ||
} | ||
] | ||
]; | ||
function readPatterns (file) { | ||
var content = fs.readFileSync(file); | ||
function readPatterns(file) { | ||
var content = fs.readFileSync(file); | ||
return content | ||
? content.toString().split(/\r?\n/) | ||
: []; | ||
return content ? content.toString().split(/\r?\n/) : []; | ||
} | ||
describe("cases", function(){ | ||
cases.forEach(function (c) { | ||
var description = c[0]; | ||
var patterns = c[1]; | ||
var paths_object = c[2]; | ||
describe("cases", function() { | ||
cases.forEach(function(c) { | ||
var description = c[0]; | ||
var patterns = c[1]; | ||
var paths_object = c[2]; | ||
if ( typeof patterns === 'string' ) { | ||
patterns = readPatterns(patterns); | ||
} | ||
if (typeof patterns === 'string') { | ||
patterns = readPatterns(patterns); | ||
} | ||
it('.filter(): ' + description, function(){ | ||
var paths = Object.keys(paths_object); | ||
it('.filter(): ' + description, function() { | ||
var paths = Object.keys(paths_object); | ||
var result = ignore() | ||
.addPattern(patterns) | ||
.filter(paths); | ||
var result = ignore() | ||
.addPattern(patterns) | ||
.filter(paths); | ||
var expected = paths.filter(function (p) { | ||
return !paths_object[p]; | ||
}); | ||
var expected = paths.filter(function(p) { | ||
return !paths_object[p]; | ||
}); | ||
expect(result.sort()).to.deep.equal(expected.sort()); | ||
}); | ||
expect(result.sort()).to.deep.equal(expected.sort()); | ||
}); | ||
// it(".createFilter(): " + description, function(){ | ||
// var result = paths.filter( | ||
// ignore() | ||
// .addPattern(patterns) | ||
// .createFilter(), | ||
// // thisArg should be binded | ||
// null | ||
// ); | ||
// it(".createFilter(): " + description, function(){ | ||
// var result = paths.filter( | ||
// ignore() | ||
// .addPattern(patterns) | ||
// .createFilter(), | ||
// // thisArg should be binded | ||
// null | ||
// ); | ||
// expect(result.sort()).to.deep.equal(expected.sort()); | ||
// }); | ||
}); | ||
}); | ||
// expect(result.sort()).to.deep.equal(expected.sort()); | ||
// }); | ||
}); | ||
}); |
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
24634
595