@ctrl/url-join
TypeScript icon, indicating that this package has built-in type declarations

2.0.3 • Public • Published

url-join npm coverage

A typescript fork of jfromaniello/url-join with additional options.

Install

npm install @ctrl/url-join

Use

import { urlJoin } from '@ctrl/url-join';

const url = urlJoin('http://www.example.com', 'a', '/b/cd', '?foo=123')
// http://www.example.com/a/b/cd?foo=123
Preserve trailing slash

Preserves trailing slashes between each provided string. Not recommended with query parameters.

import { customUrlJoin } from '@ctrl/url-join';

const trailingUrlJoin = customUrlJoin({ trailingSlash: true });

trailingUrlJoin('https://example.com', 'results', '/')
// https://example.com/results/

trailingUrlJoin('https://example.com', '#foobar')
// https://example.com/#foobar

trailingUrlJoin('https://example.com', '#', 'foobar')
// https://example.com/#/foobar

trailingUrlJoin('https://example.com', 'results', '?q=foo', '&page=1')
// https://example.com/results/?q=foo/&page=1 - Probably not what you want

See Also

Package Sidebar

Install

npm i @ctrl/url-join

Weekly Downloads

706

Version

2.0.3

License

MIT

Unpacked Size

6.64 kB

Total Files

5

Last publish

Collaborators

  • scttcper