Skip to content
Compile an ignore file (similar to .gitignore) to a Javascript function
JavaScript
Find file
Latest commit df0a0ce Jul 21, 2015 @mafintosh Merge pull request #2 from indexzero/alt-line-ending-test
Show that \r\n based line-endings also work.
Failed to load latest commit information.
.gitignore
.travis.yml added travis May 30, 2014
LICENSE
README.md
index.js
package.json
test.js

README.md

ignore-file

Compile an ignore file (similar to .gitignore) to a Javascript function that returns true or false given a filename

npm install ignore-file

build status

Usage

Assuming you have a .gitignore file in your current working directory that contains node_modules do

var ignore = require('ignore-file')

ignore('.gitignore', function(err, filter) {
  if (err) throw err
  console.log(filter('index.js'))     // returns false
  console.log(filter('node_modules')) // returns true
})

You can also use ignore.sync(filename) to synchroniously compile an ignore file If the file doesn't exist null is returned. This allows you easily implement fallbacks

var filter = ignore.sync('.npmignore') || ignore.sync('.gitignore') || ignore.compile('node_modules')

The above will use .npmignore if it exists, else .gitignore and finally just ignore all node_modules folders

License

MIT

Something went wrong with that request. Please try again.