From edb4c0abfee3eac19eb575b02df3508a808a1302 Mon Sep 17 00:00:00 2001 From: Rhys Arkins <rhys@arkins.net> Date: Tue, 14 Apr 2020 13:47:58 +0200 Subject: [PATCH] refactor: move escapeRegExp to util/regex --- lib/util/regex.ts | 4 ++++ lib/workers/branch/auto-replace.ts | 6 +----- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/util/regex.ts b/lib/util/regex.ts index 7cc415c653..eac1ad871b 100644 --- a/lib/util/regex.ts +++ b/lib/util/regex.ts @@ -25,3 +25,7 @@ export function regEx(pattern: string, flags?: string): RegExp { throw error; } } + +export function escapeRegExp(input: string): string { + return input.replace(/[.*+\-?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string +} diff --git a/lib/workers/branch/auto-replace.ts b/lib/workers/branch/auto-replace.ts index 2023b5556d..a0f4b18d34 100644 --- a/lib/workers/branch/auto-replace.ts +++ b/lib/workers/branch/auto-replace.ts @@ -2,7 +2,7 @@ import { logger } from '../../logger'; import { get } from '../../manager'; import { WORKER_FILE_UPDATE_FAILED } from '../../constants/error-messages'; import { matchAt, replaceAt } from '../../util/string'; -import { regEx } from '../../util/regex'; +import { regEx, escapeRegExp } from '../../util/regex'; export async function confirmIfDepUpdated( upgrade, @@ -60,10 +60,6 @@ export async function checkBranchDepsMatchBaseDeps( } } -function escapeRegExp(input: string): string { - return input.replace(/[.*+\-?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string -} - export async function doAutoReplace( upgrade, existingContent: string, -- GitLab