Skip to content

Commit 7b4598c

Browse files
committed
Document stringify method
1 parent d6150f5 commit 7b4598c

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

Readme.md

+22-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,13 @@ npm install path-to-regexp --save
1717
## Usage
1818

1919
```js
20-
const { match, pathToRegexp, compile, parse } = require("path-to-regexp");
20+
const {
21+
match,
22+
pathToRegexp,
23+
compile,
24+
parse,
25+
stringify,
26+
} = require("path-to-regexp");
2127
```
2228

2329
### Parameters
@@ -111,6 +117,21 @@ const toPathRaw = compile("/user/:id", { encode: false });
111117
toPathRaw({ id: "%3A%2F" }); //=> "/user/%3A%2F"
112118
```
113119

120+
## Stringify
121+
122+
Transform `TokenData` (a sequence of tokens) back into a Path-to-RegExp string.
123+
124+
- **data** A `TokenData` instance
125+
126+
```js
127+
const data = new TokenData([
128+
{ type: "text", value: "/" },
129+
{ type: "param", name: "foo" },
130+
]);
131+
132+
const path = stringify(data); //=> "/:foo"
133+
```
134+
114135
## Developers
115136

116137
- If you are rewriting paths with match and compile, consider using `encode: false` and `decode: false` to keep raw paths passed around.

0 commit comments

Comments
 (0)