npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@hyperjump/uri

v1.2.2

Published

A small and fast library for validating parsing and resolving URIs and IRIs

Downloads

11,656

Readme

URI

A small and fast library for validating, parsing, and resolving URIs (RFC 3986) and IRIs (RFC 3987).

Install

Designed for node.js (ES Modules, TypeScript) and browsers.

npm install @hyperjump/uri

Usage

import { resolveUri, parseUri, isUri, isIri } from "@hyperjump/uri"

const resolved = resolveUri("foo/bar", "http://example.com/aaa/bbb"); // https://example.com/aaa/foo/bar

const components = parseUri("https://[email protected]:80/foo?bar#baz"); // {
//   scheme: "https",
//   authority: "[email protected]:80",
//   userinfo: "jason",
//   host: "example.com",
//   port: "80",
//   path: "/foo",
//   query: "bar",
//   fragment: "baz"
// }

const a = isUri("http://examplé.org/rosé#"); // false
const a = isIri("http://examplé.org/rosé#"); // true

API

Resolve Relative References

These functions resovle relative-references against a base URI/IRI. The base URI/IRI must be absolute, meaning it must have a scheme (https) and no fragment (#foo). The resolution process will normalize percent-encoded characters and dot segments (/., /..).

  • resolveUri: (uriReference: string, baseUri: string) => string
  • resolveIri: (iriReference: string, baseIri: string) => string

Normalize

These functions apply two normalization rules.

  1. Decode any unnecessarily percent-encoded characters.
  2. Convert any lowercase characters in the hex numbers of percent-encoded characters to uppercase.
  3. Resolve and remove any dot-segments (/., /..) in paths.
  • normalizeUri: (uri: string) => string
  • normalizeIri: (iri: string, baseIri: string) => string

URI

A URI is not relative and may include a fragment.

  • isUri: (value: string) => boolean

  • parseUri: (value: string) => IdentifierComponents

  • toAbsoluteUri: (value: string) => string

    Takes a URI and strips its fragment component if it exists.

URI-Reference

A URI-reference may be relative.

  • isUriReference: (value: string) => boolean
  • parseUriReference: (value: string) => IdentifierComponents

absolute-URI

An absolute-URI is not relative an does not include a fragment.

  • isAbsoluteUri: (value: string) => boolean
  • parseAbsoluteUri: (value: string) => IdentifierComponents

IRI

An IRI is not relative and may include a fragment.

  • isIri: (value: string) => boolean

  • parseIri: (value: string) => IdentifierComponents

  • toAbsoluteIri: (value: string) => string

    Takes an IRI and strips its fragment component if it exists.

IRI-reference

An IRI-reference may be relative.

  • isIriReference: (value: string) => boolean
  • parseIriReference: (value: string) => IdentifierComponents

absolute-IRI

An absolute-IRI is not relative an does not include a fragment.

  • isAbsoluteIri: (value: string) => boolean
  • parseAbsoluteIri: (value: string) => IdentifierComponents

Types

  • IdentifierComponents
    • scheme: string
    • authority: string
    • userinfo: string
    • host: string
    • port: string
    • path: string
    • query: string
    • fragment: string

Contributing

Tests

Run the tests

npm test

Run the tests with a continuous test runner

npm test -- --watch