Created
August 9, 2016 15:43
-
-
Save mhkeller/e20b7f85301e012e7d9ff9b8718fdd26 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// -------------------------------------------- | |
// | |
// 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