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 🙏

© 2025 – Pkg Stats / Ryan Hefner

pica-route

v1.1.2

Published

A pure URL pattern matching library compatible with route-parser API

Readme

Pica Route

A pure TypeScript URL pattern matching library compatible with the route-parser API.

Features

  • Multiple formats - ESM, CommonJS, and IIFE builds available
  • Pure TypeScript - No dependencies, fully typed
  • Compatible API - Drop-in replacement for route-parser
  • Comprehensive pattern matching - Supports parameters, splats, optional groups, and query parameters
  • Reversible routes - Generate URLs from parameters
  • Parser-based implementation - Clean and maintainable code
  • Thoroughly tested - Comprehensive Jest test suite

Installation

npm install pica-route

Usage

ESM (ES Modules)

import { Route } from 'pica-route';

const route = new Route('/users/:id');

// Match URLs
route.match('/users/123'); // { id: '123' }
route.match('/users/john'); // { id: 'john' }

// Reverse generation
route.reverse({ id: 456 }); // '/users/456'

CommonJS

const { Route } = require('pica-route');

const route = new Route('/users/:id');
const result = route.match('/users/123'); // { id: '123' }

IIFE (Browser)

<script src="https://unpkg.com/pica-route/dist/index.iife.min.js"></script>
<script>
  const { Route } = PicaRoute;
  const route = new Route('/api/:version');
  console.log(route.match('/api/v1')); // { version: 'v1' }
</script>

Route Syntax

Parameters

  • :name - Captures a parameter up to /, ?, or end of string
const route = new Route('/users/:id/comments/:comment');
route.match('/users/123/comments/456'); // { id: 123, comment: 456 }

Splats

  • *name - Captures everything up to ? or end of string
const route = new Route('/files/*path');
route.match('/files/documents/readme.txt'); // { path: 'documents/readme.txt' }

Optional Groups

  • () - Optional sections that can contain parameters, splats, or nested optional groups
const route = new Route('/api/users(/:id)(/:action)');
route.match('/api/users'); // {}
route.match('/api/users/123'); // { id: 123 }
route.match('/api/users/123/edit'); // { id: 123, action: 'edit' }

Query Parameters

Query parameters work with the same syntax as path parameters.

const route = new Route('/books?author=:author&subject=:subject');
route.match('/books?author=tolkien&subject=fantasy');
// { author: 'tolkien', subject: 'fantasy' }

API

Constructor

new Route(pattern: string)

Creates a new route instance from a pattern string.

match(url: string)

match(url: string): RouteParams | false

Attempts to match a URL against the route pattern. Returns an object with captured parameters or false if no match.

reverse(params: RouteParams)

reverse(params?: RouteParams): string

Generates a URL from the route pattern using the provided parameters.

Examples

Basic Usage

const route = new Route('/users/:id/comments/:comment/rating/:rating');

route.match('/users/123/comments/456/rating/5');
// { id: 123, comment: 456, rating: 5 }

route.reverse({ id: 123, comment: 456, rating: 5 });
// '/users/123/comments/456/rating/5'

Splat Routes

const route = new Route('/books/*section/:title');

route.match('/books/programming/javascript/learning-js');
// { section: 'programming/javascript', title: 'learning-js' }

Optional Groups

const route = new Route('/some/(optional/):thing');

route.match('/some/optional/value'); // { thing: 'value' }
route.match('/some/value');          // { thing: 'value' }

Query Parameters

const route = new Route('/search?q=:query');

route.match('/search?q=javascript'); // { query: 'javascript' }

TypeScript Support

Full TypeScript support with proper type definitions:

interface RouteParams {
  [key: string]: string | number;
}

class Route {
  match(url: string): RouteParams | false;
  reverse(params?: RouteParams): string;
}

Testing

npm test

Building

npm run build

Development

# Install dependencies
npm install

# Run tests
npm test

# Run tests in watch mode
npm run test:watch

# Build the project
npm run build

# Development build with watch
npm run dev

Release

This project uses semantic-release for automated versioning and publishing.

# Dry run to see what would be released
npm run release:dry

# Create a release (requires proper git setup and npm auth)
npm run release

Commit Message Format

Follow the Conventional Commits specification:

  • feat: - new features (minor version bump)
  • fix: - bug fixes (patch version bump)
  • refactor: - code refactoring (minor version bump)
  • perf: - performance improvements (patch version bump)
  • docs: - documentation changes (patch version bump)
  • chore(deps): - dependency updates (patch version bump)
  • BREAKING CHANGE: - breaking changes (major version bump)

License

MIT