Match a string by sinatra/express style named-params, or regexes, and get something back.
npm i --save byway
var Byway = require('byway'), routes = require('someroutes'), //json, or js, that exports an array of objects byway = new Byway(routes);
Here the value of
routes is an array of objects, with the following properties:
pattern- required string to convert to a regular expression, or a literal RegExp
isregex- optional true if
patternis a string you want to convert to a regex
param- optional anything; this is returned as part of a match, if truthy.
Once you've created a
byway object, determine if a string matches any of the
var match = byway.of(some_string);
some_string wasn't matched by any
match is false. Otherwise, the return value is an object with the following properties:
input- the original string that was passed to of()
param- the value of the param property defined in the corresponding route
parts- an object with key/value pairs corresponding to the matched named patterns, or an array containing the text captured by your regex subpatterns, if any.
named spot patterns
named spot patterns do a non-greedy match for any characters within the p
npm run-script cover npm run-script plato
MIT, see LICENSE.txt.