
Security News
Maven Central Adds Sigstore Signature Validation
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.
@jridgewell/resolve-uri
Advanced tools
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.
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 30,797,287 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
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.