You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

32 lines
1.0 KiB

8 years ago
  1. # Path-to-RegExp
  2. Turn an Express-style path string such as `/user/:name` into a regular expression.
  3. ## Usage
  4. ```javascript
  5. var pathToRegexp = require('path-to-regexp');
  6. ```
  7. ### pathToRegexp(path, keys, options)
  8. - **path** A string in the express format, an array of such strings, or a regular expression
  9. - **keys** An array to be populated with the keys present in the url. Once the function completes, this will be an array of strings.
  10. - **options**
  11. - **options.sensitive** Defaults to false, set this to true to make routes case sensitive
  12. - **options.strict** Defaults to false, set this to true to make the trailing slash matter.
  13. - **options.end** Defaults to true, set this to false to only match the prefix of the URL.
  14. ```javascript
  15. var keys = [];
  16. var exp = pathToRegexp('/foo/:bar', keys);
  17. //keys = ['bar']
  18. //exp = /^\/foo\/(?:([^\/]+?))\/?$/i
  19. ```
  20. ## Live Demo
  21. You can see a live demo of this library in use at [express-route-tester](http://forbeslindesay.github.com/express-route-tester/).
  22. ## License
  23. MIT