URI Parsing

https://github.com/wizard04wsu/URI_Parsing

by wizard04

HTML

<input type="text" id="uri" placeholder="Enter a URI here" style="width:100%; box-sizing:border-box;"><br>
<button id="parse_scheme" style="clear:left;">Parse according to scheme</button>
<button id="parse_generic">Parse as a generic URI</button><br>
<br>
<input type="text" id="email" placeholder="Enter an email address here" style="width:100%; box-sizing:border-box;"><br>
<button id="parse_mailbox">Parse email address</button>

JavaScript

import URI, {isDNSDomain, parseMailbox} from "https://cdn.jsdelivr.net/gh/wizard04wsu/URI_Parsing@jsfiddle-demo/src/uri_parsing.mjs"

console.clear();

document.getElementById("parse_scheme").addEventListener("click", ()=>{
	let val = document.getElementById("uri").value;
	console.group("scheme");
	try{
		let obj = URI(val);
		console.log("--> "+(obj?obj.toString():obj));
		console.log(obj);
	}catch(e){
		if(e instanceof URIError) console.error(e.message);
		else throw e;
	}finally{
		console.groupEnd();
	}
}, false);

document.getElementById("parse_generic").addEventListener("click", ()=>{
	let val = document.getElementById("uri").value;
	console.group("generic");
	try{
		let obj = URI.parse(val)
		console.log("--> "+(obj?obj.toString():obj));
		console.log(obj);
	}catch(e){
		if(e instanceof URIError) console.error(e.message);
		else throw e;
	}finally{
		console.groupEnd();
	}
}, false);

document.getElementById("parse_mailbox").addEventListener("click", ()=>{
	let val = document.getElementById("email").value;
	console.group("email");
	try{
		let obj = parseMailbox(val);
		console.log("--> "+(obj?obj.toString():obj));
		console.log(obj);
	}catch(e){
		if(e instanceof URIError) console.log(e.message);
		else throw e;
	}finally{
		console.groupEnd();
	}
}, false);