utils/src/misc.ts

24 lines
724 B
TypeScript
Raw Normal View History

2024-02-07 01:33:07 -05:00
import {md5} from './string';
/**
* Get profile image from Gravatar
*
* @param {string} email Account email address
* @param {string} def Default image, can be a link or '404', see: https://docs.gravatar.com/general/images/
2024-02-07 01:33:07 -05:00
* @returns {string} Gravatar URL
*/
2024-03-20 20:44:53 -04:00
export function gravatar(email: string, def='mp') {
2024-02-07 01:33:07 -05:00
if(!email) return '';
return `https://www.gravatar.com/avatar/${md5(email)}?d=${def}`;
2024-02-07 01:33:07 -05:00
}
2024-10-12 12:27:45 -04:00
/**
* Escape any regex special characters to avoid misinterpretation during search
*
* @param {string} value String which should be escaped
* @return {string} New escaped sequence
*/
2024-10-12 12:30:23 -04:00
export function escapeRegex(value: string) {
2024-10-12 12:27:45 -04:00
return value.replace(/[.*+?^${}()|\[\]\\]/g, '\\$&');
}