Skip to content

Commit

Permalink
Document stringify method
Browse files Browse the repository at this point in the history
  • Loading branch information
blakeembrey committed Sep 10, 2024
1 parent d6150f5 commit 7b4598c
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@ npm install path-to-regexp --save
## Usage

```js
const { match, pathToRegexp, compile, parse } = require("path-to-regexp");
const {
match,
pathToRegexp,
compile,
parse,
stringify,
} = require("path-to-regexp");
```

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

## Stringify

Transform `TokenData` (a sequence of tokens) back into a Path-to-RegExp string.

- **data** A `TokenData` instance

```js
const data = new TokenData([
{ type: "text", value: "/" },
{ type: "param", name: "foo" },
]);

const path = stringify(data); //=> "/:foo"
```

## Developers

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

0 comments on commit 7b4598c

Please sign in to comment.