fix type error in util.ts

This commit is contained in:
monoid 2021-10-11 22:56:49 +09:00
parent a96b740a15
commit e7906dd889

View File

@ -2,8 +2,9 @@
import {Context} from 'koa';
export function ParseQueryNumber(s: string|undefined): number| undefined{
export function ParseQueryNumber(s: string[] | string|undefined): number| undefined{
if(s === undefined) return undefined;
else if(typeof s === "object") return undefined;
else return Number.parseInt(s);
}
export function ParseQueryArray(s: string[]|string|undefined){
@ -11,19 +12,20 @@ export function ParseQueryArray(s: string[]|string|undefined){
const r = s instanceof Array ? s : [s];
return r.map(x=>decodeURIComponent(x));
}
export function ParseQueryArgString(s: string|undefined){
export function ParseQueryArgString(s: string[]|string|undefined){
if(typeof s === "object") return undefined;
return s === undefined ? s : decodeURIComponent(s);
}
export function ParseQueryBoolean(s: string|undefined): [boolean,boolean|undefined]{
export function ParseQueryBoolean(s: string[] |string|undefined): [boolean,boolean|undefined]{
let value:boolean|undefined;
if(s === "true")
value = true;
else if(s === "false")
value = false;
else if(s === undefined)
value = undefined;
else
return [false,undefined]
else return [false,undefined]
return [true,value]
}