24 lines
930 B
TypeScript
24 lines
930 B
TypeScript
import sanitize from '../utils/sanitize.ts';
|
|
|
|
const EMAIL_REGEX = /^(?<username>.+)@(?<domain>(?<hostname>.+)\.(?<tld>.+))$/;
|
|
export default function by_email(email: string): string[] {
|
|
const { groups: { username, domain, hostname, tld } } = {
|
|
groups: {
|
|
username: undefined,
|
|
domain: undefined,
|
|
hostname: undefined,
|
|
tld: undefined
|
|
},
|
|
...(email.match(EMAIL_REGEX) ?? {})
|
|
};
|
|
|
|
if (typeof username === 'undefined' || typeof domain === 'undefined' || typeof hostname === 'undefined' || typeof tld === 'undefined') {
|
|
return [];
|
|
}
|
|
|
|
// for example, a symlinking index based on this organizer might look like:
|
|
// fsdb root index tld domain email
|
|
// [ ][ V ][ V ][ V ][ V ]
|
|
// /path/to/db/root/.indexes/email/com/example.com/soandso@example.com
|
|
return [sanitize(tld), sanitize(domain), sanitize(email), `${sanitize(email)}.json`];
|
|
}
|