export function getPropName(valueProp, type) {
    return typeof valueProp === 'function' ? valueProp(type) : valueProp;
}
export function getValueFromEvent() {
    var args = [];
    for (var _i = 0; _i < arguments.length; _i++) {
        args[_i] = arguments[_i];
    }
    var e = args[0];
    return e && e.target ? (e.target.type === 'checkbox' ? e.target.checked : e.target.value) : e;
}
export function validate(value, rule) {
    var message = rule.message, required = rule.required, max = rule.max, min = rule.min, enumVal = rule.enum, len = rule.len, pattern = rule.pattern, transform = rule.transform, type = rule.type, validator = rule.validator, whitespace = rule.whitespace;
    var val = transform ? transform(value) : value;
    if (required && !val) {
        return message || 'The value is required';
    }
    if (type && typeof val !== type) {
        return message || "The value is not a " + type;
    }
    if (max || len) {
        var segment = (max || len);
        if (typeof val === 'number' && val > segment) {
            return message || 'The value is greater than the max';
        }
        else if ((typeof val === 'string' || Array.isArray(val)) && val.length > segment) {
            return message || 'The length of value is greater than the max';
        }
    }
    if (min) {
        if (typeof val === 'number' && val < min) {
            return message || 'The value is less than the max';
        }
        else if ((typeof val === 'string' || Array.isArray(val)) && val.length < min) {
            return message || 'The length of value is less than the max';
        }
    }
    if (enumVal && !enumVal.includes(val)) {
        return message || 'The value is not in the enum';
    }
    if (pattern && !pattern.test(val)) {
        return message || 'The value does not find a match';
    }
    if (validator) {
        var res = validator(val);
        if (res instanceof Promise ? !res.then(val) : !res) {
            return message || 'The value is validated unsuccessfully';
        }
    }
    if (whitespace && typeof val === 'string' && val.trim().length <= 0) {
        return message || 'The input contains whitespace';
    }
    return undefined;
}
//# sourceMappingURL=form-helper.js.map