2024-02-07 01:33:07 -05:00
|
|
|
import {md5} from './string';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get profile image from Gravatar
|
|
|
|
*
|
|
|
|
* @param {string} email Account email address
|
2024-03-20 19:26:13 -04:00
|
|
|
* @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 '';
|
2024-03-20 19:26:13 -04:00
|
|
|
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
|
|
|
|
*/
|
|
|
|
function escapeRegex(value: string) {
|
|
|
|
return value.replace(/[.*+?^${}()|\[\]\\]/g, '\\$&');
|
|
|
|
}
|