Methods
buildUrl(…args) → {string}
Build an URL by joining provided parts and removing trailing slash
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
args | Array.<string> | | <repeatable> | Url parts |
- Source
Returns:
- Type:
- string
Example
import { buildUrl } from '@infotorg/build-url';
// How url is fixed
const normalizedUrl = buildUrl('https://example.com/');
console.log(normalizedUrl);
// https://example.com
// How url is built from two parts
const normalizedUrl = buildUrl('https://example.com', 'chunk');
console.log(normalizedUrl);
// https://example.com/chunk
// How url is built by joining an array of parts
const normalizedUrl = buildUrl(['https://example', 'chunk']);
console.log(normalizedUrl);
// https://example/chunk