/** * FSDB Organizer: By Email * * Organizes by splitting an email into its components, eg: * * com/example.com/soandso@example.com * * 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 * * @module */ import sanitize from '../utils/sanitize.ts'; const EMAIL_REGEX = /^(?.+)@(?(?.+)\.(?.+))$/; 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 []; } return [sanitize(tld), sanitize(domain), sanitize(email), `${sanitize(email)}.json`]; }