Skip to content

Commit

Permalink
Fix readme example
Browse files Browse the repository at this point in the history
  • Loading branch information
blakeembrey committed Aug 9, 2023
1 parent 534b77c commit 11cfcc1
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -284,15 +284,14 @@ const toPath = compile("/user/:id", { encode: encodeURIComponent });

toPath({ id: 123 }); //=> "/user/123"
toPath({ id: "café" }); //=> "/user/caf%C3%A9"
toPath({ id: "/" }); //=> "/user/%2F"

toPath({ id: ":/" }); //=> "/user/%3A%2F"

// Without `encode`, you need to make sure inputs are encoded correctly.
const toPathRaw = compile("/user/:id");
// (Note: You can use `validate: false` to create an invalid paths.)
const toPathRaw = compile("/user/:id", { validate: false });

toPathRaw({ id: "%3A%2F" }); //=> "/user/%3A%2F"
toPathRaw({ id: ":/" }, { validate: false }); //=> "/user/:/"
toPathRaw({ id: ":/" }); //=> "/user/:/"

const toPathRepeated = compile("/:segment+");

Expand All @@ -303,8 +302,6 @@ const toPathRegexp = compile("/user/:id(\\d+)");

toPathRegexp({ id: 123 }); //=> "/user/123"
toPathRegexp({ id: "123" }); //=> "/user/123"
toPathRegexp({ id: "abc" }); //=> Throws `TypeError`.
toPathRegexp({ id: "abc" }, { validate: false }); //=> "/user/abc"
```

**Note:** The generated function will throw on invalid input.
Expand Down

0 comments on commit 11cfcc1

Please sign in to comment.