import DataType from "../DataType";

export default class NumberType extends DataType<number>{
    public sanitize(value: any): number|null|undefined {
        if (value === "") return null;
        if (value == null) return value;
        if (typeof value === "number") return value;
        if (typeof value === "boolean") return value ? 1 : 0;
        if (typeof value === "string" && !isNaN(parseFloat(value))) return parseFloat(value);
        console.warn("Value is not a number");
        console.warn(value);
        throw new Error("Value is not a number");
    }
}