source: imaps-frontend/node_modules/ignore/legacy.js@ 0c6b92a

main
Last change on this file since 0c6b92a was 0c6b92a, checked in by stefan toskovski <stefantoska84@…>, 5 weeks ago

Pred finalna verzija

  • Property mode set to 100644
File size: 20.3 KB
RevLine 
[d565449]1"use strict";
2
3function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
4function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
5function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
6function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
7function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
8function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
[0c6b92a]9function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
10function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
11function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
12function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
13function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i["return"] && (_r = _i["return"](), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
14function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
[d565449]15// A simple implementation of make-array
16function makeArray(subject) {
17 return Array.isArray(subject) ? subject : [subject];
18}
19var EMPTY = '';
20var SPACE = ' ';
21var ESCAPE = '\\';
22var REGEX_TEST_BLANK_LINE = /^\s+$/;
23var REGEX_INVALID_TRAILING_BACKSLASH = /(?:[^\\]|^)\\$/;
24var REGEX_REPLACE_LEADING_EXCAPED_EXCLAMATION = /^\\!/;
25var REGEX_REPLACE_LEADING_EXCAPED_HASH = /^\\#/;
26var REGEX_SPLITALL_CRLF = /\r?\n/g;
27// /foo,
28// ./foo,
29// ../foo,
30// .
31// ..
32var REGEX_TEST_INVALID_PATH = /^\.*\/|^\.+$/;
33var SLASH = '/';
34
35// Do not use ternary expression here, since "istanbul ignore next" is buggy
36var TMP_KEY_IGNORE = 'node-ignore';
37/* istanbul ignore else */
38if (typeof Symbol !== 'undefined') {
39 TMP_KEY_IGNORE = Symbol["for"]('node-ignore');
40}
41var KEY_IGNORE = TMP_KEY_IGNORE;
42var define = function define(object, key, value) {
43 return Object.defineProperty(object, key, {
44 value: value
45 });
46};
47var REGEX_REGEXP_RANGE = /([0-z])-([0-z])/g;
48var RETURN_FALSE = function RETURN_FALSE() {
49 return false;
50};
51
52// Sanitize the range of a regular expression
53// The cases are complicated, see test cases for details
54var sanitizeRange = function sanitizeRange(range) {
55 return range.replace(REGEX_REGEXP_RANGE, function (match, from, to) {
56 return from.charCodeAt(0) <= to.charCodeAt(0) ? match
57 // Invalid range (out of order) which is ok for gitignore rules but
58 // fatal for JavaScript regular expression, so eliminate it.
59 : EMPTY;
60 });
61};
62
63// See fixtures #59
64var cleanRangeBackSlash = function cleanRangeBackSlash(slashes) {
65 var length = slashes.length;
66 return slashes.slice(0, length - length % 2);
67};
68
69// > If the pattern ends with a slash,
70// > it is removed for the purpose of the following description,
71// > but it would only find a match with a directory.
72// > In other words, foo/ will match a directory foo and paths underneath it,
73// > but will not match a regular file or a symbolic link foo
74// > (this is consistent with the way how pathspec works in general in Git).
75// '`foo/`' will not match regular file '`foo`' or symbolic link '`foo`'
76// -> ignore-rules will not deal with it, because it costs extra `fs.stat` call
77// you could use option `mark: true` with `glob`
78
79// '`foo/`' should not continue with the '`..`'
80var REPLACERS = [[
81// remove BOM
82// TODO:
83// Other similar zero-width characters?
84/^\uFEFF/, function () {
85 return EMPTY;
86}],
87// > Trailing spaces are ignored unless they are quoted with backslash ("\")
88[
89// (a\ ) -> (a )
90// (a ) -> (a)
[0c6b92a]91// (a ) -> (a)
[d565449]92// (a \ ) -> (a )
[0c6b92a]93/((?:\\\\)*?)(\\?\s+)$/, function (_, m1, m2) {
94 return m1 + (m2.indexOf('\\') === 0 ? SPACE : EMPTY);
[d565449]95}],
96// replace (\ ) with ' '
[0c6b92a]97// (\ ) -> ' '
98// (\\ ) -> '\\ '
99// (\\\ ) -> '\\ '
100[/(\\+?)\s/g, function (_, m1) {
101 var length = m1.length;
102 return m1.slice(0, length - length % 2) + SPACE;
[d565449]103}],
104// Escape metacharacters
105// which is written down by users but means special for regular expressions.
106
107// > There are 12 characters with special meanings:
108// > - the backslash \,
109// > - the caret ^,
110// > - the dollar sign $,
111// > - the period or dot .,
112// > - the vertical bar or pipe symbol |,
113// > - the question mark ?,
114// > - the asterisk or star *,
115// > - the plus sign +,
116// > - the opening parenthesis (,
117// > - the closing parenthesis ),
118// > - and the opening square bracket [,
119// > - the opening curly brace {,
120// > These special characters are often called "metacharacters".
121[/[\\$.|*+(){^]/g, function (match) {
122 return "\\".concat(match);
123}], [
124// > a question mark (?) matches a single character
125/(?!\\)\?/g, function () {
126 return '[^/]';
127}],
128// leading slash
129[
130// > A leading slash matches the beginning of the pathname.
131// > For example, "/*.c" matches "cat-file.c" but not "mozilla-sha1/sha1.c".
132// A leading slash matches the beginning of the pathname
133/^\//, function () {
134 return '^';
135}],
136// replace special metacharacter slash after the leading slash
137[/\//g, function () {
138 return '\\/';
139}], [
140// > A leading "**" followed by a slash means match in all directories.
141// > For example, "**/foo" matches file or directory "foo" anywhere,
142// > the same as pattern "foo".
143// > "**/foo/bar" matches file or directory "bar" anywhere that is directly
144// > under directory "foo".
145// Notice that the '*'s have been replaced as '\\*'
146/^\^*\\\*\\\*\\\//,
147// '**/foo' <-> 'foo'
148function () {
149 return '^(?:.*\\/)?';
150}],
151// starting
152[
153// there will be no leading '/'
154// (which has been replaced by section "leading slash")
155// If starts with '**', adding a '^' to the regular expression also works
156/^(?=[^^])/, function startingReplacer() {
157 // If has a slash `/` at the beginning or middle
158 return !/\/(?!$)/.test(this)
159 // > Prior to 2.22.1
160 // > If the pattern does not contain a slash /,
161 // > Git treats it as a shell glob pattern
162 // Actually, if there is only a trailing slash,
163 // git also treats it as a shell glob pattern
164
165 // After 2.22.1 (compatible but clearer)
166 // > If there is a separator at the beginning or middle (or both)
167 // > of the pattern, then the pattern is relative to the directory
168 // > level of the particular .gitignore file itself.
169 // > Otherwise the pattern may also match at any level below
170 // > the .gitignore level.
171 ? '(?:^|\\/)'
172
173 // > Otherwise, Git treats the pattern as a shell glob suitable for
174 // > consumption by fnmatch(3)
175 : '^';
176}],
177// two globstars
178[
179// Use lookahead assertions so that we could match more than one `'/**'`
180/\\\/\\\*\\\*(?=\\\/|$)/g,
181// Zero, one or several directories
182// should not use '*', or it will be replaced by the next replacer
183
184// Check if it is not the last `'/**'`
185function (_, index, str) {
186 return index + 6 < str.length
187
188 // case: /**/
189 // > A slash followed by two consecutive asterisks then a slash matches
190 // > zero or more directories.
191 // > For example, "a/**/b" matches "a/b", "a/x/b", "a/x/y/b" and so on.
192 // '/**/'
193 ? '(?:\\/[^\\/]+)*'
194
195 // case: /**
196 // > A trailing `"/**"` matches everything inside.
197
198 // #21: everything inside but it should not include the current folder
199 : '\\/.+';
200}],
201// normal intermediate wildcards
202[
203// Never replace escaped '*'
204// ignore rule '\*' will match the path '*'
205
206// 'abc.*/' -> go
207// 'abc.*' -> skip this rule,
208// coz trailing single wildcard will be handed by [trailing wildcard]
209/(^|[^\\]+)(\\\*)+(?=.+)/g,
210// '*.js' matches '.js'
211// '*.js' doesn't match 'abc'
212function (_, p1, p2) {
213 // 1.
214 // > An asterisk "*" matches anything except a slash.
215 // 2.
216 // > Other consecutive asterisks are considered regular asterisks
217 // > and will match according to the previous rules.
218 var unescaped = p2.replace(/\\\*/g, '[^\\/]*');
219 return p1 + unescaped;
220}], [
221// unescape, revert step 3 except for back slash
222// For example, if a user escape a '\\*',
223// after step 3, the result will be '\\\\\\*'
224/\\\\\\(?=[$.|*+(){^])/g, function () {
225 return ESCAPE;
226}], [
227// '\\\\' -> '\\'
228/\\\\/g, function () {
229 return ESCAPE;
230}], [
231// > The range notation, e.g. [a-zA-Z],
232// > can be used to match one of the characters in a range.
233
234// `\` is escaped by step 3
235/(\\)?\[([^\]/]*?)(\\*)($|\])/g, function (match, leadEscape, range, endEscape, close) {
236 return leadEscape === ESCAPE
237 // '\\[bar]' -> '\\\\[bar\\]'
238 ? "\\[".concat(range).concat(cleanRangeBackSlash(endEscape)).concat(close) : close === ']' ? endEscape.length % 2 === 0
239 // A normal case, and it is a range notation
240 // '[bar]'
241 // '[bar\\\\]'
242 ? "[".concat(sanitizeRange(range)).concat(endEscape, "]") // Invalid range notaton
243 // '[bar\\]' -> '[bar\\\\]'
244 : '[]' : '[]';
245}],
246// ending
247[
248// 'js' will not match 'js.'
249// 'ab' will not match 'abc'
250/(?:[^*])$/,
251// WTF!
252// https://git-scm.com/docs/gitignore
253// changes in [2.22.1](https://git-scm.com/docs/gitignore/2.22.1)
254// which re-fixes #24, #38
255
256// > If there is a separator at the end of the pattern then the pattern
257// > will only match directories, otherwise the pattern can match both
258// > files and directories.
259
260// 'js*' will not match 'a.js'
261// 'js/' will not match 'a.js'
262// 'js' will match 'a.js' and 'a.js/'
263function (match) {
264 return /\/$/.test(match)
265 // foo/ will not match 'foo'
266 ? "".concat(match, "$") // foo matches 'foo' and 'foo/'
267 : "".concat(match, "(?=$|\\/$)");
268}],
269// trailing wildcard
270[/(\^|\\\/)?\\\*$/, function (_, p1) {
271 var prefix = p1
272 // '\^':
273 // '/*' does not match EMPTY
274 // '/*' does not match everything
275
276 // '\\\/':
277 // 'abc/*' does not match 'abc/'
278 ? "".concat(p1, "[^/]+") // 'a*' matches 'a'
279 // 'a*' matches 'aa'
280 : '[^/]*';
281 return "".concat(prefix, "(?=$|\\/$)");
282}]];
283
284// A simple cache, because an ignore rule only has only one certain meaning
285var regexCache = Object.create(null);
286
287// @param {pattern}
288var makeRegex = function makeRegex(pattern, ignoreCase) {
289 var source = regexCache[pattern];
290 if (!source) {
[0c6b92a]291 source = REPLACERS.reduce(function (prev, _ref) {
292 var _ref2 = _slicedToArray(_ref, 2),
293 matcher = _ref2[0],
294 replacer = _ref2[1];
295 return prev.replace(matcher, replacer.bind(pattern));
[d565449]296 }, pattern);
297 regexCache[pattern] = source;
298 }
299 return ignoreCase ? new RegExp(source, 'i') : new RegExp(source);
300};
301var isString = function isString(subject) {
302 return typeof subject === 'string';
303};
304
305// > A blank line matches no files, so it can serve as a separator for readability.
306var checkPattern = function checkPattern(pattern) {
307 return pattern && isString(pattern) && !REGEX_TEST_BLANK_LINE.test(pattern) && !REGEX_INVALID_TRAILING_BACKSLASH.test(pattern)
308
309 // > A line starting with # serves as a comment.
310 && pattern.indexOf('#') !== 0;
311};
312var splitPattern = function splitPattern(pattern) {
313 return pattern.split(REGEX_SPLITALL_CRLF);
314};
315var IgnoreRule = /*#__PURE__*/_createClass(function IgnoreRule(origin, pattern, negative, regex) {
316 _classCallCheck(this, IgnoreRule);
317 this.origin = origin;
318 this.pattern = pattern;
319 this.negative = negative;
320 this.regex = regex;
321});
322var createRule = function createRule(pattern, ignoreCase) {
323 var origin = pattern;
324 var negative = false;
325
326 // > An optional prefix "!" which negates the pattern;
327 if (pattern.indexOf('!') === 0) {
328 negative = true;
329 pattern = pattern.substr(1);
330 }
331 pattern = pattern
332 // > Put a backslash ("\") in front of the first "!" for patterns that
333 // > begin with a literal "!", for example, `"\!important!.txt"`.
334 .replace(REGEX_REPLACE_LEADING_EXCAPED_EXCLAMATION, '!')
335 // > Put a backslash ("\") in front of the first hash for patterns that
336 // > begin with a hash.
337 .replace(REGEX_REPLACE_LEADING_EXCAPED_HASH, '#');
338 var regex = makeRegex(pattern, ignoreCase);
339 return new IgnoreRule(origin, pattern, negative, regex);
340};
341var throwError = function throwError(message, Ctor) {
342 throw new Ctor(message);
343};
344var checkPath = function checkPath(path, originalPath, doThrow) {
345 if (!isString(path)) {
346 return doThrow("path must be a string, but got `".concat(originalPath, "`"), TypeError);
347 }
348
349 // We don't know if we should ignore EMPTY, so throw
350 if (!path) {
351 return doThrow("path must not be empty", TypeError);
352 }
353
354 // Check if it is a relative path
355 if (checkPath.isNotRelative(path)) {
356 var r = '`path.relative()`d';
357 return doThrow("path should be a ".concat(r, " string, but got \"").concat(originalPath, "\""), RangeError);
358 }
359 return true;
360};
361var isNotRelative = function isNotRelative(path) {
362 return REGEX_TEST_INVALID_PATH.test(path);
363};
364checkPath.isNotRelative = isNotRelative;
365checkPath.convert = function (p) {
366 return p;
367};
368var Ignore = /*#__PURE__*/function () {
369 function Ignore() {
[0c6b92a]370 var _ref3 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
371 _ref3$ignorecase = _ref3.ignorecase,
372 ignorecase = _ref3$ignorecase === void 0 ? true : _ref3$ignorecase,
373 _ref3$ignoreCase = _ref3.ignoreCase,
374 ignoreCase = _ref3$ignoreCase === void 0 ? ignorecase : _ref3$ignoreCase,
375 _ref3$allowRelativePa = _ref3.allowRelativePaths,
376 allowRelativePaths = _ref3$allowRelativePa === void 0 ? false : _ref3$allowRelativePa;
[d565449]377 _classCallCheck(this, Ignore);
378 define(this, KEY_IGNORE, true);
379 this._rules = [];
380 this._ignoreCase = ignoreCase;
381 this._allowRelativePaths = allowRelativePaths;
382 this._initCache();
383 }
384 _createClass(Ignore, [{
385 key: "_initCache",
386 value: function _initCache() {
387 this._ignoreCache = Object.create(null);
388 this._testCache = Object.create(null);
389 }
390 }, {
391 key: "_addPattern",
392 value: function _addPattern(pattern) {
393 // #32
394 if (pattern && pattern[KEY_IGNORE]) {
395 this._rules = this._rules.concat(pattern._rules);
396 this._added = true;
397 return;
398 }
399 if (checkPattern(pattern)) {
400 var rule = createRule(pattern, this._ignoreCase);
401 this._added = true;
402 this._rules.push(rule);
403 }
404 }
405
406 // @param {Array<string> | string | Ignore} pattern
407 }, {
408 key: "add",
409 value: function add(pattern) {
410 this._added = false;
411 makeArray(isString(pattern) ? splitPattern(pattern) : pattern).forEach(this._addPattern, this);
412
413 // Some rules have just added to the ignore,
414 // making the behavior changed.
415 if (this._added) {
416 this._initCache();
417 }
418 return this;
419 }
420
421 // legacy
422 }, {
423 key: "addPattern",
424 value: function addPattern(pattern) {
425 return this.add(pattern);
426 }
427
428 // | ignored : unignored
429 // negative | 0:0 | 0:1 | 1:0 | 1:1
430 // -------- | ------- | ------- | ------- | --------
431 // 0 | TEST | TEST | SKIP | X
432 // 1 | TESTIF | SKIP | TEST | X
433
434 // - SKIP: always skip
435 // - TEST: always test
436 // - TESTIF: only test if checkUnignored
437 // - X: that never happen
438
439 // @param {boolean} whether should check if the path is unignored,
440 // setting `checkUnignored` to `false` could reduce additional
441 // path matching.
442
443 // @returns {TestResult} true if a file is ignored
444 }, {
445 key: "_testOne",
446 value: function _testOne(path, checkUnignored) {
447 var ignored = false;
448 var unignored = false;
449 this._rules.forEach(function (rule) {
450 var negative = rule.negative;
451 if (unignored === negative && ignored !== unignored || negative && !ignored && !unignored && !checkUnignored) {
452 return;
453 }
454 var matched = rule.regex.test(path);
455 if (matched) {
456 ignored = !negative;
457 unignored = negative;
458 }
459 });
460 return {
461 ignored: ignored,
462 unignored: unignored
463 };
464 }
465
466 // @returns {TestResult}
467 }, {
468 key: "_test",
469 value: function _test(originalPath, cache, checkUnignored, slices) {
470 var path = originalPath
471 // Supports nullable path
472 && checkPath.convert(originalPath);
473 checkPath(path, originalPath, this._allowRelativePaths ? RETURN_FALSE : throwError);
474 return this._t(path, cache, checkUnignored, slices);
475 }
476 }, {
477 key: "_t",
478 value: function _t(path, cache, checkUnignored, slices) {
479 if (path in cache) {
480 return cache[path];
481 }
482 if (!slices) {
483 // path/to/a.js
484 // ['path', 'to', 'a.js']
485 slices = path.split(SLASH);
486 }
487 slices.pop();
488
489 // If the path has no parent directory, just test it
490 if (!slices.length) {
491 return cache[path] = this._testOne(path, checkUnignored);
492 }
493 var parent = this._t(slices.join(SLASH) + SLASH, cache, checkUnignored, slices);
494
495 // If the path contains a parent directory, check the parent first
496 return cache[path] = parent.ignored
497 // > It is not possible to re-include a file if a parent directory of
498 // > that file is excluded.
499 ? parent : this._testOne(path, checkUnignored);
500 }
501 }, {
502 key: "ignores",
503 value: function ignores(path) {
504 return this._test(path, this._ignoreCache, false).ignored;
505 }
506 }, {
507 key: "createFilter",
508 value: function createFilter() {
509 var _this = this;
510 return function (path) {
511 return !_this.ignores(path);
512 };
513 }
514 }, {
515 key: "filter",
516 value: function filter(paths) {
517 return makeArray(paths).filter(this.createFilter());
518 }
519
520 // @returns {TestResult}
521 }, {
522 key: "test",
523 value: function test(path) {
524 return this._test(path, this._testCache, true);
525 }
526 }]);
527 return Ignore;
528}();
529var factory = function factory(options) {
530 return new Ignore(options);
531};
532var isPathValid = function isPathValid(path) {
533 return checkPath(path && checkPath.convert(path), path, RETURN_FALSE);
534};
535factory.isPathValid = isPathValid;
536
537// Fixes typescript
538factory["default"] = factory;
539module.exports = factory;
540
541// Windows
542// --------------------------------------------------------------
543/* istanbul ignore if */
544if (
545// Detect `process` so that it can run in browsers.
546typeof process !== 'undefined' && (process.env && process.env.IGNORE_TEST_WIN32 || process.platform === 'win32')) {
547 /* eslint no-control-regex: "off" */
548 var makePosix = function makePosix(str) {
549 return /^\\\\\?\\/.test(str) || /[\0-\x1F"<>\|]+/.test(str) ? str : str.replace(/\\/g, '/');
550 };
551 checkPath.convert = makePosix;
552
553 // 'C:\\foo' <- 'C:\\foo' has been converted to 'C:/'
554 // 'd:\\foo'
555 var REGIX_IS_WINDOWS_PATH_ABSOLUTE = /^[a-z]:\//i;
556 checkPath.isNotRelative = function (path) {
557 return REGIX_IS_WINDOWS_PATH_ABSOLUTE.test(path) || isNotRelative(path);
558 };
559}
Note: See TracBrowser for help on using the repository browser.