feature: initial commit

This commit is contained in:
Andy Burke 2025-06-13 20:40:28 -07:00
commit ce024ba87a
17 changed files with 1141 additions and 0 deletions

24
organizers/by_email.ts Normal file
View file

@ -0,0 +1,24 @@
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`];
}