validate.js 395 Bytes
export const required = function required(value) {
    if (Array.isArray(value)) {
        return value.length > 0 ? undefined : '此项是必填项';
    } else if (typeof (value) == 'string' && value && !value.trim()) {
        return value.trim() ? undefined : '此项是必填项';
    } else {
        return typeof (value) == 'number' || value ? undefined : '此项是必填项';
    }
};