predicates library
Pure Dart boolean predicate functions for string classification.
Predicates are grouped by concern:
string_predicates— alpha, alphanumeric, base64, email, hex, JSON, etc.date_predicates— date parsing, past/future/today, weekday, leap yearidentifier_predicates— UUID, credit card, ISBN, IBAN, MongoId, FQDNnetwork_predicates— IPv4, IPv6, hostnames, postal codesnumeric_predicates— divisibility, sign, primalitycombinators— composing predicates with and/or/not
Regex constants live under lib/src/ and are not part of the public API.
Classes
- Experimental
- Annotation for predicates not yet stable enough for production use.
- Predicates
- Combinators for building Predicates out of smaller ones.
Extensions
- GmanaNullableStringPredicatesX on String?
- Convenient extension methods on nullable String values.
- GmanaStringPredicatesX on String
- Convenient extension methods on non-null String values.
-
PredicateX
on Predicate<
T> - Fluent composition for Predicates.
Constants
- experimental → const Experimental
- Marks a predicate as experimental — subject to change or removal.
Functions
-
contains(
String str, String seed) → bool -
Returns
trueifstrcontainsseed. -
containsIgnoreCase(
String str, String seed) → bool -
Returns
trueifstrcontainsseed, ignoring case. -
endsWithIgnoreCase(
String str, String suffix) → bool -
Returns
trueifstrends withsuffix, ignoring case. -
equals(
String? str, String comparison) → bool -
Returns
trueifstrequalscomparison. -
hasWhitespace(
String str) → bool -
Returns
trueifstrcontains at least one whitespace character. -
isAfter(
String str, [String? reference]) → bool -
Returns
trueifstrrepresents a date afterreference. -
isAgeAtLeast(
String str, int years) → bool -
Returns
trueif a birth date ofstrmeans an age of at leastyearsas of today (UTC). -
isAlpha(
String str) → bool -
Returns
trueifstrcontains only ASCII alphabetic characters (a–z, A–Z). -
isAlphaNumeric(
String str) → bool -
Returns
trueifstrcontains only ASCII alphanumeric characters (a–z, A–Z, 0–9). -
isAnagram(
String str, String other, {bool ignoreCase = true, bool ignoreNonAlphanumeric = true}) → bool -
Returns
trueifstrandotherare anagrams of one another. -
isAscii(
String str) → bool -
Returns
trueifstrcontains only printable ASCII characters (U+0000–U+007F). -
isBase32(
String str) → bool -
Returns
trueifstris a valid Base32-encoded string (RFC 4648). -
isBase64(
String str) → bool -
Returns
trueifstris a valid Base64-encoded string. -
isBefore(
String str, [String? reference]) → bool -
Returns
trueifstrrepresents a date beforereference. -
isBetween(
String str, String from, String to) → bool -
Returns
trueifstrrepresents a date strictly betweenfromandto. -
isBetweenInclusive(
String str, String from, String to) → bool -
Returns
trueifstrfalls betweenfromandto, bounds included. -
isBic(
String str) → bool -
Returns
trueifstris a valid BIC/SWIFT code (ISO 9362). -
isBinary(
String str) → bool -
Returns
trueifstrcontains only binary digits (0and1). -
isBlank(
String? str) → bool -
Returns
trueifstrisnull, empty, or consists only of whitespace. -
isByteLength(
String str, int min, [int? max]) → bool -
Returns
trueifstrbyte-length is within`min`, `max`. -
isCamelCase(
String str) → bool -
Returns
trueifstris in camelCase format (e.g.fooBar). -
isCapitalized(
String str) → bool -
Returns
trueifstrstarts with an uppercase letter. -
isCidr(
String str, [int? version]) → bool -
Returns
trueifstris a valid CIDR notation. -
isCreditCard(
String str) → bool -
Returns
trueifstris a valid credit card number (Luhn check). -
isDataURI(
String str) → bool -
Returns
trueifstris a valid Data URI scheme (RFC 2397). -
isDate(
String str) → bool -
Returns
trueifstris a parseable date string. -
isDecimal(
String str, {int? places}) → bool -
Returns
trueifstris a decimal number, optionally with exactlyplacesdigits after the point. -
isDivisibleBy(
String str, String n) → bool -
Returns
trueif the numeric value ofstris divisible byn. -
isEAN(
String str, [String? version]) → bool -
Returns
trueifstris a valid EAN-8 or EAN-13 barcode number with valid checksum. -
isEmail(
String str) → bool -
Returns
trueifstrmatches the RFC 5322 email format heuristic. -
isEndOfMonth(
String str) → bool -
Returns
trueifstris the last day of its month. -
isEven(
String str) → bool -
Returns
trueifstrrepresents an even integer. -
isFloat(
String str) → bool -
Returns
trueifstrrepresents a floating-point number. -
isFQDN(
String str, {bool requireTld = true, bool allowUnderscores = false}) → bool -
Returns
trueifstris a valid fully-qualified domain name. -
isFullWidth(
String str) → bool -
Returns
trueifstrcontains full-width Unicode characters. -
isFuture(
String str) → bool -
Returns
trueifstrrepresents a date in the future. -
isHalfWidth(
String str) → bool -
Returns
trueifstrcontains half-width Unicode characters. -
isHash(
String str, String algorithm) → bool -
Returns
trueifstris a valid hash string foralgorithm(e.g.'md5','sha1','sha256','sha512'). -
isHexadecimal(
String str) → bool -
Returns
trueifstris a valid hexadecimal string. -
isHexColor(
String str) → bool -
Returns
trueifstris a valid hex color (e.g.#FFFor#FFFFFF). -
isHostname(
String str) → bool -
Returns
trueifstris a valid hostname label sequence (RFC 1123). -
isHslColor(
String str) → bool -
Returns
trueifstris a CSShsl()orhsla()color with saturation and lightness in 0–100%. -
isIban(
String str) → bool -
Returns
trueifstris a valid IBAN, by ISO 13616 mod-97 checksum. -
isIMEI(
String str) → bool -
Returns
trueifstris a valid 15-digit International Mobile Equipment Identity (IMEI) number. -
isInRange(
String str, num min, num max) → bool -
Returns
trueif the numeric value ofstris within`min`, `max`(inclusive). -
isInt(
String str) → bool -
Returns
trueifstrrepresents an integer. -
isIP(
String str, [int? version]) → bool -
Returns
trueifstris a valid IP address. -
isIpv4(
String str) → bool -
Returns
trueifstris a valid IPv4 address. -
isIpv6(
String str) → bool -
Returns
trueifstris a valid IPv6 address. -
isISBN(
String? str, [String? version]) → bool -
Returns
trueifstris a valid ISBN-10 or ISBN-13. -
isIso8601(
String str) → bool -
Returns
trueifstris a full ISO 8601 date or date-time. -
isJson(
String str) → bool -
Returns
trueifstris valid JSON. -
isJwt(
String str) → bool -
Returns
trueifstrmatches JSON Web Token (JWT) format structure. -
isKebabCase(
String str) → bool -
Returns
trueifstris in kebab-case format (e.g.foo-bar). -
isLatitude(
String str) → bool -
Returns
trueifstris a latitude in the range -90 to 90. -
isLatLong(
String str) → bool -
Returns
trueifstris alatitude,longitudepair (e.g.11.55,104.91). -
isLeapYear(
String str) → bool -
Returns
trueifstrrepresents a date in a leap year. -
isLength(
String str, int min, [int? max]) → bool -
Returns
trueif the display-length ofstris within`min`, `max`, counting surrogate pairs as single characters. -
isLongitude(
String str) → bool -
Returns
trueifstris a longitude in the range -180 to 180. -
isLoopbackIpv4(
String str) → bool -
Returns
trueifstris an IPv4 loopback address (127.0.0.0/8). -
isLowerCase(
String str) → bool -
Returns
trueifstris entirely lowercase (or has no cased characters). -
isLuhnValid(
String str) → bool -
Returns
trueifstrpasses the Luhn checksum algorithm. -
isMacAddress(
String str) → bool -
Returns
trueifstris a valid MAC address (e.g.00:1A:2B:3C:4D:5E,00-1A-2B-3C-4D-5E, or001A.2B3C.4D5E). -
isMagnetURI(
String str) → bool -
Returns
trueifstris a valid BitTorrent Magnet URI. -
isMimeType(
String str) → bool -
Returns
trueifstris a valid MIME type format (e.g.application/json). -
isMongoId(
String str) → bool -
Returns
trueifstris a valid 24-character MongoDB ObjectId (hex). -
isMultiByte(
String str) → bool -
Returns
trueifstrcontains multi-byte (non-ASCII) characters. -
isNanoId(
String str, [int expectedLength = 21]) → bool -
Returns
trueifstrmatches a Nano ID format of lengthexpectedLength(default: 21). -
isNegative(
String str) → bool -
Returns
trueif the numeric value ofstris less than zero. -
isNotBlank(
String? str) → bool -
Returns
trueifstris notnulland contains non-whitespace characters. -
isNullOrEmpty(
String? str) → bool -
Returns
trueifstrisnullor empty. -
isNumeric(
String str) → bool -
Returns
trueifstrcontains only numeric digits (optionally negative). -
isOctal(
String str) → bool -
Returns
trueifstrcontains only octal digits (0–7). -
isOdd(
String str) → bool -
Returns
trueifstrrepresents an odd integer. -
isPalindrome(
String str, {bool ignoreCase = true, bool ignoreNonAlphanumeric = true}) → bool -
Returns
trueifstrreads the same forwards and backwards. -
isPascalCase(
String str) → bool -
Returns
trueifstris in PascalCase format (e.g.FooBar). -
isPast(
String str) → bool -
Returns
trueifstrrepresents a date in the past. -
isPhoneNumber(
String str, {bool requirePlusPrefix = false}) → bool -
Returns
trueifstris a valid phone number. -
isPort(
String str) → bool -
Returns
trueifstris a valid network port number (1–65535). -
isPositive(
String str) → bool -
Returns
trueif the numeric value ofstris greater than zero. -
isPostalCode(
String? text, String locale, {bool orElse()?}) → bool -
Returns
trueiftextis a valid postal code forlocale. -
isPrime(
int n) → bool -
Returns
trueifnis a prime integer. -
isPrimeString(
String str) → bool -
Returns
trueifstrrepresents a prime integer. -
isPrintable(
String str) → bool -
Returns
trueifstrcontains only printable ASCII, tab, newline or carriage return. -
isPrivateIpv4(
String str) → bool -
Returns
trueifstris an IPv4 address in a private range (RFC 1918). -
isPublicIpv4(
String str) → bool -
Returns
trueifstris an IPv4 address that is routable on the public internet. -
isRgbColor(
String str) → bool -
Returns
trueifstris a CSSrgb()orrgba()color with every channel in 0–255. -
isSameDay(
String date1, String date2) → bool -
Returns
trueifdate1anddate2represent the same UTC calendar day. -
isSameMonth(
String date1, String date2) → bool -
Returns
trueifdate1anddate2represent the same UTC year and month. -
isSameWeek(
String date1, String date2) → bool -
Returns
trueifdate1anddate2fall in the same Monday-start week. -
isSameYear(
String date1, String date2) → bool -
Returns
trueifdate1anddate2represent the same UTC year. -
isScreamingSnakeCase(
String str) → bool -
Returns
trueifstris in SCREAMING_SNAKE_CASE (e.g.FOO_BAR). -
isSemVer(
String str) → bool -
Returns
trueifstris a valid Semantic Versioning string (e.g.1.0.0,2.1.0-alpha.1,3.0.0+build.1). -
isSlug(
String str) → bool -
Returns
trueifstris a valid URL slug (lowercase alphanumeric words separated by hyphens). -
isSnakeCase(
String str) → bool -
Returns
trueifstris in snake_case format (e.g.foo_bar). -
isStartOfMonth(
String str) → bool -
Returns
trueifstris the first day of its month. -
isStrongPassword(
String str, {int minLength = 8, int? maxLength, bool requireUppercase = true, bool requireLowercase = true, bool requireDigit = true, bool requireSpecial = true, bool allowWhitespace = false}) → bool -
Returns
trueifstrmeets every enabled password-strength requirement. -
isSurrogatePair(
String str) → bool -
Returns
trueifstrcontains surrogate pairs. -
isTime(
String str) → bool -
Returns
trueifstrmatches 24-hour time format (HH:mmorHH:mm:ss). -
isTitleCase(
String str) → bool -
Returns
trueifstris in Title Case (e.g.Foo Bar Baz). -
isToday(
String str) → bool -
Returns
trueifstrrepresents today's UTC date. -
isTomorrow(
String str) → bool -
Returns
trueifstrrepresents tomorrow's UTC date. -
isULID(
String str) → bool -
Returns
trueifstris a valid 26-character Universally Unique Lexicographically Sortable Identifier (ULID). -
isUpperCase(
String str) → bool -
Returns
trueifstris entirely uppercase (or has no cased characters). -
isUrl(
String str, {Set< String> ? allowedSchemes, bool requireHost = true}) → bool -
Returns
trueifstris a valid URL. -
isUuid(
String? str, [String? version]) → bool -
Returns
trueifstris a valid UUID (any version by default). -
isVariableWidth(
String str) → bool -
Returns
trueifstrcontains both full-width and half-width characters. -
isWeekday(
String str) → bool -
Returns
trueifstrrepresents a Monday–Friday. -
isWeekend(
String str) → bool -
Returns
trueifstrrepresents a Saturday or Sunday. -
isWithinLast(
String str, Duration duration) → bool -
Returns
trueifstris in the past and no older thanduration. -
isWithinNext(
String str, Duration duration) → bool -
Returns
trueifstris in the future and no further off thanduration. -
isYesterday(
String str) → bool -
Returns
trueifstrrepresents yesterday's UTC date. -
isZero(
String str) → bool -
Returns
trueif the numeric value ofstris exactly zero. -
matches(
String str, String pattern) → bool -
Returns
trueifstrmatches the regexpattern. -
startsWithIgnoreCase(
String str, String prefix) → bool -
Returns
trueifstrstarts withprefix, ignoring case. -
tryParseDate(
String str) → DateTime? -
Parses
stras a UTC DateTime, returningnullon failure.