Skip to content

Commit c24cd22

Browse files
Физули Махмудовphilsturgeon
authored andcommitted
Replace deprecated resolve function
1 parent 5d7f895 commit c24cd22

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

lib/util/url.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,21 @@ let urlDecodePatterns = [
2323
];
2424

2525
exports.parse = require("url").parse;
26-
exports.resolve = require("url").resolve;
26+
27+
/**
28+
* Returns resolved target URL relative to a base URL in a manner similar to that of a Web browser resolving an anchor tag HREF.
29+
*
30+
* @return {string}
31+
*/
32+
exports.resolve = function resolve (from, to) {
33+
let resolvedUrl = new URL(to, new URL(from, "resolve://"));
34+
if (resolvedUrl.protocol === "resolve:") {
35+
// `from` is a relative URL.
36+
let { pathname, search, hash } = resolvedUrl;
37+
return pathname + search + hash;
38+
}
39+
return resolvedUrl.toString();
40+
};
2741

2842
/**
2943
* Returns the current working directory (in Node) or the current page URL (in browsers).

0 commit comments

Comments
 (0)