From 915fdf2d543b4465b0afeccb6fcb42e5c3667229 Mon Sep 17 00:00:00 2001 From: Seth Trowbridge Date: Mon, 24 Jul 2023 17:41:13 -0400 Subject: [PATCH] add url remapper file --- url-remapper.tsx | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 url-remapper.tsx diff --git a/url-remapper.tsx b/url-remapper.tsx new file mode 100644 index 0000000..f387cc1 --- /dev/null +++ b/url-remapper.tsx @@ -0,0 +1,41 @@ +function remapUrl({ input, mapFrom, mapTo }: { input: string, mapFrom: string, mapTo: string}): string | undefined +{ + const partsInput = input.split('/'); + const partsMapFrom = mapFrom.split('/'); + const partsMapTo = mapTo.split('/'); + + if(partsInput.length == partsMapFrom.length) + { + for(let i=0; i -1) + { + const partMapTo = partsMapTo[indexMapTo]; + if(partMapTo === partMapFrom) + { + partsMapTo[indexMapTo] = partInput; + continue; + } + } + return; + } + } + return partsMapTo.join("/"); + } +} + + + const remap: string | undefined = remapUrl({ + input: "/base/theproj/app01", + mapFrom: "/base/:project/:id", + mapTo: "https://vcs.com/remote/raw/:project/show/:id" + }); + + console.log(remap); // Output: "https://vcs.com/remote/raw/theproj/show/app01" + + \ No newline at end of file