Socket
Socket
Sign inDemoInstall

path-pattern

Package Overview
Dependencies
1
Maintainers
3
Versions
23
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

path-pattern


Version published
Maintainers
3
Created

Readme

Source

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

Keywords

FAQs

Last updated on 23 Apr 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc