Skip to content

Commit d823782

Browse files
committed
revival
1 parent d3e084b commit d823782

9 files changed

+1335
-5
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
coverage

.travis.yml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
language: node_js
2+
3+
node_js:
4+
- "0.11"
5+
- "0.10"
6+
- "0.8"
7+
8+
after_script: "npm install coveralls@2 && cat ./coverage/lcov.info | coveralls"

History.md

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
1.0.1 / 2014-08-27
2+
==================
3+
4+
* Ensure installation works correctly on 0.8
5+
6+
1.0.0 / 2014-08-17
7+
==================
8+
9+
* No more API changes
10+
11+
0.2.5 / 2014-08-07
12+
==================
13+
14+
* Allow keys parameter to be omitted
15+
16+
0.2.4 / 2014-08-02
17+
==================
18+
19+
* Code coverage badge
20+
* Updated readme
21+
* Attach keys to the generated regexp
22+
23+
0.2.3 / 2014-07-09
24+
==================
25+
26+
* Add MIT license
27+
28+
0.2.2 / 2014-07-06
29+
==================
30+
31+
* A passed in trailing slash in non-strict mode will become optional
32+
* In non-end mode, the optional trailing slash will only match at the end
33+
34+
0.2.1 / 2014-06-11
35+
==================
36+
37+
* Fixed a major capturing group regexp regression
38+
39+
0.2.0 / 2014-06-09
40+
==================
41+
42+
* Improved support for arrays
43+
* Improved support for regexps
44+
* Better support for non-ending strict mode matches with a trailing slash
45+
* Travis CI support
46+
* Block using regexp special characters in the path
47+
* Removed support for the asterisk to match all
48+
* New support for parameter suffixes - `*`, `+` and `?`
49+
* Updated readme
50+
* Provide delimiter information with keys array
51+
52+
0.1.2 / 2014-03-10
53+
==================
54+
55+
* Move testing dependencies to `devDependencies`
56+
57+
0.1.1 / 2014-03-10
58+
==================
59+
60+
* Match entire substring with `options.end`
61+
* Properly handle ending and non-ending matches
62+
63+
0.1.0 / 2014-03-06
64+
==================
65+
66+
* Add `options.end`
67+
68+
0.0.2 / 2013-02-10
69+
==================
70+
71+
* Update to match current express
72+
* Add .license property to component.json

LICENSE

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2014 Component
3+
Copyright (c) 2014 Blake Embrey ([email protected])
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal
@@ -9,13 +9,13 @@ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
99
copies of the Software, and to permit persons to whom the Software is
1010
furnished to do so, subject to the following conditions:
1111

12-
The above copyright notice and this permission notice shall be included in all
13-
copies or substantial portions of the Software.
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
1414

1515
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1616
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1717
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1818
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1919
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21-
SOFTWARE.
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

Readme.md

