From d5dee6c615d1a956e1110a3cfabf1a3f3bd73f78 Mon Sep 17 00:00:00 2001 From: KoloMl Date: Tue, 8 Apr 2025 19:18:27 +0400 Subject: [PATCH] Replaced custom-made RegExp escaping utility with `@std/regexp` --- src/lib/extension/CustomCategoriesResolver.ts | 2 +- src/lib/utils.ts | 18 ------------------ 2 files changed, 1 insertion(+), 19 deletions(-) diff --git a/src/lib/extension/CustomCategoriesResolver.ts b/src/lib/extension/CustomCategoriesResolver.ts index 11e9935..4a2545b 100644 --- a/src/lib/extension/CustomCategoriesResolver.ts +++ b/src/lib/extension/CustomCategoriesResolver.ts @@ -1,6 +1,6 @@ import type { TagDropdownWrapper } from "$lib/components/TagDropdownWrapper"; import TagGroup from "$entities/TagGroup"; -import { escapeRegExp } from "$lib/utils"; +import { escape as escapeRegExp } from "@std/regexp"; import { emit } from "$lib/components/events/comms"; import { EVENT_TAG_GROUP_RESOLVED } from "$lib/components/events/tag-dropdown-events"; diff --git a/src/lib/utils.ts b/src/lib/utils.ts index 251fd43..e743865 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -21,21 +21,3 @@ export function findDeepObject(targetObject: Record, path: string[] return result; } - -/** - * Matches all the characters needing replacement. - * - * Gathered from right here: https://stackoverflow.com/a/3561711/16048617. Because I don't want to introduce some - * library for that. - */ -const unsafeRegExpCharacters: RegExp = /[/\-\\^$*+?.()|[\]{}]/g; - -/** - * Escape all the RegExp syntax-related characters in the following value. - * @param value Original value. - * @return Resulting value with all needed characters escaped. - */ -export function escapeRegExp(value: string): string { - unsafeRegExpCharacters.lastIndex = 0; - return value.replace(unsafeRegExpCharacters, "\\$&"); -}