ignore
ignore
is a manager and filter for .gitignore rules.
Installation
npm install ignore --save
Usage
var ignore = require('ignore');
var ig = ignore({
ignore: [
'.abc/*'
]
}).add('!.abc/d/');
var paths = [
'.abc/a.js',
'.abc/d/e.js'
];
ig.filter(paths);
paths.filter(ig.createFilter());
Why another ignore?
-
ignore
is a standalone module, and is much simpler so that it could easily work with other programs, unlike isaacs's fstream-ignore which must work with the modules of the fstream family.
-
ignore
only contains utility methods to filter paths according to the specified ignore rules.
-
Exactly according to gitignore man page, fixes some known matching issues of fstream-ignore, such as:
- '
/*.js
' should match 'a.js
', but not 'abc/a.js
'. - '
**/foo
' should match 'foo
' anywhere.
Methods
.add(rule)
Adds a rule or several rules to the current manager.
Returns this
Rule String|Array.<String>
The ignore rule or a array of rules.
.filter(paths)
Filters the given array of pathnames, and returns the filtered array.
paths Array
The array of paths to be filtered
.createFilter()
Creates a filter function which could be used with Array.prototype.filter
.
Returns function(path)
The filter function.
Constructor: ignore.Ignore
new ignore.Ignore(options);
ignore(options);
options.noCase boolean=true
By default, all ignore rules will be treated as case-insensitive ones as well as the git does.
options.twoGlobstars boolean=false
By defailt, ignoreRules
will omit every pattern that includes '**
' (two consecutive asterisks) which is not compatible cross operating systems, because the behavior of file .gitignore depends on the implementation of command fnmatch
in shell.
By the way, Mac OS doesn't support '**
'.
options.ignore Array.<String>
The ignore rules to be added.
You can also use .add()
method to do this.