Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@alwatr/resolve-url

Package Overview
Dependencies
Maintainers
0
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@alwatr/resolve-url

A tiny TypeScript library to resolve URLs.

  • 5.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
0
Created
Source

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.

Exir Studio

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.

Keywords

FAQs

Package last updated on 02 Nov 2024

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc