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

View file

@ -0,0 +1,21 @@
import sanitize from '../utils/sanitize.ts';
export default function by_character(value: string): string[] {
const result: string[] = [];
// Replace invalid filename characters and leading dots
const sanitized_value = sanitize(value);
const characters_remaining = sanitized_value.split('');
let previous_characters = '';
while (characters_remaining.length) {
previous_characters += characters_remaining.shift();
result.push(previous_characters);
if (result.length >= 3) {
break;
}
}
result.push(`${sanitized_value}.json`);
return result;
}

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`];
}

18
organizers/by_lurid.ts Normal file
View file

@ -0,0 +1,18 @@
import sanitize from '../utils/sanitize.ts';
export default function by_lurid(id: string): string[] {
// Replace invalid filename characters and leading dots
const sanitized_id = sanitize(id);
// assuming a lurid, eg: able-fish-cost-them-post-many-form-hope-wife-born
// ./able-fish-cost-them/able-fish-cost-them-post-many-form/able-fish-cost-them-post-many-form-hope-wife-born.json
const result: string[] = [
sanitized_id.slice(0, 14),
sanitized_id.slice(0, 34),
sanitized_id,
`${sanitized_id}.json`
];
return result;
}

35
organizers/by_phone.ts Normal file
View file

@ -0,0 +1,35 @@
import sanitize from '../utils/sanitize.ts';
const PHONE_REGEX =
/^(?<country_code>\+?\d{1,3})?[\s.x-]?\(?(?<area_code>\d{3})\)?[\s.x-]?(?<central_office_code>\d{3})[\s.x-]?(?<subscriber_code>\d{4})$/;
export default function by_phone(phone: string): string[] {
const { groups: { country_code, area_code, central_office_code, subscriber_code } } = {
groups: {
country_code: undefined,
area_code: undefined,
central_office_code: undefined,
subscriber_code: undefined
},
...(phone.match(PHONE_REGEX) ?? {})
};
if (
typeof area_code !== 'string' || typeof central_office_code !== 'string' ||
typeof subscriber_code !== 'string'
) {
return [];
}
const normalized_number = `${sanitize(area_code)}-${sanitize(central_office_code)}-${sanitize(subscriber_code)}`;
// for example, a symlinking index based on this organizer might look like:
// fsdb root index country_code office_code area_code phone
// /path/to/db/root/.indexes/phone/1/213/555/213-555-1234
return [
sanitize(country_code ?? '1'),
sanitize(area_code),
sanitize(central_office_code),
normalized_number,
`${normalized_number}.json`
];
}