export function getFieldError(field, minmax) {
    if (field == null || field.length == 0) {
        return "Required"
    }
    const [min, max] = minmax;
    if (field.length < min) {
        return "Too short";
    }
    if (field.length > max) {
        return "Too long";
    }
    return null;
}

// Removes consecutive spaces.
export function cleanField(field) {
    return field.replace(/\s{2,}/g, " ").replace(/\n{2,}/g, "\n");
}

export function correctFieldAnimate(field, setField, fieldErrors) {
    if (fieldErrors == null) {
        return;
    }
    setField({...field, animating: true, erroring: true});
}

// Requires lower case extension.
export function isSupportedExtension(ext) {
    const extensions = ["png", "jpeg", "jpg"];
    return extensions.some((e) => e == ext);
}