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

5.5.5 • Public • Published

resolve-url

A tiny TypeScript library to resolve URLs.

Features

  • Lightweight and fast.
  • Cross-platform support.
  • Written in TypeScript.
  • Handles leading and trailing slashes.
  • Removes empty parts.
  • Replaces multiple slashes with a single slash.
  • Preserves protocol slashes.

Installation

npm install @alwatr/resolve-url

Usage

import {resolveUrl} from '@alwatr/resolve-url';

console.log(resolveUrl('/', 'ali', 'v1')); // '/ali/v1'
console.log(resolveUrl('/', '/ali/', '/v1')); // '/ali/v1'
console.log(resolveUrl('[https://domain.com](https://domain.com)', 'ali', 'v1')); // https://domain.com/ali/v1

API

resolveUrl(...parts: string[]): string

Resolves a URL from multiple parts.

Parameters:

  • parts: The parts of the URL to resolve.

Returns:

The resolved URL.

Examples

resolveUrl('foo', 'bar'); // 'foo/bar'
resolveUrl('/foo', 'bar'); // '/foo/bar'
resolveUrl('/foo/', 'bar'); // '/foo/bar'
resolveUrl('/foo//', 'bar'); // '/foo/bar'
resolveUrl('/foo/', '/bar/'); // '/foo/bar'
resolveUrl('https://example.com', 'foo', 'bar'); // 'https://example.com/foo/bar'
resolveUrl('https://example.com/', '/foo/', '/bar/'); // 'https://example.com/foo/bar'

Sponsors

The following companies, organizations, and individuals support Nanolib ongoing maintenance and development. Become a Sponsor to get your logo on our README and website.

Contributing

Contributions are welcome! Please read our contribution guidelines before submitting a pull request.

License

This project is licensed under the AGPL-3.0 License.

/@alwatr/resolve-url/

    Package Sidebar

    Install

    npm i @alwatr/resolve-url

    Weekly Downloads

    100

    Version

    5.5.5

    License

    AGPL-3.0-only

    Unpacked Size

    55 kB

    Total Files

    11

    Last publish

    Collaborators

    • alimd