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-peeksh
pnpm add route-peeksh
yarn add route-peeksh
bun add route-peekCompatibility Note
Please ensure that Node.js version 18 or higher is installed in your project.
Usage
Import route-peek into your project:
ts
import { RouteMatcherBuilder } from 'route-peek';Define a routes you want to match:
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:
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);
}