Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
resolve-url
Advanced tools
The resolve-url package is a utility for resolving URLs based on a base URL. It is commonly used to resolve relative paths to absolute URLs in the context of web development.
Resolve relative URL
This feature allows you to resolve a relative URL to an absolute URL using a base URL. In the code sample, '/some/path' is resolved against the base URL 'http://example.com/' to form the absolute URL 'http://example.com/some/path'.
var resolve = require('resolve-url');
var resolvedUrl = resolve('http://example.com/', '/some/path');
Resolve URL with query string
This feature enables resolving a relative URL in the presence of a query string in the base URL. The code sample demonstrates how 'path' is resolved against 'http://example.com/?query=123' to form 'http://example.com/path?query=123'.
var resolve = require('resolve-url');
var resolvedUrl = resolve('http://example.com/?query=123', 'path');
Resolve URL with hash fragment
This feature is used to resolve a relative URL when there is a hash fragment in the base URL. In the code sample, 'path' is resolved against 'http://example.com/#hash' to form 'http://example.com/path#hash'.
var resolve = require('resolve-url');
var resolvedUrl = resolve('http://example.com/#hash', 'path');
This package provides similar functionality to resolve-url but is specifically designed for browser environments. It resolves relative URLs against a base URL, similar to resolve-url, but may have differences in handling edge cases or browser-specific quirks.
url-join is a package that allows for joining multiple URL segments together, ensuring that there are no duplicate slashes and that the segments are properly concatenated. It differs from resolve-url in that it focuses on joining segments rather than resolving relative URLs against a base URL.
url-parse is a robust URL parsing library that can handle parsing URLs, resolving them, and normalizing them. It offers more comprehensive URL manipulation capabilities compared to resolve-url, which is more focused on resolving URLs.
Like Node.js’ path.resolve
/url.resolve
for the browser.
var resolveUrl = require("resolve-url")
window.location
// https://example.com/articles/resolving-urls/edit
resolveUrl("remove")
// https://example.com/articles/resolving-urls/remove
resolveUrl("/static/scripts/app.js")
// https://example.com/static/scripts/app.js
// Imagine /static/scripts/app.js contains `//# sourceMappingURL=../source-maps/app.js.map`
resolveUrl("/static/scripts/app.js", "../source-maps/app.js.map")
// https://example.com/static/source-maps/app.js.map
resolveUrl("/static/scripts/app.js", "../source-maps/app.js.map", "../coffee/app.coffee")
// https://example.com/static/coffee/app.coffee
resolveUrl("//cdn.example.com/jquery.js")
// https://cdn.example.com/jquery.js
resolveUrl("http://foo.org/")
// http://foo.org/
npm install resolve-url
bower install resolve-url
component install lydell/resolve-url
Works with CommonJS, AMD and browser globals, through UMD.
resolveUrl(...urls)
Pass one or more urls. Resolves the last one to an absolute url, using the
previous ones and window.location
.
It’s like starting out on window.location
, and then clicking links with the
urls as href
attributes in order, from left to right.
Unlike Node.js’ path.resolve
, this function always goes through all of the
arguments, from left to right. path.resolve
goes from right to left and only
in the worst case goes through them all. Should that matter.
Actually, the function is really like clicking a lot of links in series: An
actual <a>
gets its href
attribute set for each url! This means that the
url resolution of the browser is used, which makes this module really
light-weight.
Also note that this functions deals with urls, not paths, so in that respect it
has more in common with Node.js’ url.resolve
. But the arguments are more
like path.resolve
.
Run npm test
, which lints the code and then gives you a link to open in a
browser of choice (using testling
).
Version 0.2.1 (2014-02-25) ###
undefined
or null
.FAQs
Like Node.js’ `path.resolve`/`url.resolve` for the browser.
The npm package resolve-url receives a total of 6,672,898 weekly downloads. As such, resolve-url popularity was classified as popular.
We found that resolve-url demonstrated a not healthy version release cadence and project activity because the last version was released 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.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.