mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-17 08:05:19 +00:00
43 lines
828 B
JavaScript
43 lines
828 B
JavaScript
var Immutable = require('immutable');
|
|
var IgnoreMutable = require('ignore');
|
|
|
|
/*
|
|
Immutable version of node-ignore
|
|
*/
|
|
var Ignore = Immutable.Record({
|
|
ignore: new IgnoreMutable()
|
|
}, 'Ignore');
|
|
|
|
Ignore.prototype.getIgnore = function() {
|
|
return this.get('ignore');
|
|
};
|
|
|
|
/**
|
|
Test if a file is ignored by these rules
|
|
|
|
@param {String} filePath
|
|
@return {Boolean}
|
|
*/
|
|
Ignore.prototype.isFileIgnored = function(filename) {
|
|
var ignore = this.getIgnore();
|
|
return ignore.filter([filename]).length == 0;
|
|
};
|
|
|
|
/**
|
|
Add rules
|
|
|
|
@param {String}
|
|
@return {Ignore}
|
|
*/
|
|
Ignore.prototype.add = function(rule) {
|
|
var ignore = this.getIgnore();
|
|
var newIgnore = new IgnoreMutable();
|
|
|
|
newIgnore.add(ignore);
|
|
newIgnore.add(rule);
|
|
|
|
return this.set('ignore', newIgnore);
|
|
};
|
|
|
|
module.exports = Ignore;
|