This commit is contained in:
Zeeshaun
2026-03-17 11:09:46 -05:00
parent bd1a9744ad
commit 6e7edcfe1b
332 changed files with 64174 additions and 0 deletions
@@ -0,0 +1,48 @@
interface IUrlParam {
key: string;
value: string | number | boolean;
}
export default class UrlFormatting {
/**
* Replace the variable parameters of a url with their values
*
* I.E.
*
* ReplaceURLParams(
* "http://www.test.com/foo/{fooId}/bar/{barId}",
* { key: 'fooId', value: 1 },
* { key: barId, value: 'second_param' }
* );
*
* Would result in a return value of:
* "http://www.test.com/foo/1/bar/second_param"
*
* NOTE: This method is case sensitive
*
* @param url The base URL
* @param params Each param with it's token and value
* @returns A paramterized version of the URL
*/
public static ReplaceURLParams(url: string, ...params: IUrlParam[]) {
for (const param of params) {
url = url.replace(`{${param.key}}`, param.value + '');
}
return url;
}
/**
* Concatenate the array value parameter items into a query string format to be added onto the end of a URL
*
* @param arrayValues The array of values for the query
* @param queryPrefix The string to be prepended to each array value
* @returns A query formatted URL substring
*/
public static FormatArrayValuesIntoQuery(arrayValues: string[], queryPrefix: string) {
let returnString = "";
for (const arrayValue of arrayValues) {
returnString += (queryPrefix + arrayValue);
}
return returnString;
}
}