Skip to content

Commit 64fde72

Browse files
authored
Merge branch 'master' into 260-asterisk-parameter
2 parents 80d4d03 + b45871b commit 64fde72

File tree

11 files changed

+10514
-10958
lines changed

11 files changed

+10514
-10958
lines changed

.github/workflows/ci.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: CI
2+
on:
3+
- push
4+
- pull_request
5+
jobs:
6+
test:
7+
name: Node.js ${{ matrix.node-version }}
8+
runs-on: macos-latest
9+
strategy:
10+
matrix:
11+
node-version:
12+
- "12"
13+
- "*"
14+
steps:
15+
- uses: actions/checkout@v2
16+
- uses: actions/setup-node@v1
17+
with:
18+
node-version: ${{ matrix.node-version }}
19+
- uses: actions/cache@v2
20+
with:
21+
path: ~/.npm
22+
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
23+
restore-keys: |
24+
${{ runner.os }}-node-
25+
- run: npm install -g npm@8
26+
- run: npm ci
27+
- run: npm test
28+
- uses: codecov/codecov-action@v1
29+
with:
30+
name: Node.js ${{ matrix.node-version }}

.travis.yml

Lines changed: 0 additions & 10 deletions
This file was deleted.

Readme.md

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@
33
> Turn a path string such as `/user/:name` into a regular expression.
44
55
[![NPM version][npm-image]][npm-url]
6-
[![Build status][travis-image]][travis-url]
7-
[![Test coverage][coveralls-image]][coveralls-url]
8-
[![Dependency Status][david-image]][david-url]
6+
[![NPM downloads][downloads-image]][downloads-url]
7+
[![Build status][build-image]][build-url]
8+
[![Build coverage][coverage-image]][coverage-url]
99
[![License][license-image]][license-url]
10-
[![Downloads][downloads-image]][downloads-url]
1110

1211
## Installation
1312

@@ -26,9 +25,13 @@ const { pathToRegexp, match, parse, compile } = require("path-to-regexp");
2625
// compile(path)
2726
```
2827

28+
### Path to regexp
29+
30+
The `pathToRegexp` function will return a regular expression object based on the provided `path` argument. It accepts the following arguments:
31+
2932
- **path** A string, array of strings, or a regular expression.
30-
- **keys** An array to populate with keys found in the path.
31-
- **options**
33+
- **keys** _(optional)_ An array to populate with keys found in the path.
34+
- **options** _(optional)_
3235
- **sensitive** When `true` the regexp will be case sensitive. (default: `false`)
3336
- **strict** When `true` the regexp won't allow an optional trailing delimiter to match. (default: `false`)
3437
- **end** When `true` the regexp will match to the end of the string. (default: `true`)
@@ -194,6 +197,23 @@ fn("/invalid"); //=> false
194197
fn("/user/caf%C3%A9"); //=> { path: '/user/caf%C3%A9', index: 0, params: { id: 'café' } }
195198
```
196199

200+
The `match` function can be used to custom match named parameters. For example, this can be used to whitelist a small number of valid paths:
201+
202+
```js
203+
const urlMatch = match("/users/:id/:tab(home|photos|bio)", {
204+
decode: decodeURIComponent,
205+
});
206+
207+
urlMatch("/users/1234/photos");
208+
//=> { path: '/users/1234/photos', index: 0, params: { id: '1234', tab: 'photos' } }
209+
210+
urlMatch("/users/1234/bio");
211+
//=> { path: '/users/1234/bio', index: 0, params: { id: '1234', tab: 'bio' } }
212+
213+
urlMatch("/users/1234/otherstuff");
214+
//=> false
215+
```
216+
197217
#### Process Pathname
198218

199219
You should make sure variations of the same path match the expected `path`. Here's one possible solution using `encode`:
@@ -321,15 +341,13 @@ You can see a live demo of this library in use at [express-route-tester](http://
321341

322342
MIT
323343

324-
[npm-image]: https://img.shields.io/npm/v/path-to-regexp.svg?style=flat
344+
[npm-image]: https://img.shields.io/npm/v/path-to-regexp
325345
[npm-url]: https://npmjs.org/package/path-to-regexp
326-
[travis-image]: https://img.shields.io/travis/pillarjs/path-to-regexp.svg?style=flat
327-
[travis-url]: https://travis-ci.org/pillarjs/path-to-regexp
328-
[coveralls-image]: https://img.shields.io/coveralls/pillarjs/path-to-regexp.svg?style=flat
329-
[coveralls-url]: https://coveralls.io/r/pillarjs/path-to-regexp?branch=master
330-
[david-image]: http://img.shields.io/david/pillarjs/path-to-regexp.svg?style=flat
331-
[david-url]: https://david-dm.org/pillarjs/path-to-regexp
346+
[downloads-image]: https://img.shields.io/npm/dm/path-to-regexp
347+
[downloads-url]: https://npmjs.org/package/path-to-regexp
348+
[build-image]: https://img.shields.io/github/workflow/status/pillarjs/path-to-regexp/CI/master
349+
[build-url]: https://github.com/pillarjs/path-to-regexp/actions/workflows/ci.yml?query=branch%3Amaster
350+
[coverage-image]: https://img.shields.io/codecov/c/gh/pillarjs/path-to-regexp
351+
[coverage-url]: https://codecov.io/gh/pillarjs/path-to-regexp
332352
[license-image]: http://img.shields.io/npm/l/path-to-regexp.svg?style=flat
333353
[license-url]: LICENSE.md
334-
[downloads-image]: http://img.shields.io/npm/dm/path-to-regexp.svg?style=flat
335-
[downloads-url]: https://npmjs.org/package/path-to-regexp

0 commit comments

Comments
 (0)