Added escapeRegex
This commit is contained in:
parent
b93ed45521
commit
e4229296c1
4
package-lock.json
generated
4
package-lock.json
generated
@ -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"
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@ztimson/utils",
|
||||
"version": "0.18.0",
|
||||
"version": "0.18.1",
|
||||
"description": "Utility library",
|
||||
"author": "Zak Timson",
|
||||
"license": "MIT",
|
||||
|
10
src/misc.ts
10
src/misc.ts
@ -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, '\\$&');
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user