ip function

LivrRule ip(
  1. List<Object?> args,
  2. RuleContext context
)

ip: the value must be an IPv4 or an IPv6 address; {ip: 'v4'} accepts only IPv4, {ip: 'v6'} only IPv6. IPv4 numbers have no leading zeros (010.0.0.1 fails: some systems read it as octal); IPv6 is in the text forms of RFC 4291, without a zone or brackets. The output is the value as a string.

Implementation

LivrRule ip(List<Object?> args, RuleContext context) {
  final version = _version(args, 'ip');
  return (value, allValues) => _check(value, (str) {
    final length = str.length;
    return (version != 6 && _isIPv4(str, 0, length)) ||
        (version != 4 && _isIPv6(str, 0, length));
  });
}