A small library to match and compile paths like /user/:name
This is a a wrapper around path-to-regexp.
Even if we use this package in production at Realytics and it is quite well tested, we can't garanty it won't break. If you want to use this, do it carefully and feel free to report issue so we can improve it π.
You need NodeJS and NPM or Yarn to install this package.
yarn add path-pattern
or npm install path-pattern --save
This package is inspired from the match
function from React Router. The main difference is that you don't have to pass the path everytime, instead you just create a "pattern" once and use it everywhere you need.
Note : If you use Typescript, typings are include in the package !
import { createPattern } from 'path-pattern';
const PathPattern = require('path-pattern').PathPattern;
// A basic route
const userRoute = new PathPattern('/home');
// You can then try to match it with apath
const noMatch = userRoute.match('/foo'); // => false
const match = userRoute.match('/home'); // => { isExact: true, params: {}, path: "/home", "url": "/home" }
We use SemVer for versioning. For the versions available, see the releases on this repository.
This project is licensed under the MIT License - see the LICENSE.md file for details