kopia lustrzana https://github.com/cloudflare/wildebeest
22 wiersze
476 B
TypeScript
22 wiersze
476 B
TypeScript
export type Handle = {
|
|
localPart: string
|
|
domain: string | null
|
|
}
|
|
|
|
export function parseHandle(query: string): Handle {
|
|
// Remove the leading @, if there's one.
|
|
if (query.startsWith('@')) {
|
|
query = query.substring(1)
|
|
}
|
|
|
|
// In case the handle has been URL encoded
|
|
query = decodeURIComponent(query)
|
|
|
|
const parts = query.split('@')
|
|
if (parts.length > 1) {
|
|
return { localPart: parts[0], domain: parts[1] }
|
|
} else {
|
|
return { localPart: parts[0], domain: null }
|
|
}
|
|
}
|