Remove number and add int and float insted

This commit is contained in:
Fabian Stamm
2022-04-13 19:01:12 +00:00
parent 339d3006d6
commit b980af4b17
10 changed files with 64 additions and 41 deletions

View File

@ -4,13 +4,24 @@ export class VerificationError extends Error {
public readonly field?: string,
public readonly value?: any
) {
super("Parameter verification failed! " +(type ? "Expected " + type + "! " :"") + (field ? "At: " + field + "! " : ""));
super(
"Parameter verification failed! " +
(type ? "Expected " + type + "! " : "") +
(field ? "At: " + field + "! " : "")
);
}
}
export function apply_number(data: any) {
export function apply_int(data: any) {
data = Math.floor(Number(data));
if (Number.isNaN(data)) throw new VerificationError("int", undefined, data);
return data;
}
export function apply_float(data: any) {
data = Number(data);
if(Number.isNaN(data)) throw new VerificationError("number", undefined, data);
if (Number.isNaN(data))
throw new VerificationError("float", undefined, data);
return data;
}