mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-14 08:36:26 +00:00
00c56d8bde
* chore: fix types * fix more types * chore: mote fixes * fix frmat * chore: fix tests * chore: fix type * chore: cleanup * chore: cleanup Co-authored-by: Rhys Arkins <rhys@arkins.net>
31 lines
883 B
TypeScript
31 lines
883 B
TypeScript
import { CONFIG_VALIDATION } from '../constants/error-messages';
|
|
import { logger } from '../logger';
|
|
|
|
let RegEx: RegExpConstructor;
|
|
|
|
try {
|
|
// eslint-disable-next-line
|
|
const RE2 = require('re2');
|
|
// Test if native is working
|
|
new RE2('.*').exec('test');
|
|
logger.debug('Using RE2 as regex engine');
|
|
RegEx = RE2;
|
|
} catch (err) {
|
|
logger.warn({ err }, 'RE2 not usable, falling back to RegExp');
|
|
RegEx = RegExp;
|
|
}
|
|
|
|
export function regEx(pattern: string, flags?: string): RegExp {
|
|
try {
|
|
return new RegEx(pattern, flags);
|
|
} catch (err) {
|
|
const error = new Error(CONFIG_VALIDATION);
|
|
error.configFile = pattern;
|
|
error.validationError = 'Invalid regular expression: ' + err.toString();
|
|
throw error;
|
|
}
|
|
}
|
|
|
|
export function escapeRegExp(input: string): string {
|
|
return input.replace(/[.*+\-?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string
|
|
}
|