Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function subdomainToIpfsPath (url) {
if (typeof url === 'string') {
url = new URL(url)
}
const match = url.toString().match(IsIpfs.subdomainPattern)
if (!match) throw new Error('no match for IsIpfs.subdomainPattern')
// TODO: support CID split with commas
const cid = match[1]
// TODO: support .ip(f|n)s. being at deeper levels
const protocol = match[2]
return `/${protocol}/${cid}${url.pathname}${url.search}${url.hash}`
}