path-pattern
TypeScript icon, indicating that this package has built-in type declarations

2.1.1 • Public • Published

path-pattern logo

Path Pattern npm travis

A small library to match and compile paths like /user/:name

This is a a wrapper around path-to-regexp.

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

Package Sidebar

Install

npm i path-pattern

Weekly Downloads

0

Version

2.1.1

License

MIT

Unpacked Size

56.3 kB

Total Files

18

Last publish

Collaborators

  • gwendalperon
  • realytics-tech
  • vincentnguyenhuu