From 7b4598c051126cfaccf931abd472fd5e3c14ac95 Mon Sep 17 00:00:00 2001 From: Blake Embrey Date: Mon, 9 Sep 2024 17:08:30 -0700 Subject: [PATCH] Document stringify method --- Readme.md | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/Readme.md b/Readme.md index 3c24e66..455c935 100644 --- a/Readme.md +++ b/Readme.md @@ -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 @@ -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.