Comment on page
String validations
required
: can't be undefined (default:false
)empty
: accepts empty string (default:false
)equal
: * equal to passed valueminLength
: can't be shorter than passed valuemaxLength
: can't be longer than passed valueexactLength
: length must be exactly the passed valueregex
: matches the passed regexalphanumeric
: composed only by alphabetical and numeric characterslowerCase
: all characters must be lower casedupperCase
: all characters must be upper casedemail
: is a valid email (default:false
)nullable
: accepts null (default:false
)guid
: is a valid guid. You can pass a boolean or the options object accepted by Joi (default:false
)
const User = attributes({
id: {
type: String,
guid: true,
},
token: {
type: String,
guid: {
version: ['uuidv4'],
},
},
initials: {
type: String,
upperCase: true,
maxLength: 4,
},
gender: {
type: String,
nullable: true,
},
password: String,
passwordConfirmation: {
type: String,
equal: { attr: 'password' },
},
greet: {
type: String,
required: true,
equal: ['Mr', 'Ms', 'Mrs', 'Miss', { attr: 'greetDesc' }],
},
greetDesc: String,
})(
class User {
getFullGreet() {
return `${this.greet} ${this.initials}`;
}
}
);
Last modified 3yr ago