Skip to content

Getting Started

Follow these simple steps to quickly start using route-peek in your application.

Installation

You can install route-peek using the JavaScript package manager:

sh
npm add route-peek
sh
pnpm add route-peek
sh
yarn add route-peek
sh
bun add route-peek

Compatibility Note

Please ensure that Node.js version 18 or higher is installed in your project.

Usage

Import route-peek into your project:

index.ts
ts
import { RouteMatcherBuilder } from 'route-peek';

Define a routes you want to match:

index.ts
ts
import { RouteMatcherBuilder } from 'route-peek';

const builder = new RouteMatcherBuilder(); 

builder.add('/');
builder.add('/users/{id:[0-9]+}');

const matcher = builder.build();

Use the created instance to match a URL and extract parameters:

index.ts
ts
import { RouteMatcherBuilder } from 'route-peek';

const builder = new RouteMatcherBuilder();

builder.add('/');
builder.add('/users/{id:[0-9]+}');

const matcher = builder.build();
const matchedRoutes = matcher.match('/users/123'); 

for (const matchedRoute of matchedRoutes) {
  console.log(matchedRoute);
}

Released under the MIT License.