open-path
Url path parser for OpenAPI.
Install
$ npm i open-path
Usage
var Parse = ;var parse = '/user/{category}/today/{tag}/detail';// or// var parse = new Parse('/user/:category/today/:tag/detail'); console;// prints: /user/{category}/today/{tag}/detail // matchparse; // returns params if matched or null // buildparse;// returns: /user/tech/today/mobile/detail
Parameters
The path argument is used to define parameters.
Named Parameters
Named parameters are defined by prefixing a colon to the parameter name (:foo) or surround with braces ({foo}). By default, the parameter will match until the following path segment.
Unnamed Parameters
Unnamed parameters are defined by regexp and naming by index.
Parameter Modifiers
Optional
Parameters can be suffixed with a question mark (?) to make the parameter optional.
var parse = '/:foo/:bar?';
Zero or more
Parameters can be suffixed with an asterisk (*) to denote a zero or more parameter matches. The prefix is taken into account for each match.
var parse = '/:foo*';
One or more
Parameters can be suffixed with a plus sign (+) to denote a one or more parameter matches. The prefix is taken into account for each match.
var parse = '/:foo+';
Path
Path can be suffixed with an asterisk (*) or plus sign (+) to allow more path matches.
Zero or more
var parse = '/api*';
One or more
var parse = '/api+';