utils/src/misc.ts
ztimson 379de273c4
All checks were successful
Build / Build NPM Project (push) Successful in 31s
Build / Tag Version (push) Successful in 7s
Build / Publish Documentation (push) Successful in 28s
Added path-events
2024-10-14 13:52:03 -04:00

28 lines
877 B
TypeScript

import {PathEvent} from './path-events.ts';
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/
* @returns {string} Gravatar URL
*/
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
*/
export function escapeRegex(value: string) {
return value.replace(/[.*+?^${}()|\[\]\\]/g, '\\$&');
}
export type Listener = (event: PathEvent, ...args: any[]) => any;
export type Unsubscribe = () => void;