2022-01-02 22:02:47 +00:00
|
|
|
export class VerificationError extends Error {
|
|
|
|
constructor(
|
|
|
|
public readonly type?: string,
|
|
|
|
public readonly field?: string,
|
|
|
|
public readonly value?: any
|
|
|
|
) {
|
2022-01-03 17:11:53 +00:00
|
|
|
super("Parameter verification failed! " +(type ? "Expected " + type + "! " :"") + (field ? "At: " + field + "! " : ""));
|
2022-01-02 22:02:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-03 17:11:53 +00:00
|
|
|
export function apply_number(data: any) {
|
|
|
|
data = Number(data);
|
|
|
|
if(Number.isNaN(data)) throw new VerificationError("number", undefined, data);
|
2022-01-02 22:02:47 +00:00
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
2022-01-03 17:11:53 +00:00
|
|
|
export function apply_string(data: any) {
|
|
|
|
return String(data);
|
2022-01-02 22:02:47 +00:00
|
|
|
}
|
|
|
|
|
2022-01-03 17:11:53 +00:00
|
|
|
export function apply_boolean(data: any) {
|
|
|
|
return Boolean(data);
|
2022-01-02 22:02:47 +00:00
|
|
|
}
|
|
|
|
|
2022-01-03 17:11:53 +00:00
|
|
|
export function apply_void(data: any) {}
|