New:Microsoft Teams Notifications Are Now Available in Socket.Learn more
Get Started

@anymud/uri

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@anymud/uri

A JavaScript library for parsing, resolving, and stringifying Uniform Resource Identifiers (URIs).

latest
Source
npmnpm
Version
0.1.4
Version published
Maintainers
1
Created
Source

@anymud/uri

A lightweight JavaScript library for handling Uniform Resource Identifiers (URIs) efficiently.

Installation

You can install the @anymud/uri package via npm, yarn, pnpm or bun:

# npm
npm install @anymud/uri

#yarn
yarn add @anymud/uri

# pnpm
npm install @anymud/uri

# bun
bun install @anymud/uri

Usage

Importing

You can import the library in your JavaScript/TypeScript files as follows:

import * as uri from '@anymud/uri';

Functions

parseUri(uri: string): UriComponents

This function parses a URI string and returns its components as an object conforming to the UriComponents interface.

resolveUri(baseComponents: UriComponentsInput, relativeComponents: UriComponentsInput): UriComponents

This function resolves a relative URI against a base URI and returns the resulting URI components.

toString(components: UriComponentsInput): string

Converts a URI components object into a URI string.

getSubdomain(components: RequiredComponent<'host'>, tlds: string[] = KnownTlds): string

Extracts the subdomain from the host component of a URI.

Full Reference: https://anymud.github.io/uri/

Example

import { parseUri, resolveUri, toString } from '@anymud/uri';

const uriString = 'https://www.example.com/path/to/resource?query=123#fragment';
const parsedUri = parseUri(uriString);
console.log(parsedUri);

const baseUri = {
  scheme: 'https',
  host: 'www.example.com',
  path: '/base',
};

const relativeUri = {
  path: 'path/to/resource',
  query: 'query=123',
  fragment: 'fragment',
};

const resolvedUri = resolveUri(baseUri, relativeUri);
console.log(resolvedUri);

const uriString = toString(resolvedUri);
console.log(uriString);

License

This library is released under the MIT License. See the LICENSE file for details.

Keywords

URI

FAQs

Package last updated on 26 Feb 2024

Related posts