npm.io
0.1.0 • Published 12 years ago

url-match

Licence
—
Version
0.1.0
Deps
1
Vulns
2
Weekly
0

url-match

url-match is a pattern matching for urls paths and query parameters based on the backbone router and the plugin backbone-query-parameters

install

npm install url-match

or

put this line in the dependencies section of your package.json:

"url-match": "0.1.0"

then run:

npm install

require

var urlMatch = require('url-match');
match urls
make pattern from string
var pattern = urlPattern.generate('/users/:id');
match pattern against url

match returns the extracted parameters or null if there was no match:

pattern.match('/projects/5'); // => null
pattern.match('/users/5'); // => [{id: '5'}, {}]
pattern.match('/users/5?a=b&c=d'); // => [{id: '5'}, {a: "b", c: "d"}]

Keywords