fix(striker-ui-api): handle empty query params

main
Tsu-ba-me 3 years ago
parent f88ac0387d
commit d3cd671288
  1. 23
      striker-ui-api/src/lib/sanitizeQS.ts

@ -12,11 +12,24 @@ type MapToReturnFunction = {
const MAP_TO_RETURN_FUNCTION: MapToReturnFunction = {
boolean: (qs) => qs !== undefined,
string: (qs) => String(qs),
'string[]': (qs) =>
qs instanceof Array
? qs.map((element) => String(element))
: String(qs).split(/[,;]/),
string: (qs) => (qs ? String(qs) : ''),
'string[]': (qs) => {
let result: string[] = [];
if (qs instanceof Array) {
result = qs.reduce<string[]>((reduceContainer, element) => {
if (element) {
reduceContainer.push(String(element));
}
return reduceContainer;
}, []);
} else if (qs) {
result = String(qs).split(/[,;]/);
}
return result;
},
};
export const sanitizeQS = <ReturnTypeName extends keyof MapToReturnType>(

Loading…
Cancel
Save