matchPathTemplate()function
matchPathTemplate(template: AbsolutePath, target: AbsolutePath, caller: AnyCaller = matchPathTemplate): TemplateMatches | undefined
| Param | Type | |
|---|---|---|
template | AbsolutePath | The path-shaped template string, e.g. /users/{name}. required |
target | AbsolutePath | The path containing values, e.g. /users/Dave. required |
caller | AnyCaller | Function to attribute a thrown error to (defaults to matchPathTemplate itself). Defaults to matchPathTemplate |
| Return | |
|---|---|
TemplateMatches | undefined | An object containing values (e.g. { name: "Dave" }), or undefined if no match. |
| Throws | |
|---|---|
ValueError | If two template placeholders are not separated by at least one character. |
Match a path-shaped template against a target path.
- Like
matchTemplate(), but with/segment semantics: non-catchall placeholders cannot span path segments; catchall placeholders can. - A trailing catchall (e.g.
/files/{...path}) also matches when the trailing separator is absent (e.g./files), with the catchall value as"".
Examples
matchPathTemplate("/users/{name}", "/users/Dave") // { name: "Dave" }