path-match

1.2.4 • Public • Published

path match

NPM version Build status Test coverage Dependency Status License Downloads

Thin wrapper around path-to-regexp to make extracting the param names easier.

var route = require('path-match')({
  // path-to-regexp options
  sensitive: false,
  strict: false,
  end: false,
});
 
// create a match function from a route
var match = route('/post/:id');
 
// match a route
var parse = require('url').parse;
require('http').createServer(function (req, res) {
  var params = match(parse(req.url).pathname);
 
  // no match
  if (params === false) {
    res.statusCode = 404;
    res.end();
    return;
  }
 
  // the matched id
  var id = params.id;
 
  // do stuff with the ID
})

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.2.4
    442,948
    • latest

Version History

Package Sidebar

Install

npm i path-match

Weekly Downloads

444,870

Version

1.2.4

License

MIT

Last publish

Collaborators

  • sindresorhus
  • fishrock123
  • dougwilson
  • jongleberry
  • defunctzombie