The core url module currently has url.resolve() to compute absolute URLs from relative segments (which is complementary with path.resolve()). but it is missing the complementary .relative() function to compute relative URLs from two absolute URLs.
Many programs simply use path.relative() when dealing with URLs (e.g.: https://github.com/substack/node-browserify/blob/ce3deecf7be27373c0131286bda86533ec83ffd1/index.js#L692 ) but on Windows systems, path.relative() uses the path.sep character, resulting in relative URLs like ..\\..\\a\\b instead of ../../a/b.
The algorithm for computing relative URLs is (AFAIK) the same, but the separator character should always be a / as specified in RFC 3986 Section 3.3.
Opening this for discussion here prior to writing a PR.
The core
urlmodule currently hasurl.resolve()to compute absolute URLs from relative segments (which is complementary withpath.resolve()). but it is missing the complementary.relative()function to compute relative URLs from two absolute URLs.Many programs simply use
path.relative()when dealing with URLs (e.g.: https://github.com/substack/node-browserify/blob/ce3deecf7be27373c0131286bda86533ec83ffd1/index.js#L692 ) but on Windows systems,path.relative()uses thepath.sepcharacter, resulting in relative URLs like..\\..\\a\\binstead of../../a/b.The algorithm for computing relative URLs is (AFAIK) the same, but the separator character should always be a
/as specified in RFC 3986 Section 3.3.Opening this for discussion here prior to writing a PR.