diff --git a/src/uri.js b/src/uri.js index a691427..e013e6e 100644 --- a/src/uri.js +++ b/src/uri.js @@ -1,11 +1,17 @@ -/* +/** * This is just a hack to adapt the jsonschema lib to work without a polyfill for the "url" lib. */ -// https://nodejs.org/api/url.html#urlresolvefrom-to +/** + * @see {@link https://nodejs.org/api/url.html#urlresolvefrom-to} + * @param {string} from + * @param {string} to + * @returns {string} + */ export const resolve = (from, to) => { if (!to) return from; - const resolved = new URL(to, new URL(from, "resolve://")); + if (to.startsWith("#")) return (from || "") + to; + const resolved = new URL(to, new URL(from, "resolve://resolve/")); if (resolved.protocol === "resolve:") { const { pathname, search, hash } = resolved; @@ -15,4 +21,8 @@ export const resolve = (from, to) => { return resolved.toString(); }; +/** + * @param {string} uri + * @returns {URL} + */ export const parse = (uri) => new URL(uri);