Skip to content

mytecor/path2regexp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

path2regexp

Usage

let p2r = require('path2regexp')

// Optional parameters
let ex1 = p2r('/user/:login/:method?/:action')
console.log(ex1('/user/mytecor/test')) // {login: 'mytecor', method: undefined, action: 'test'}
console.log(ex1('/user/mytecor/get/test')) // {login: 'mytecor', method: 'get', action: 'test'}

// Unnamed parameters
let ex2 = p2r('/user/(.*)/:action')
console.log(ex2('/user/get/test')) // {unnamed: ['get'], action: 'test'}

// Regexp route
let ex3 = p2r(/\/user\/(.*)/)
console.log(ex3('/user/get/test')) // {unnamed: ['get/test']}

// Other routes
let ex4 = p2r('/user/(get|post)/:action')
console.log(ex4('/user/post/test')) // {unnamed: ['post'], action: 'test'}

Releases

No releases published

Packages

No packages published