JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 39
  • Score
    100M100P100Q68454F
  • License MIT

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

Package Exports

  • @iamnapo/construct-url

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@iamnapo/construct-url) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

@iamnapo/construct-url

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

build npm size license

Install

$ npm i @iamnapo/construct-url

Usage

const constructUrl = require("@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, any]] | { [key: string]: any } | URLSearchParams
Default: undefined

Query parameters to include in the resuliting URL.