import { ParseError , ParseErrorType } from '../utils/errors' ; param protocol param hostname param path param port returns export function constructUrl ( protocol , hostname , path , port ? ) { if ( port ) { return `${ protocol }://${ hostname }:${ port }${ path }` ; } return `${ protocol }://${ hostname }${ path }` ; } param url returns export function urlToPayId ( url ) { const payIdUrl = parsePayIdUrl ( url ) ; const user = payIdUrl . pathname . slice ( 1 ) ; return `${ user . toLowerCase ( ) }$${ payIdUrl . host }` ; } param input returns function isASCII ( input ) { return /^[\x00-\x7F]*$/u . test ( input ) ; } param url returns throws function parsePayIdUrl ( url ) { if ( ! url . startsWith ( 'http://' ) && ! url . startsWith ( 'https://' ) ) { throw new ParseError ( 'Invalid PayID URL protocol. PayID URLs must be HTTP/HTTPS.' , ParseErrorType . InvalidPayId ) ; } if ( ! isASCII ( url ) ) { throw new ParseError ( 'Invalid PayID characters. PayIDs must be ASCII.' , ParseErrorType . InvalidPayId ) ; } const parsedUrl = new URL ( url ) ; if ( ( parsedUrl . pathname . match ( /\//gu ) || [ ] ) . length > 1 ) { throw new ParseError ( 'Too many paths. The only paths allowed in a PayID are to specify the user.' , ParseErrorType . InvalidPayId ) ; } return parsedUrl ; }