2023-09-12 13:40:38 +02:00
|
|
|
/** Splits a list of strings by commas within the strings */
|
2023-04-05 18:59:56 +02:00
|
|
|
const splitComma = (strings: string[]): string[] => {
|
2023-08-09 16:07:33 +02:00
|
|
|
if (!strings) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2023-04-05 18:59:56 +02:00
|
|
|
for (let i = 0; i < strings.length; i++) {
|
|
|
|
|
const comma = strings[i].indexOf(',');
|
|
|
|
|
if (comma !== -1) {
|
|
|
|
|
const splits = strings[i].split(/,/);
|
|
|
|
|
strings.splice(i, 1, ...splits);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return strings;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns an array of the comma split parameters from the given URL search params
|
|
|
|
|
* @param lowerCaseKey - lower case search parameter value
|
|
|
|
|
* @param params - URLSearchParams
|
|
|
|
|
* @returns Array of comma split items matching, or null
|
|
|
|
|
*/
|
|
|
|
|
const getSplitParam = (
|
|
|
|
|
lowerCaseKey: string,
|
|
|
|
|
params = new URLSearchParams(window.location.search)
|
|
|
|
|
): string[] => {
|
2023-09-01 22:19:39 +02:00
|
|
|
const sourceKey = [...params.keys()].find(it => it.toLowerCase() === lowerCaseKey);
|
2023-08-09 16:07:33 +02:00
|
|
|
if (!sourceKey) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-04-05 22:37:37 +02:00
|
|
|
return splitComma(params.getAll(sourceKey));
|
2023-04-05 18:59:56 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export { splitComma, getSplitParam };
|