3.0.2 • Published 11 months ago

@iamnapo/construct-url v3.0.2

Weekly downloads
13
License
MIT
Repository
github
Last release
11 months ago

@iamnapo/construct-url

Small utility function to construct URLs, without caring about slashes or encoding

build npm

Install

npm i @iamnapo/construct-url

Usage

import constructUrl from "@iamnapo/construct-url";

constructUrl("https://example.com", "/foo"); // => "https://example.com/foo"
constructUrl("https://example.com/foo", "/bar"); // => "https://example.com/foo/bar"
constructUrl("https://example.com", "/foo", { bar: true }); // => "https://example.com/foo?bar=true"
constructUrl("https://example.com", "", { bar: true }); // => "https://example.com/?bar=true"
constructUrl("https://example.com", "/foo", { "//bar//": true }); // => "https://example.com/foo?%2F%2Fbar%2F%2F=true"

API

constructUrl(base, path?, query?)

Get a full URL, including encoded query parameters.

base

Type: string | URL

Base URL.

path

Type: string\ Default: ""

Path relative to base.

query

Type: string | [string, unknown][] | Record<string, unknown> | URLSearchParams\ Default: ""

Query parameters to include in the resuliting URL.

3.0.2

11 months ago

3.0.1

2 years ago

3.0.0

2 years ago

2.1.0

2 years ago

2.0.1

3 years ago

2.0.0

3 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago