( pathParamsAllowedCharacters: ReadonlyArray<string>, )
| 203 | * This should be called once at router initialization. |
| 204 | */ |
| 205 | export function compileDecodeCharMap( |
| 206 | pathParamsAllowedCharacters: ReadonlyArray<string>, |
| 207 | ) { |
| 208 | const charMap = new Map( |
| 209 | pathParamsAllowedCharacters.map((char) => [encodeURIComponent(char), char]), |
| 210 | ) |
| 211 | // Escape special regex characters and join with | |
| 212 | const pattern = Array.from(charMap.keys()) |
| 213 | .map((key) => key.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')) |
| 214 | .join('|') |
| 215 | const regex = new RegExp(pattern, 'g') |
| 216 | return (encoded: string) => |
| 217 | encoded.replace(regex, (match) => charMap.get(match) ?? match) |
| 218 | } |
| 219 | |
| 220 | interface InterpolatePathOptions { |
| 221 | path?: string |
no test coverage detected