| | |
| | | |
| | | const REGEX_REGEXP_RANGE = /([0-z])-([0-z])/g |
| | | |
| | | const RETURN_FALSE = () => false |
| | | |
| | | // Sanitize the range of a regular expression |
| | | // The cases are complicated, see test cases for details |
| | | const sanitizeRange = range => range.replace( |
| | |
| | | const regexCache = Object.create(null) |
| | | |
| | | // @param {pattern} |
| | | const makeRegex = (pattern, negative, ignorecase) => { |
| | | const r = regexCache[pattern] |
| | | if (r) { |
| | | return r |
| | | const makeRegex = (pattern, ignoreCase) => { |
| | | let source = regexCache[pattern] |
| | | |
| | | if (!source) { |
| | | source = REPLACERS.reduce( |
| | | (prev, current) => prev.replace(current[0], current[1].bind(pattern)), |
| | | pattern |
| | | ) |
| | | regexCache[pattern] = source |
| | | } |
| | | |
| | | // const replacers = negative |
| | | // ? NEGATIVE_REPLACERS |
| | | // : POSITIVE_REPLACERS |
| | | |
| | | const source = REPLACERS.reduce( |
| | | (prev, current) => prev.replace(current[0], current[1].bind(pattern)), |
| | | pattern |
| | | ) |
| | | |
| | | return regexCache[pattern] = ignorecase |
| | | return ignoreCase |
| | | ? new RegExp(source, 'i') |
| | | : new RegExp(source) |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | const createRule = (pattern, ignorecase) => { |
| | | const createRule = (pattern, ignoreCase) => { |
| | | const origin = pattern |
| | | let negative = false |
| | | |
| | |
| | | // > begin with a hash. |
| | | .replace(REGEX_REPLACE_LEADING_EXCAPED_HASH, '#') |
| | | |
| | | const regex = makeRegex(pattern, negative, ignorecase) |
| | | const regex = makeRegex(pattern, ignoreCase) |
| | | |
| | | return new IgnoreRule( |
| | | origin, |
| | |
| | | |
| | | class Ignore { |
| | | constructor ({ |
| | | ignorecase = true |
| | | ignorecase = true, |
| | | ignoreCase = ignorecase, |
| | | allowRelativePaths = false |
| | | } = {}) { |
| | | this._rules = [] |
| | | this._ignorecase = ignorecase |
| | | define(this, KEY_IGNORE, true) |
| | | |
| | | this._rules = [] |
| | | this._ignoreCase = ignoreCase |
| | | this._allowRelativePaths = allowRelativePaths |
| | | this._initCache() |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | if (checkPattern(pattern)) { |
| | | const rule = createRule(pattern, this._ignorecase) |
| | | const rule = createRule(pattern, this._ignoreCase) |
| | | this._added = true |
| | | this._rules.push(rule) |
| | | } |
| | |
| | | // Supports nullable path |
| | | && checkPath.convert(originalPath) |
| | | |
| | | checkPath(path, originalPath, throwError) |
| | | checkPath( |
| | | path, |
| | | originalPath, |
| | | this._allowRelativePaths |
| | | ? RETURN_FALSE |
| | | : throwError |
| | | ) |
| | | |
| | | return this._t(path, cache, checkUnignored, slices) |
| | | } |
| | |
| | | |
| | | const factory = options => new Ignore(options) |
| | | |
| | | const returnFalse = () => false |
| | | |
| | | const isPathValid = path => |
| | | checkPath(path && checkPath.convert(path), path, returnFalse) |
| | | checkPath(path && checkPath.convert(path), path, RETURN_FALSE) |
| | | |
| | | factory.isPathValid = isPathValid |
| | | |