Security News
New axobject-query Maintainer Faces Backlash Over Controversial Decision to Support Legacy Node.js Versions
A JavaScript library maintainer is under fire after merging a controversial PR to support legacy versions of Node.js.
@jridgewell/resolve-uri
Advanced tools
Package description
The @jridgewell/resolve-uri package is designed to resolve URIs in a consistent and reliable manner. It provides functionality for resolving relative URIs against a base URI, similar to how web browsers resolve relative links. This can be particularly useful in web development and applications that need to handle various URI manipulations.
Resolving relative URIs
This feature allows the resolution of a relative URI against a base URI, effectively calculating the absolute URI. It's particularly useful for web applications that need to dynamically resolve links or resources.
"const resolveUri = require('@jridgewell/resolve-uri');\nconst baseUri = 'http://example.com/dir/page.html';\nconst relativeUri = '../image.png';\nconst resolvedUri = resolveUri(relativeUri, baseUri);\nconsole.log(resolvedUri); // Outputs: 'http://example.com/image.png'"
The url-resolve package offers similar functionality for resolving URLs. It provides a simple API for combining a base URL with a relative path to form a complete URL. Compared to @jridgewell/resolve-uri, it might offer a simpler interface but lacks some of the advanced resolution capabilities and optimizations present in @jridgewell/resolve-uri.
resolve-url is another npm package that provides URL resolution capabilities. It is designed to resolve URLs in a manner similar to web browsers, handling various edge cases and relative path scenarios. While it shares similar goals with @jridgewell/resolve-uri, the implementation details and specific features may vary, offering different performance characteristics or API nuances.
Readme
Resolve a URI relative to an optional base URI
Resolve any combination of absolute URIs, protocol-realtive URIs, absolute paths, or relative paths.
npm install @jridgewell/resolve-uri
function resolve(input: string, base?: string): string;
import resolve from '@jridgewell/resolve-uri';
resolve('foo', 'https://example.com'); // => 'https://example.com/foo'
Input | Base | Resolution | Explanation |
---|---|---|---|
https://example.com | any | https://example.com/ | Input is normalized only |
//example.com | https://base.com/ | https://example.com/ | Input inherits the base's protocol |
//example.com | rest | //example.com/ | Input is normalized only |
/example | https://base.com/ | https://base.com/example | Input inherits the base's origin |
/example | //base.com/ | //base.com/example | Input inherits the base's host and remains protocol relative |
/example | rest | /example | Input is normalized only |
example | https://base.com/dir/ | https://base.com/dir/example | Input is joined with the base |
example | https://base.com/file | https://base.com/example | Input is joined with the base without its file |
example | //base.com/dir/ | //base.com/dir/example | Input is joined with the base's last directory |
example | //base.com/file | //base.com/example | Input is joined with the base without its file |
example | /base/dir/ | /base/dir/example | Input is joined with the base's last directory |
example | /base/file | /base/example | Input is joined with the base without its file |
example | base/dir/ | base/dir/example | Input is joined with the base's last directory |
example | base/file | base/example | Input is joined with the base without its file |
FAQs
Resolve a URI relative to an optional base URI
The npm package @jridgewell/resolve-uri receives a total of 32,894,420 weekly downloads. As such, @jridgewell/resolve-uri popularity was classified as popular.
We found that @jridgewell/resolve-uri demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
A JavaScript library maintainer is under fire after merging a controversial PR to support legacy versions of Node.js.
Security News
Results from the 2023 State of JavaScript Survey highlight key trends, including Vite's dominance, rising TypeScript adoption, and the enduring popularity of React. Discover more insights on developer preferences and technology usage.
Security News
The US Justice Department has penalized two consulting firms $11.3 million for failing to meet cybersecurity requirements on federally funded projects, emphasizing strict enforcement to protect sensitive government data.