toInt function
- IValidator child, {
- String? message,
Coerces a value to an integer.
Handles existing integers, doubles (by truncating), and strings that can be
parsed as an integer.
Passes the resulting integer to the child validator.
Implementation
IValidator toInt(IValidator child, {String? message}) {
final base = ($isInt | $isNumber | $isIntString) &
core.transform((v) {
return switch (v) {
final int n => n,
final double n => n.toInt(),
final String s => int.tryParse(s.trim()),
_ => null,
};
}, child);
return handleReturnPreserveValue(base, message);
}