#287 - Fixed & improved highlightText() + a bit of cleaning (#288)

This commit is contained in:
Simon Cambier
2023-09-11 21:32:01 +02:00
committed by GitHub
parent d651278b43
commit 0558b9a328
3 changed files with 38 additions and 44 deletions

View File

@@ -25,12 +25,6 @@ export function wait(ms: number): Promise<void> {
})
}
// https://stackoverflow.com/a/3561711
// but we enclose special chars in brackets to avoid them being interpreted as regex
export function escapeRegex(str: string): string {
return str.replace(/[-/\\^$*+?.()|[\]{}]/g, '[$&]')
}
/**
* Returns the positions of all occurences of `val` inside of `text`
* https://stackoverflow.com/a/58828841