New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

urljoins

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

urljoins

Trailing-Slash compatible urljoin

latest
Source
npmnpm
Version
0.0.3
Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

urljoins

Trailing-Slash compatible join utility.

Install

npm i urljoins

Usage

import {urljoins} from "urljoins";

console.log(urljoins("a.test/", "/a", "b")); // a.test/a/b

Try on https://npm.runkit.com/urljoins

var urljoins = require("urljoins").urljoins;

console.log(urljoins("a.test", {key1: "v1", key2: "v2"})); // a.test?key1=v1&key2=v2

Feature

Trailing-Slash compatible.

urljoins("a.test", "/a", "b"); // a.test/a/b
urljoins("a.test/", "/a", "b", "c"); // a.test/a/b/c

Spread key-value objects.

urljoins("a.test", {key1: "v1", key2: "v2"}); // a.test?key1=v1&key2=v2
urljoins("a.test", {key1: "v1", key2: undefined, key3:"v3"}); // a.test?key1=v1&key2=&key3=v3
urljoins("a.test", {key1: "v1", key2: null, key3: "v3"}); // same as undefined value
urljoins("a.test", {key1: "v1", key2: "v2"}, "/a"); // a.test?key1=v1&key2=v2&/a
urljoins("a.test", {keys: ["v1", "v2"]}); // a.test?keys[]=v1&keys[]=v2

Some other trailing (or heading) treatments.

urljoins("a.test?", "?a", "b"); // a.test?a&b

Notes

Parameter Orders

Parameter-Orders are strict.
When first "?" delimiter is found, all remaining strings are joined as query.

/*
 it returns "a.test?key1=v1&/a"
 not "a.test/a?key1=v1"
 */
urljoin("a.test?key1=v1", "/a");

Array(s) of strings

urljoins receives Rest Parameter. So you can spread any string[];

const paths = ["a.test", "a", "b"];
urljoins(...paths); // same as urljoins("a.test", "a", "b");

FAQs

Package last updated on 18 Apr 2022

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