(query: string)
| 5 | |
| 6 | // Parse a "handle" in the form: `[@] <local-part> '@' <domain>` |
| 7 | export function parseHandle(query: string): Handle { |
| 8 | // Remove the leading @, if there's one. |
| 9 | if (query.startsWith('@')) { |
| 10 | query = query.substring(1) |
| 11 | } |
| 12 | |
| 13 | // In case the handle has been URL encoded |
| 14 | query = decodeURIComponent(query) |
| 15 | |
| 16 | const parts = query.split('@') |
| 17 | const localPart = parts[0] |
| 18 | |
| 19 | if (!/^[\w-.]+$/.test(localPart)) { |
| 20 | throw new Error('invalid handle: localPart: ' + localPart) |
| 21 | } |
| 22 | |
| 23 | if (parts.length > 1) { |
| 24 | return { localPart, domain: parts[1] } |
| 25 | } else { |
| 26 | return { localPart, domain: null } |
| 27 | } |
| 28 | } |
no outgoing calls
no test coverage detected