MCPcopy Create free account
hub / github.com/code-forge-io/Remix-Forge / generatePath

Function generatePath

src/utils/file.ts:359–378  ·  view source on GitHub ↗
(path: string, urlGenerator: string | undefined)

Source from the content-addressed store, hash-verified

357 * @returns Returns the final path to open in browser
358 */
359export 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};

Callers 1

getAllRoutesFunction · 0.90

Calls 2

sanitizePathFunction · 0.90
convertRemixPathToUrlFunction · 0.85

Tested by

no test coverage detected