Newly Practicing Mortician

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

    3.0.1 • Public • Published

    @iamnapo/construct-url

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

    build npm size

    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, any]] | { [key: string]: any } | URLSearchParams
    Default: ""

    Query parameters to include in the resuliting URL.

    Install

    npm i @iamnapo/construct-url

    DownloadsWeekly Downloads

    20

    Version

    3.0.1

    License

    MIT

    Unpacked Size

    6.07 kB

    Total Files

    5

    Last publish

    Collaborators

    • iamnapo