resolve-url-modern
v0.3.0
Published
A maintained, browser-compatible continuation of resolve-url.
Readme
resolve-url-modern
A maintained, compatibility-first continuation of the deprecated
resolve-url browser library.
The public API remains one function, resolveUrl(...urls). It resolves every
argument from left to right using the browser's URL behavior. This is not a
general-purpose Node.js URL resolver.
Compatibility policy
Existing behavior wins over internal novelty. Changes are checked in real Chromium, Firefox, and WebKit against a licensed copy of the 0.2.1 implementation. See COMPATIBILITY.md for details.
Install
npm install resolve-url-modernThe package has no runtime dependencies and no build step.
CommonJS
Use the CommonJS export in browser-targeted code or a browser bundle:
var resolveUrl = require("resolve-url-modern")
resolveUrl("/static/scripts/app.js", "../source-maps/app.js.map")
// https://example.com/static/source-maps/app.js.mapRequiring the module in Node.js returns the function, but calling it needs a
browser document. Node.js-only execution is not a supported runtime API.
Browser global and AMD
The distributed file can be loaded directly as a classic script:
<script src="resolve-url.js"></script>
<script>
resolveUrl("remove")
</script>The global name is resolveUrl. The same file retains its original AMD
define(factory) branch.
API: resolveUrl(...urls)
Pass one or more URL values. The first value is resolved against the document's used base URL. Each later value is resolved against the previous result. The final string is returned.
resolveUrl(
"/static/scripts/app.js",
"../source-maps/app.js.map",
"../coffee/app.coffee"
)
// https://example.com/static/coffee/app.coffeeCalling resolveUrl() with no arguments throws:
Error: resolveUrl requires at least one argument; got none.Values are converted to strings by browser DOM URL properties, as in the original package.
Browser support
Compatibility is tested with the Chromium, Firefox, and WebKit versions bundled by the locked Playwright release. The package no longer claims the original IE 8, Opera 12, or Safari 5 matrix.
Migration from resolve-url
Usually only the dependency and import name change:
-var resolveUrl = require("resolve-url")
+var resolveUrl = require("resolve-url-modern")After publication and registry verification, an npm alias can keep source imports unchanged:
{
"dependencies": {
"resolve-url": "npm:resolve-url-modern@^0.3.0"
}
}ESM
There is no separate ESM entry point. Keeping CommonJS, AMD, and browser-global interfaces avoids a build pipeline. ESM consumers should use their runtime or bundler's CommonJS interop.
Known differences
Version 0.3.0 keeps the original resolver implementation, so no result
differences are accepted. Package metadata, development tooling, browser
coverage, and documentation changed. MODERNIZATION.md
explains why the first WHATWG URL candidate was not shipped.
Development
npm install
npx playwright install chromium firefox webkit
npm testThe suite runs Golden Master and differential checks in all three engines.
License
MIT. Simon Lydell's original copyright notice is retained in LICENSE and the copied fixture.
