source: trip-planner-front/node_modules/picomatch/lib/utils.js@ 188ee53

Last change on this file since 188ee53 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.8 KB
Line 
1'use strict';
2
3const path = require('path');
4const win32 = process.platform === 'win32';
5const {
6 REGEX_BACKSLASH,
7 REGEX_REMOVE_BACKSLASH,
8 REGEX_SPECIAL_CHARS,
9 REGEX_SPECIAL_CHARS_GLOBAL
10} = require('./constants');
11
12exports.isObject = val => val !== null && typeof val === 'object' && !Array.isArray(val);
13exports.hasRegexChars = str => REGEX_SPECIAL_CHARS.test(str);
14exports.isRegexChar = str => str.length === 1 && exports.hasRegexChars(str);
15exports.escapeRegex = str => str.replace(REGEX_SPECIAL_CHARS_GLOBAL, '\\$1');
16exports.toPosixSlashes = str => str.replace(REGEX_BACKSLASH, '/');
17
18exports.removeBackslashes = str => {
19 return str.replace(REGEX_REMOVE_BACKSLASH, match => {
20 return match === '\\' ? '' : match;
21 });
22};
23
24exports.supportsLookbehinds = () => {
25 const segs = process.version.slice(1).split('.').map(Number);
26 if (segs.length === 3 && segs[0] >= 9 || (segs[0] === 8 && segs[1] >= 10)) {
27 return true;
28 }
29 return false;
30};
31
32exports.isWindows = options => {
33 if (options && typeof options.windows === 'boolean') {
34 return options.windows;
35 }
36 return win32 === true || path.sep === '\\';
37};
38
39exports.escapeLast = (input, char, lastIdx) => {
40 const idx = input.lastIndexOf(char, lastIdx);
41 if (idx === -1) return input;
42 if (input[idx - 1] === '\\') return exports.escapeLast(input, char, idx - 1);
43 return `${input.slice(0, idx)}\\${input.slice(idx)}`;
44};
45
46exports.removePrefix = (input, state = {}) => {
47 let output = input;
48 if (output.startsWith('./')) {
49 output = output.slice(2);
50 state.prefix = './';
51 }
52 return output;
53};
54
55exports.wrapOutput = (input, state = {}, options = {}) => {
56 const prepend = options.contains ? '' : '^';
57 const append = options.contains ? '' : '$';
58
59 let output = `${prepend}(?:${input})${append}`;
60 if (state.negated === true) {
61 output = `(?:^(?!${output}).*$)`;
62 }
63 return output;
64};
Note: See TracBrowser for help on using the repository browser.