import UrlParser from 'url-parse' ; export function parseMailto ( mailtoURL ) { const mailto_url = UrlParser ( mailtoURL ) ; if ( mailto_url . protocol . toLowerCase ( ) !== 'mailto:' ) { throw new Error ( "not a mailto link, doesn't start with 'mailto:': " + mailtoURL ) ; } const query = UrlParser . qs . parse ( ( mailto_url . query as any ) as string ) ; const address = mailto_url . pathname || query . to || null ; return { to : address && decodeURIComponent ( address ) . trim ( ) , subject : query . subject , body : query . body , } ; }