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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@helix-re/url-pattern

v1.0.1

Published

Validate URLs and extract values easily!

Readme

URL Pattern

Validate URLs and extract values easily!

Installation

Using npm

npm i @helix-re/url-pattern

Usage

Note: URL Pattern supports both ES and CJS modules.

To use the APIs, you will need to understand the concept of a namespace. We define namespace as one or more characters between 2 slashes. Let's look at an example URL.

https://example.com/foo/bar/

We recommend using URL Pattern only with the pathname part of the URL.

/foo/bar/

We also define a concept of named and anonymous namespaces. Let's see how they work in practice on the example URL. There are 2 anonymous namespaces foo and bar, or 1 named namespace foo with value bar.

The reason we define 2 concepts is that a typical application might use a combination of both. For example, if we look at the HELIX RE office on Google Maps.

https://google.com/maps/place/HELIX+RE/@51.5333649,-0.1075597,17z/data=!3m1!4b1!4m5!3m4!1s0x48761bb724ab195d:0x1c29f788dbea0821!8m2!3d51.5333649!4d-0.1053657

Again, remove the domain part.

/maps/place/HELIX+RE/@51.5333649,-0.1075597,17z/data=!3m1!4b1!4m5!3m4!1s0x48761bb724ab195d:0x1c29f788dbea0821!8m2!3d51.5333649!4d-0.1053657
  • maps is an anonymous namespace
  • place is a named namespace with value HELIX+RE
  • @51.5333649,-0.1075597,17z is an anonymous namespace
  • data=!3m1!4b1!4m5!3m4!1s0x48761bb724ab195d:0x1c29f788dbea0821!8m2!3d51.5333649!4d-0.1053657 is an anonymous namespace

Let's look at how we can extract the place namespace with URL Pattern.

import { required, select } from '@helix-re/url-pattern';

const pattern = required() + select('place');
url.match(new RegExp(`^${pattern}`))[1]; // 'HELIX+RE'

All we had to do was require an anonymous namespace (maps) and select the value of a named namespace place.

Another common use case is defining optional namespaces. Let's assume Google Maps works even if you skip the initial /maps/ prefix. We could make our selector work like this.

import { optional, select } from '@helix-re/url-pattern';

const pattern = optional('maps') + select('place');
url.match(new RegExp(`^${pattern}`))[1]; // 'HELIX+RE'

Our pattern will now match the following URL as well.

/place/HELIX+RE/@51.5333649,-0.1075597,17z/data=!3m1!4b1!4m5!3m4!1s0x48761bb724ab195d:0x1c29f788dbea0821!8m2!3d51.5333649!4d-0.1053657

API

- optional(values)

Denotes one or more optional anonymous namespaces. Note that you need to know their values in advance.

- required(name)

Denotes a required namespace. Accepts an optional name parameter. If skipped, we require an anonymous namespace.

- select(name)

Selects a namespace value which can be accessed in the matched result. Accepts an optional name parameter. If skipped we select an anonymous namespace.