+150
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
# Path-to-RegExp
2+
3+
Turn an Express-style path string such as `/user/:name` into a regular expression.
4+
5+
[![NPM version][npm-image]][npm-url]
6+
[![Build status][travis-image]][travis-url]
7+
[![Test coverage][coveralls-image]][coveralls-url]
8+
9+
## Installation
10+
11+
```
12+
npm install path-to-regexp --save
13+
```
14+
15+
## Usage
16+
17+
```javascript
18+
var pathToRegexp = require('path-to-regexp');
19+
20+
// pathToRegexp(path, keys, options);
21+
```
22+
23+
- **path** A string in the express format, an array of strings, or a regular expression.
24+
- **keys** An array to be populated with the keys present in the url.
25+
- **options**
26+
- **sensitive** When `true` the route will be case sensitive. (default: `false`)
27+
- **strict** When `false` the trailing slash is optional. (default: `false`)
28+
- **end** When `false` the path will match at the beginning. (default: `true`)
29+
30+
```javascript
31+
var keys = [];
32+
var re = pathToRegexp('/foo/:bar', keys);
33+
// re = /^\/foo\/([^\/]+?)\/?$/i
34+
// keys = [{ name: 'bar', delimiter: '/', repeat: false, optional: false }]
35+
```
36+
37+
### Parameters
38+
39+
The path has the ability to define parameters and automatically populate the keys array.
40+
41+
#### Named Parameters
42+
43+
Named parameters are defined by prefixing a colon to the parameter name (`:foo`). By default, this parameter will match up to the next path segment.
44+
45+
```js
46+
var re = pathToRegexp('/:foo/:bar', keys);
47+
// keys = [{ name: 'foo', ... }, { name: 'bar', ... }]
48+
49+
re.exec('/test/route');
50+
//=> ['/test/route', 'test', 'route']
51+
```
52+
53+
#### Suffixed Parameters
54+
55+
##### Optional
56+
57+
Parameters can be suffixed with a question mark (`?`) to make the entire parameter optional. This will also make any prefixed path delimiter optional (`/` or `.`).
58+
59+
```js
60+
var re = pathToRegexp('/:foo/:bar?', keys);
61+
// keys = [{ name: 'foo', ... }, { name: 'bar', delimiter: '/', optional: true, repeat: false }]
62+
63+
re.exec('/test');
64+
//=> ['/test', 'test', undefined]
65+
66+
re.exec('/test/route');
67+
//=> ['/test', 'test', 'route']
68+
```
69+
70+
##### Zero or more
71+
72+
Parameters can be suffixed with an asterisk (`*`) to denote a zero or more parameter match. The prefixed path delimiter is also taken into account for the match.
73+
74+
```js
75+
var re = pathToRegexp('/:foo*', keys);
76+
// keys = [{ name: 'foo', delimiter: '/', optional: true, repeat: true }]
77+
78+
re.exec('/');
79+
//=> ['/', undefined]
80+
81+
re.exec('/bar/baz');
82+
//=> ['/bar/baz', 'bar/baz']
83+
```
84+
85+
##### One or more
86+
87+
Parameters can be suffixed with a plus sign (`+`) to denote a one or more parameters match. The prefixed path delimiter is included in the match.
88+
89+
```js
90+
var re = pathToRegexp('/:foo+', keys);
91+
// keys = [{ name: 'foo', delimiter: '/', optional: false, repeat: true }]
92+
93+
re.exec('/');
94+
//=> null
95+
96+
re.exec('/bar/baz');
97+
//=> ['/bar/baz', 'bar/baz']
98+
```
99+
100+
#### Custom Match Parameters
101+
102+
All parameters can be provided a custom matching regexp and override the default. Please note: Backslashes need to be escaped in strings.
103+
104+
```js
105+
var re = pathToRegexp('/:foo(\\d+)', keys);
106+
// keys = [{ name: 'foo', ... }]
107+
108+
re.exec('/123');
109+
//=> ['/123', '123']
110+
111+
re.exec('/abc');
112+
//=> null
113+
```
114+
115+
#### Unnamed Parameters
116+
117+
It is possible to write an unnamed parameter that is only a matching group. It works the same as a named parameter, except it will be numerically indexed.
118+
119+
```js
120+
var re = pathToRegexp('/:foo/(.*)', keys);
121+
// keys = [{ name: 'foo', ... }, { name: '0', ... }]
122+
123+
re.exec('/test/route');
124+
//=> ['/test/route', 'test', 'route']
125+
```
126+
127+
## Compatibility with Express <= 4.x
128+
129+
Path-To-RegExp breaks compatibility with Express <= 4.x in a few ways:
130+
131+
* RegExp special characters can now be used in the regular path. E.g. `/user[(\\d+)]`
132+
* All RegExp special characters can now be used inside the custom match. E.g. `/:user(.*)`
133+
* No more support for asterisk matching - use an explicit parameter instead. E.g. `/(.*)`
134+
* Parameters can have suffixes that augment meaning - `*`, `+` and `?`. E.g. `/:user*`
135+
* Strings aren't interpreted as literal regexp strings - no more non-capturing groups, lookaheads, lookbehinds or nested matching groups (but you can still pass a regexp manually)
136+
137+
## Live Demo
138+
139+
You can see a live demo of this library in use at [express-route-tester](http://forbeslindesay.github.com/express-route-tester/).
140+
141+
## License
142+
143+
MIT
144+
145+
[npm-image]: https://img.shields.io/npm/v/path-to-regexp.svg?style=flat
146+
[npm-url]: https://npmjs.org/package/path-to-regexp
147+
[travis-image]: https://img.shields.io/travis/component/path-to-regexp.svg?style=flat
148+
[travis-url]: https://travis-ci.org/component/path-to-regexp
149+
[coveralls-image]: https://img.shields.io/coveralls/component/path-to-regexp.svg?style=flat
150+
[coveralls-url]: https://coveralls.io/r/component/path-to-regexp?branch=master

component.json

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "path-to-regexp",
3+
"description": "Express style path to RegExp utility",
4+
"version": "1.0.1",
5+
"keywords": [
6+
"express",
7+
"regexp",
8+
"route",
9+
"routing"
10+
],
11+
"scripts": [
12+
"index.js"
13+
],
14+
"license": "MIT"
15+
}

0 commit comments

Comments
 (0)