yufan.me/src/helpers/tools.ts
Yufan Sheng c37ce2b820
feat: change the commenter avatar link. ()
* feat: add new comment user merge service.

* feat: better hide the commenter email.
2024-11-15 14:53:53 +08:00

25 lines
786 B
TypeScript

import crypto from 'node:crypto';
export const makeToken = (
length: number,
characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789',
) => {
let result = '';
const charactersLength = characters.length;
let counter = 0;
while (counter < length) {
result += characters.charAt(Math.floor(Math.random() * charactersLength));
counter += 1;
}
return result;
};
export const urlJoin = (base: string, ...paths: string[]): string => {
return Array.from([base, ...paths])
.reduce((left, right) => left + (left.endsWith('/') || right.startsWith('/') ? '' : '/') + right)
.replace(/([^:]\/)\/+/g, '$1');
};
export const encodedEmail = (email: string): string =>
crypto.createHash('md5').update(email.trim().toLowerCase()).digest('hex');