rules library

The builder functions of all built-in rules, to compose rules of your own.

Functions

anyObject(List<Object?> args, RuleContext context) → LivrRule
any_object: the value must be an object (a Map). Its content is not validated.
decimal(List<Object?> args, RuleContext context) → LivrRule
decimal: the value must be a number, an integer or a decimal. Strings are accepted in the form -12 or -12.34, and the output is always a double.
defaultValue(List<Object?> args, RuleContext context) → LivrRule
default: sets the value when it is empty: missing, null or an empty string. Other values, 0 included, are kept.
email(List<Object?> args, RuleContext context) → LivrRule
email: the value must be an email address.
eq(List<Object?> args, RuleContext context) → LivrRule
eq: the value must be equal to the argument. Values are compared as strings, and the output is the argument.
equalToField(List<Object?> args, RuleContext context) → LivrRule
equal_to_field: the value must be equal to the value of another field. Values are compared as strings: '10' and 10 are equal. A missing field is not equal to any value.
integer(List<Object?> args, RuleContext context) → LivrRule
integer: the value must be an integer. Strings with an integer ('10', '1e3') are accepted, and the output is always an int.
isoDate(List<Object?> args, RuleContext context) → LivrRule
iso_date: the value must be an ISO 8601 date without time, like 2014-08-14.
leaveOnly(List<Object?> args, RuleContext context) → LivrRule
leave_only: Removes all characters except the given ones. Numbers and booleans are converted to strings, objects and lists are left as they are.
lengthBetween(List<Object?> args, RuleContext context) → LivrRule
length_between: the string must have from min to max characters (Unicode code points), inclusive. The output is the value as a string.
lengthEqual(List<Object?> args, RuleContext context) → LivrRule
length_equal: the string must have exactly the given number of characters (Unicode code points). The output is the value as a string.
like(List<Object?> args, RuleContext context) → LivrRule
like: the value must match the regular expression. Flags are the second argument: {like: ['^[a-z]+$', 'i']}; only i (ignore case) is supported. The output is the value as a string.
listOf(List<Object?> args, RuleContext context) → LivrRule
list_of: validates every element of a list with the same rules. Errors are a list with the error of every element, null for valid elements. Both the new syntax {list_of: ['required', 'email']} and the old one {list_of: [['required', 'email']]} work.
listOfDifferentObjects(List<Object?> args, RuleContext context) → LivrRule
list_of_different_objects: validates every element of a list with one of several object schemas. The value of the selector field of an element chooses the schema, like in variable_object.
listOfObjects(List<Object?> args, RuleContext context) → LivrRule
list_of_objects: validates every element of a list with the same object schema. Errors are a list with the errors of every element, null for valid elements.
maxLength(List<Object?> args, RuleContext context) → LivrRule
max_length: the string must have at most the given number of characters (Unicode code points). The output is the value as a string.
maxNumber(List<Object?> args, RuleContext context) → LivrRule
max_number: the number must be at most the argument. Strings with a number are accepted, and the output is the number.
minLength(List<Object?> args, RuleContext context) → LivrRule
min_length: the string must have at least the given number of characters (Unicode code points). The output is the value as a string.
minNumber(List<Object?> args, RuleContext context) → LivrRule
min_number: the number must be at least the argument. Strings with a number are accepted, and the output is the number.
nestedObject(List<Object?> args, RuleContext context) → LivrRule
nested_object: validates a nested object with its own schema. Errors have the shape of the object.
notEmpty(List<Object?> args, RuleContext context) → LivrRule
not_empty: the value must not be an empty string, if it is present.
notEmptyList(List<Object?> args, RuleContext context) → LivrRule
not_empty_list: the value must be a list with at least one element.
numberBetween(List<Object?> args, RuleContext context) → LivrRule
number_between: the number must be from min to max, inclusive. Strings with a number are accepted, and the output is the number.
oneOf(List<Object?> args, RuleContext context) → LivrRule
one_of: the value must be one of the arguments. Values are compared as strings, and the output is the allowed value. Both the new syntax {one_of: ['a', 'b']} and the old one {one_of: [['a', 'b']]} work.
or(List<Object?> args, RuleContext context) → LivrRule
or: applies the sets of rules one after another until one of them succeeds: {or: ['email', 'positive_integer']}. When all of them fail, the error of the last one is returned.
positiveDecimal(List<Object?> args, RuleContext context) → LivrRule
positive_decimal: the value must be a number greater than zero. Strings are accepted in the form 12 or 12.34, and the output is always a double.
positiveInteger(List<Object?> args, RuleContext context) → LivrRule
positive_integer: the value must be an integer greater than zero. Strings with an integer are accepted, and the output is always an int.
remove(List<Object?> args, RuleContext context) → LivrRule
remove: Removes the given characters from the string. Numbers and booleans are converted to strings, objects and lists are left as they are.
required(List<Object?> args, RuleContext context) → LivrRule
required: the value must be present, not null and not an empty string. 0 and false are valid values.
string(List<Object?> args, RuleContext context) → LivrRule
string: the value must be a primitive value, it is converted to a string.
toLc(List<Object?> args, RuleContext context) → LivrRule
to_lc: Converts the string to lower case. Numbers and booleans are converted to strings, objects and lists are left as they are.
toUc(List<Object?> args, RuleContext context) → LivrRule
to_uc: Converts the string to upper case. Numbers and booleans are converted to strings, objects and lists are left as they are.
trim(List<Object?> args, RuleContext context) → LivrRule
trim: Removes leading and trailing whitespace. Numbers and booleans are converted to strings, objects and lists are left as they are.
url(List<Object?> args, RuleContext context) → LivrRule
url: the value must be an http or https URL, with the protocol.
variableObject(List<Object?> args, RuleContext context) → LivrRule
variable_object: validates an object with one of several schemas. The value of the selector field chooses the schema: {variable_object: ['type', {'material': {...}, 'service': {...}}]}.