Added escapeRegex
All checks were successful
Build / Build NPM Project (push) Successful in 59s
Build / Tag Version (push) Successful in 14s
Build / Publish Documentation (push) Successful in 42s

This commit is contained in:
Zakary Timson 2024-10-12 12:27:45 -04:00
parent b93ed45521
commit e4229296c1
3 changed files with 13 additions and 3 deletions

4
package-lock.json generated
View File

@ -1,12 +1,12 @@
{
"name": "@ztimson/utils",
"version": "0.18.0",
"version": "0.18.1",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "@ztimson/utils",
"version": "0.18.0",
"version": "0.18.1",
"license": "MIT",
"dependencies": {
"var-persist": "^1.0.1"

View File

@ -1,6 +1,6 @@
{
"name": "@ztimson/utils",
"version": "0.18.0",
"version": "0.18.1",
"description": "Utility library",
"author": "Zak Timson",
"license": "MIT",

View File

@ -11,3 +11,13 @@ export function gravatar(email: string, def='mp') {
if(!email) return '';
return `https://www.gravatar.com/avatar/${md5(email)}?d=${def}`;
}
/**
* Escape any regex special characters to avoid misinterpretation during search
*
* @param {string} value String which should be escaped
* @return {string} New escaped sequence
*/
function escapeRegex(value: string) {
return value.replace(/[.*+?^${}()|\[\]\\]/g, '\\$&');
}