path-pattern
v2.1.1
Published
A url matching lib to go with Realytics/react-router-magic
Downloads
14
Readme
This package might contain a few bugs
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 😉.
Prerequisites
You need NodeJS and NPM or Yarn to install this package.
Installing
yarn add path-pattern
or npm install path-pattern --save
Motivations
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.
Import in your project
ES6 or Typescript
Note : If you use Typescript, typings are include in the package !
import { createPattern } from 'path-pattern';
Node
const PathPattern = require('path-pattern').PathPattern;
Some examples
// 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" }
Versioning
We use SemVer for versioning. For the versions available, see the releases on this repository.
License
This project is licensed under the MIT License - see the LICENSE.md file for details