objectProps
Parameters
import {objectProps} from 'strickland';
const personValidator = objectProps({
firstName: every([required(), length(2, 20)]),
lastName: every([required(), length(2, 20)]),
birthYear: range(1900, 2018)
}, {
message: 'The person must be valid'
});Validation Context
import {objectProps} from 'strickland';
const personValidator = objectProps({
firstName: every([
required(),
length((context) => ({
minLength: context.minLength,
maxLength: context.maxLength
}))
]),
lastName: every([
required(),
length((context) => ({
minLength: context.minLength,
maxLength: context.maxLength
}))
]),
birthYear: range((context) => ({
min: context.min,
max: context.max
}))
}, {
message: 'The person must be valid'
});
// Create a person
const person = {
firstName: 'Stanford',
lastName: 'Strickland',
birthYear: 1925
};
const result = validate(personValidator, person, {
objectProps: {
firstName: {
minLength: 5,
maxLength: 20
},
lastName: {
minLength: 8,
maxLength: 23
},
birthYear: {
min: 1900,
max: 2018
}
}
});Result Properties
Last updated