Security News
ESLint is Now Language-Agnostic: Linting JSON, Markdown, and Beyond
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
path-pattern
Advanced tools
A small library to match and compile paths
This is a a wrapper aroud path-to-regexp.
This package is under developement, do not use it in production.
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.
You need NodeJS and NPM or Yarn.
npm install path-pattern --save
or
yarn add path-pattern
const PathPattern = require('path-pattern').PathPattern;
Note : If you use Typescript, typings are include in the package !
import { PathPattern } fropm 'path-pattern';
##Usage
const homePattern = new PathPattern('/home');
// same as
const homePattern = new PathPattern('/home', { exact: false, strict: false });
PathPattern
new PathPattern<P>(path: string, options?: { strict?: boolean, exact?: boolean })
P
: Type of params object (in Match resulr)path
: The path pattern to parse, see path-to-regexp docsoption.strict
: (false
by default) When true
, a path that has a trailing slash will only match a location.pathname with a trailing slash. This has no effect when there are additional URL segments in the location.pathnameoption.exact
: (false
by default) When true
, the path will not match sub path (see table below)new PathPattern('/home')
(any path that start with home)
/home
/home/
/home/user
/home/user/
/home/user/john
/
/welcome
new PathPattern('/home', { exact: true })
(home path)
/home
/home/
/home/user
/home/user/
/home/user/john
/
/welcome
new PathPattern('/home/', { exact: true, strict: true })
(home path with a trailing slash)
/home/
/home
/home/user
/home/user/
/home/user/john
/
/welcome
match(location: string): (Match<P> | false)
location
: the location.pathname
you want to matchMatch
object is the location match the path, false if not. See Match object bellowcompile(params: P): string
Match
Match is a plain object that contain the following keys:
path: string
: The path that match, example: /user/:user
url: string
: The url that match, example: /user/john
,isExact: boolean
: Is the match an exact match example: false
,params: {[paramName: string]: any}
: Params found, example: { 'user': 'john' }
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
FAQs
A url matching lib to go with Realytics/react-router-magic
The npm package path-pattern receives a total of 0 weekly downloads. As such, path-pattern popularity was classified as not popular.
We found that path-pattern demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
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.
Security News
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
Security News
Members Hub is conducting large-scale campaigns to artificially boost Discord server metrics, undermining community trust and platform integrity.
Security News
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.