The @lonr/href package exports a RelativeURL Class, a URL-like API that helps you resolve relative URLs
Install href:
# npm
npm install @lonr/href
# yarn
yarn add @lonr/hrefUsage:
import{RelativeURL}from"@lonr/href";// ⛔️ Don't use RelativeURL to parse complete URLs. Use the built-in URL insteadnewRelativeURL("https://example.com").pathname==="https://example.com";newRelativeURL("path/to/file1?q=1").searchParams.set("q","2");newRelativeURL("file2","path/to/file1").pathname==="path/to/file2";newRelativeURL("file2","path/to/").pathname==="path/to/file2";newRelativeURL("../../file2").pathname==="../../file2";Supported properties: href, pathname, search, searchPrams, hash
This package is based on the work of jsdom/whatwg-url