Skip to content

url.relative (to complement path.relative) #616

Closed
@junosuarez

Description

@junosuarez

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestIssues that request new features to be added to Node.js.pathIssues and PRs related to the path subsystem.urlIssues and PRs related to the legacy built-in url module.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions