Skip to content

Commit

Permalink
fix(aPath): startsWith("/")
Browse files Browse the repository at this point in the history
Update aPath.mjs
  • Loading branch information
VirgilClyne committed Dec 19, 2024
1 parent 2c2c105 commit 22415fa
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/function/aPath.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
// Get Absolute Path
export default function aPath(aURL = "", URL = "") {
return /^https?:\/\//i.test(URL) ? URL : aURL.match(/^(https?:\/\/(?:[^?]+)\/)/i)?.[0] + URL;
export default function aPath(URL = "", URI = "") {
let url = "";
switch (true) {
case URI.startsWith("https://") || URI.startsWith("http://"):
url = URI;
break;
case URI.startsWith("/"):
url = URL.match(/^(https?:\/\/(?:[^/]+))/i)?.[0] + URI;
break;
default:
url = URL.match(/^(https?:\/\/(?:[^?]+)\/)/i)?.[0] + URI;
break;
}
return url;
//return /^https?:\/\//i.test(URI) ? URI : URL.match(/^(https?:\/\/(?:[^?]+)\/)/i)?.[0] + URI;
}

0 comments on commit 22415fa

Please sign in to comment.