util library

Helpers for custom rules: the checks and conversions the built-in rules use.

Classes

SingleFieldMap
An unmodifiable map with one entry: the data of a value validated on its own (list items, or and aliases), cheaper than a map literal.

Functions

camelize(String name) → String
The camelCase form of an underscore rule name: min_length becomes minLength.
codePointLength(String str) → int
The number of characters (Unicode code points) of the string. Unlike String.length, a character outside of the Basic Multilingual Plane, like most emoji, counts once.
deepCopy(Object? value) → Object?
A deep copy of maps and lists, other values as they are.
isNoValue(Object? value) → bool
Whether the value is empty for LIVR: missing (null) or an empty string. All rules except required, not_empty and not_empty_list skip empty values.
isPrimitive(Object? value) → bool
Whether the value is a primitive value: a string, a boolean or a finite number.
livrToString(Object? value) → String
Converts a primitive value to a string like JavaScript does, so values are compared the same way in all implementations: 10.0 becomes '10' (not '10.0'), -0.0 becomes '0'.
numberArg(List<Object?> args, int index, String ruleName) → num
A number argument of a rule at index: a number or a string with a number. Throws LivrSchemaException otherwise.
parseNumber(String str) → num?
Parses a decimal number: an optional sign, digits with an optional fraction (12, -1.5, .5, 5.) and an optional exponent (1e3). Leading and trailing ASCII whitespace is allowed. Returns an int for integers that fit, a double otherwise, and null if the string is not a number. Hexadecimal numbers, Infinity and NaN are not numbers.
ruleArg(List<Object?> args, int index, String ruleName) → Object?
The argument of a rule at index, for rule builders. Throws LivrSchemaException when the schema does not have it.
stringArg(List<Object?> args, int index, String ruleName) → String
A string argument of a rule at index. Numbers and booleans are converted with livrToString. Throws LivrSchemaException for other values.
trimDeep(Object? value) → Object?
Trims all strings in the value, in nested maps and lists too. Returns the value itself when there is nothing to trim, and a trimmed copy otherwise: the value is never changed.