Function: normalizeParamNames()
API / @xmachines/play-url / index / normalizeParamNames
function normalizeParamNames(path): string;Defined in: packages/play-url/src/url-pattern-utils.ts:139
Normalizes a route path, so that each of its parameter names is a valid URLPattern identifier.
URLPattern requires a valid JS identifier as a parameter name, and such an identifier
holds no hyphen. Therefore the function replaces a name with a hyphen, for example
:cat-id, with the equivalent name with an underscore (:cat_id), for the compilation
step of URLPattern. A caller that needs the values of the captured groups, and not a
test of the match alone, must map each normalized group name back to the original param
name with getNormalizedParamNameMap.
Parameters
| Parameter | Type |
|---|---|
path | string |
Returns
string
Example
normalizeParamNames("/docs/:cat-id/:page-num?");// → "/docs/:cat_id/:page_num?"