-
-
Notifications
You must be signed in to change notification settings - Fork 37.1k
url.relative (to complement path.relative) #616
Copy link
Copy link
Closed
Labels
feature requestIssues requesting new Node.js features.Issues requesting new Node.js features.pathIssues and PRs related to the path subsystem.Issues and PRs related to the path subsystem.urlIssues and PRs related to the legacy built-in url module.Issues and PRs related to the legacy built-in url module.
Description
Activity
Metadata
Metadata
Assignees
Labels
feature requestIssues requesting new Node.js features.Issues requesting new Node.js features.pathIssues and PRs related to the path subsystem.Issues and PRs related to the path subsystem.urlIssues and PRs related to the legacy built-in url module.Issues and PRs related to the legacy built-in url module.
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.