From 87651fa793a6beb47bf56e5007b3c1b60e376161 Mon Sep 17 00:00:00 2001 From: Forbes Lindesay Date: Sun, 16 Sep 2012 03:35:33 +0100 Subject: [PATCH] Add documentation --- Readme.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/Readme.md b/Readme.md index 09da03e..95c2cb5 100644 --- a/Readme.md +++ b/Readme.md @@ -3,6 +3,30 @@ Turn an Express-style path string such as `/user/:name` into a regular expression. +## Usage + +```javascript +var pathToRegexp = require('path-to-regexp'); +``` +### pathToRegexp(path, keys, options) + + - **path** A string in the express format, an array of such strings, or a regular expression + - **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. + +```javascript +var keys = []; +var exp = pathToRegexp('/foo/:bar', keys); +//keys = ['bar'] +//exp = /^\/foo\/(?:([^\/]+?))\/?$/i +``` + +## Live Demo + +You can see a live demo of this library in use at [express-route-tester](http://forbeslindesay.github.com/express-route-tester/). + ## License MIT \ No newline at end of file