REST-to-RegExp
Turn a REST style path string into a regular expression.
Usage
var restToRegexp = ;
1. restToRegexp(path, keys, options)
2. restToRegexp({path, rules}, keys, options)
- path A string in the express format, an array of such strings, or a regular expression
- rules An object of regular expression mapping.
- keys An array to be populated with the keys present in the url. Once the function completes, this will be an array of strings.
- options
- options.sensitive Defaults to false, set this to true to make routes case sensitive
- options.strict Defaults to false, set this to true to make the trailing slash matter.
var keys = ; var exp1 = ; var exp2 = ; //keys = ['bar']
Format of path
(/ [prefix] name (validator) <alias> [suffix])+
Alias
var keys = ;var exp = ;//keys = ['list', 'page'] // matchesexp;exp; // not matchexp;exp;
rules
var keys = ;var exp = ;//keys = ['foo', 'baz'] // also you can define rules this way:exp = ; // matchesexp;exp;exp;exp; // not matchexp;
Prefixes
1. normal part (:)
var exp = ;// keys = ['bar'] // matchesexptext'/foo/bar/2'; // not matchexptext'/foo/bar';exptext'/foo';
2. optional part (#)
var exp = ;// keys = ['bar'] // matchesexp;exp; // not matchexp;
3. follow previous part (+ or *)
var exp = ;// keys = ['filter', 'begin', 'end', 'page'] // /+begin should follow /#filter// /*end follow /+begin optional // matchesexp;exp;exp; // not matchexp;exp;exp;exp;
Usage of suffixes
1. match single value (<empty> or ?)
var exp = ;// keys = ['bar', 'baz', 'qux'] // matchesexp;exp;exp; // not matchexp;
2. match multiple values (+ or *)
var exp = ;// keys = ['bar', 'baz', 'qux'] // matchesexp;exp;exp;exp; // not matchexp;
License
MIT