Add appendLastPath util function and use it in hypamemory

This commit is contained in:
sub-hub
2024-04-27 22:09:23 +09:00
parent e5a88c4ecb
commit 96622482b3
2 changed files with 32 additions and 5 deletions

View File

@@ -492,4 +492,34 @@ export function trimUntilPunctuation(s:string){
result = result.slice(0, -1)
}
return result
}
/**
* Appends the given last path to the provided URL.
*
* @param {string} url - The base URL to which the last path will be appended.
* @param {string} lastPath - The path to be appended to the URL.
* @returns {string} The modified URL with the last path appended.
*
* @example
* appendLastPath("https://github.com/kwaroran/RisuAI","/commits/main")
* return 'https://github.com/kwaroran/RisuAI/commits/main'
*
* @example
* appendLastPath("https://github.com/kwaroran/RisuAI/","/commits/main")
* return 'https://github.com/kwaroran/RisuAI/commits/main
*
* @example
* appendLastPath("http://127.0.0.1:7997","embeddings")
* return 'http://127.0.0.1:7997/embeddings'
*/
export function appendLastPath(url, lastPath) {
// Remove trailing slash from url if exists
url = url.replace(/\/$/, '');
// Remove leading slash from lastPath if exists
lastPath = lastPath.replace(/^\//, '');
// Concat the url and lastPath
return url + '/' + lastPath;
}