url-join-dual
v5.1.2
Published
Join urls and normalize as in path.join.
Downloads
20
Readme
url-join-dual
url-join-dual
is a library that joins all arguments together and normalizes the resulting URL. This library has been enhanced to be used with both ESM and CommonJS. It is based on the url-join library.
Installation
npm install url-join-dual
Usage
import urlJoin from 'url-join-dual';
const fullUrl = urlJoin('http://www.google.com', 'a', '/b/cd', '?foo=123', '&bar=456', '#heading-1');
console.log(fullUrl.toString()); // 'http://www.google.com/a/b/cd?foo=123&bar=456#heading-1'
For usage with CommonJS:
const urlJoin = require('url-join-dual');
const fullUrl = urlJoin('http://www.google.com', 'a', '/b/cd', '?foo=123', '&bar=456', '#heading-1');
console.log(fullUrl.toString()); // 'http://www.google.com/a/b/cd?foo=123&bar=456#heading-1'
You might not need this library
This library was originally created before the URL API was standardized and widely available in popular runtimes such as browsers and Node.js. Depending on your use-case you might want to consider using the standardized API over this library.
In the Browser
For example, the equivalent code for the above example would look as follows when using the URL API:
const fullUrl = new URL('http://www.google.com');
Author
KATO_Yuumin
License
MIT