mirror of
https://github.com/koloml/furbooru-tagging-assistant.git
synced 2025-12-23 23:02:58 +00:00
Replaced custom-made RegExp escaping utility with @std/regexp
This commit is contained in:
@@ -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";
|
||||
|
||||
|
||||
@@ -21,21 +21,3 @@ export function findDeepObject(targetObject: Record<string, any>, 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, "\\$&");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user