Something went wrong. Try again.
A downstream fork of Tranquil PDS for use in margin.cafe
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546/** * Normalizes a domain suffix by ensuring it has exactly one leading dot. * @param suffix The domain suffix (e.g. 'margin.cafe' or '.margin.cafe') * @returns The normalized suffix (e.g. '.margin.cafe') */export function normalizeSuffix(suffix: string): string { if (!suffix) return ''; const trimmed = suffix.trim(); if (!trimmed) return ''; if (trimmed.startsWith('.')) return trimmed; return `.${trimmed}`;}
/** * Composes a full handle from a local part and a domain suffix. * Ensures exactly one dot between the handle and the suffix. * If the handle already contains a dot, it is returned as-is (assumed to be a full handle). * @param handle The local handle part or a full handle * @param suffix The domain suffix * @returns The full handle */export function composeHandle(handle: string, suffix: string): string { const h = handle.trim(); if (!h) return ''; if (h.includes('.')) return h; const s = suffix.trim(); if (!s) return h; return `${h}${normalizeSuffix(s)}`;}
/** * Checks if a handle ends with a given domain, handling both dotted and undotted domain inputs. * Ensures that the match is on a full domain component (prefixed by a dot). * @param handle The full handle to check * @param domain The domain to check against * @returns True if the handle ends with the domain */export function handleEndsWith(handle: string, domain: string): boolean { if (!handle || !domain) return false; const normalizedSuffix = normalizeSuffix(domain); if (!normalizedSuffix) return false; return handle.endsWith(normalizedSuffix);}