app

Local-first trade for farms and co-ops
git clone https://radroots.dev/git/app.git
Log | Files | Refs | README | LICENSE

contact-read.ts (783B)


      1 import { publicContact, type PublicContact } from './contact.ts';
      2 // The writer's dedicated public disclosure is a final block, not prose scanning.
      3 export function readPublicContact(content: unknown): PublicContact | undefined {
      4   if (typeof content !== 'string') return undefined;
      5   const marker = '\n\nPublic contact: ';
      6   const at = content.lastIndexOf(marker);
      7   if (at < 0) return undefined;
      8   const href = content.slice(at + marker.length);
      9   const type = href.startsWith('mailto:')
     10     ? 'email'
     11     : href.startsWith('tel:')
     12       ? 'phone'
     13       : 'https';
     14   const value =
     15     type === 'email' ? href.slice(7) : type === 'phone' ? href.slice(4) : href;
     16   const contact = publicContact({ type, value, public: true });
     17   return contact?.href === href ? contact : undefined;
     18 }