(path: string, urlGenerator: string | undefined)
| 357 | * @returns Returns the final path to open in browser |
| 358 | */ |
| 359 | export const generatePath = (path: string, urlGenerator: string | undefined) => { |
| 360 | // Generate the path based on the urlGenerator function if one is provided |
| 361 | const generatedPath = urlGenerator ? eval(urlGenerator)(path) : undefined; |
| 362 | // If the path is generated, return it |
| 363 | if (generatedPath) { |
| 364 | return sanitizePath(generatedPath); |
| 365 | } |
| 366 | // Otherwise, generate the path based on the file path, gets the path after the routes folder and splits everything by the dot |
| 367 | const pathChunks = path.split("routes/")[1].split("."); |
| 368 | // Removes the extension from the path |
| 369 | const pathChunksWithoutExtension = pathChunks.slice(0, pathChunks.length - 1).join("/"); |
| 370 | // Converts the path to a URL by splitting the path by the slash, removing unneeded segments and joining everything back together |
| 371 | const sanitizedPathChunks = pathChunksWithoutExtension |
| 372 | .split("/") |
| 373 | .map((chunk) => convertRemixPathToUrl(chunk)) |
| 374 | .filter((chunk) => chunk !== "") |
| 375 | .join("/"); |
| 376 | |
| 377 | return sanitizePath(sanitizedPathChunks); |
| 378 | }; |
no test coverage detected