Skip to content

Instantly share code, notes, and snippets.

@mhkeller
Created August 9, 2016 15:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mhkeller/e20b7f85301e012e7d9ff9b8718fdd26 to your computer and use it in GitHub Desktop.
Save mhkeller/e20b7f85301e012e7d9ff9b8718fdd26 to your computer and use it in GitHub Desktop.
// --------------------------------------------
//
// A module for generating an `anymatch` ignore function https://github.com/es128/anymatch
// that ignores files whose parent contains a dir with a given prefix
//
// --------------------------------------------
var path = require('path')
var _ = require('underscore')
// --------------------------------------------
// Set up our defaults
// `root` is a part of the path that is ignored
// `prefix` is our string to look at
//
var defaults = {
root: '',
prefix: '_'
}
// --------------------------------------------
//
// Our main function
//
// --------------------------------------------
module.exports = function (config) {
_.defaults(config, defaults)
return function (str) {
var uniformStr = str.replace(config.root, '')
var parts = uniformStr.split(path.sep)
return parts.some(function (part) {
return part.substr(0, config.prefix.length) === config.prefix
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment