Socket
Book a DemoInstallSign in
Socket

@ctrl/url-join

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ctrl/url-join

Join strings together and normalize the resulting url

2.0.3
latest
Source
npmnpm
Version published
Weekly downloads
741
-39.46%
Maintainers
1
Weekly downloads
 
Created
Source

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

Keywords

url-join

FAQs

Package last updated on 06 May 2023

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.