|
|
@ -12,11 +12,24 @@ type MapToReturnFunction = { |
|
|
|
|
|
|
|
|
|
|
|
const MAP_TO_RETURN_FUNCTION: MapToReturnFunction = { |
|
|
|
const MAP_TO_RETURN_FUNCTION: MapToReturnFunction = { |
|
|
|
boolean: (qs) => qs !== undefined, |
|
|
|
boolean: (qs) => qs !== undefined, |
|
|
|
string: (qs) => String(qs), |
|
|
|
string: (qs) => (qs ? String(qs) : ''), |
|
|
|
'string[]': (qs) => |
|
|
|
'string[]': (qs) => { |
|
|
|
qs instanceof Array |
|
|
|
let result: string[] = []; |
|
|
|
? qs.map((element) => String(element)) |
|
|
|
|
|
|
|
: String(qs).split(/[,;]/), |
|
|
|
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>( |
|
|
|
export const sanitizeQS = <ReturnTypeName extends keyof MapToReturnType>( |
|
|
|