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,
orand aliases), cheaper than a map literal.
Functions
-
camelize(
String name) → String -
The camelCase form of an underscore rule name:
min_lengthbecomesminLength. -
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 exceptrequired,not_emptyandnot_empty_listskip 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.0becomes'10'(not'10.0'),-0.0becomes'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 anintfor integers that fit, adoubleotherwise, andnullif the string is not a number. Hexadecimal numbers,InfinityandNaNare 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.