* feat: add new comment user merge service. * feat: better hide the commenter email.
25 lines
786 B
TypeScript
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');
|