Open Vitaminaq opened 2 years ago
// api解法
function urlFormat(url) {
let u = {};
try {
u = new URL(url);
} catch(e) {
throw Error('请传入正确的url');
}
let obj = {};
obj.origin = u.origin;
obj.hash = u.hash.replace('#', '');
const usp = new URLSearchParams(u.search.replace('?', ''));
const p = Object.fromEntries(usp);
return JSON.stringify(Object.assign(obj, p), null, 0);
}