| | |
| | | }); |
| | | }; |
| | | |
| | | var REGEX_REGEXP_RANGE = /([0-z])-([0-z])/g; // Sanitize the range of a regular expression |
| | | var REGEX_REGEXP_RANGE = /([0-z])-([0-z])/g; |
| | | |
| | | var RETURN_FALSE = function RETURN_FALSE() { |
| | | return false; |
| | | }; // Sanitize the range of a regular expression |
| | | // The cases are complicated, see test cases for details |
| | | |
| | | |
| | | var sanitizeRange = function sanitizeRange(range) { |
| | | return range.replace(REGEX_REGEXP_RANGE, function (match, from, to) { |
| | |
| | | |
| | | var regexCache = Object.create(null); // @param {pattern} |
| | | |
| | | var makeRegex = function makeRegex(pattern, negative, ignorecase) { |
| | | var r = regexCache[pattern]; |
| | | var makeRegex = function makeRegex(pattern, ignoreCase) { |
| | | var source = regexCache[pattern]; |
| | | |
| | | if (r) { |
| | | return r; |
| | | } // const replacers = negative |
| | | // ? NEGATIVE_REPLACERS |
| | | // : POSITIVE_REPLACERS |
| | | if (!source) { |
| | | source = REPLACERS.reduce(function (prev, current) { |
| | | return prev.replace(current[0], current[1].bind(pattern)); |
| | | }, pattern); |
| | | regexCache[pattern] = source; |
| | | } |
| | | |
| | | |
| | | var source = REPLACERS.reduce(function (prev, current) { |
| | | return prev.replace(current[0], current[1].bind(pattern)); |
| | | }, pattern); |
| | | return regexCache[pattern] = ignorecase ? new RegExp(source, 'i') : new RegExp(source); |
| | | return ignoreCase ? new RegExp(source, 'i') : new RegExp(source); |
| | | }; |
| | | |
| | | var isString = function isString(subject) { |
| | |
| | | this.regex = regex; |
| | | }; |
| | | |
| | | var createRule = function createRule(pattern, ignorecase) { |
| | | var createRule = function createRule(pattern, ignoreCase) { |
| | | var origin = pattern; |
| | | var negative = false; // > An optional prefix "!" which negates the pattern; |
| | | |
| | |
| | | .replace(REGEX_REPLACE_LEADING_EXCAPED_EXCLAMATION, '!') // > Put a backslash ("\") in front of the first hash for patterns that |
| | | // > begin with a hash. |
| | | .replace(REGEX_REPLACE_LEADING_EXCAPED_HASH, '#'); |
| | | var regex = makeRegex(pattern, negative, ignorecase); |
| | | var regex = makeRegex(pattern, ignoreCase); |
| | | return new IgnoreRule(origin, pattern, negative, regex); |
| | | }; |
| | | |
| | |
| | | function Ignore() { |
| | | var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, |
| | | _ref$ignorecase = _ref.ignorecase, |
| | | ignorecase = _ref$ignorecase === void 0 ? true : _ref$ignorecase; |
| | | ignorecase = _ref$ignorecase === void 0 ? true : _ref$ignorecase, |
| | | _ref$ignoreCase = _ref.ignoreCase, |
| | | ignoreCase = _ref$ignoreCase === void 0 ? ignorecase : _ref$ignoreCase, |
| | | _ref$allowRelativePat = _ref.allowRelativePaths, |
| | | allowRelativePaths = _ref$allowRelativePat === void 0 ? false : _ref$allowRelativePat; |
| | | |
| | | _classCallCheck(this, Ignore); |
| | | |
| | | this._rules = []; |
| | | this._ignorecase = ignorecase; |
| | | define(this, KEY_IGNORE, true); |
| | | this._rules = []; |
| | | this._ignoreCase = ignoreCase; |
| | | this._allowRelativePaths = allowRelativePaths; |
| | | |
| | | this._initCache(); |
| | | } |
| | |
| | | } |
| | | |
| | | if (checkPattern(pattern)) { |
| | | var rule = createRule(pattern, this._ignorecase); |
| | | var rule = createRule(pattern, this._ignoreCase); |
| | | this._added = true; |
| | | |
| | | this._rules.push(rule); |
| | |
| | | value: function _test(originalPath, cache, checkUnignored, slices) { |
| | | var path = originalPath // 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); |
| | | } |
| | | }, { |
| | |
| | | return new Ignore(options); |
| | | }; |
| | | |
| | | var returnFalse = function returnFalse() { |
| | | return false; |
| | | }; |
| | | |
| | | var isPathValid = function isPathValid(path) { |
| | | return checkPath(path && checkPath.convert(path), path, returnFalse); |
| | | return checkPath(path && checkPath.convert(path), path, RETURN_FALSE); |
| | | }; |
| | | |
| | | factory.isPathValid = isPathValid; // Fixes typescript |