mayr_dart_extensions 1.1.0 copy "mayr_dart_extensions: ^1.1.0" to clipboard
mayr_dart_extensions: ^1.1.0 copied to clipboard

A comprehensive set of handy Dart extensions to make your code cleaner, shorter, and more expressive. Pure Dart package with zero Flutter dependencies.

Changelog #

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.

1.1.0 - 2025-01-17 #

Added #

Function Extensions

  • compose() - Compose functions together
  • memoize() - Cache function results
  • debounce() - Debounce function calls
  • throttle() - Throttle function calls
  • delayed() - Execute function after delay

Future Extensions

  • timeout() - Add timeout to futures with optional fallback
  • retryWhen() - Retry failed futures based on error condition
  • catchError() - Catch and handle errors with default values
  • thenMap() - Map future results
  • delay() - Delay future completion
  • withLoading() - Track loading state with ValueNotifier

Stream Extensions

  • debounceTime() - Debounce stream events
  • throttleTime() - Throttle stream events
  • distinctUntilChanged() - Filter consecutive duplicate values
  • bufferTime() - Buffer stream events over time window
  • retryWhen() - Retry stream on error
  • firstWhereOrNull() - Find first matching element or null

Uri Extensions

  • addQueryParam() - Add query parameter to URI
  • removeQueryParam() - Remove query parameter from URI
  • hasQueryParam() - Check if query parameter exists
  • getQueryParam() - Get query parameter value
  • replaceQueryParams() - Replace all query parameters
  • isSecure - Check if URI uses HTTPS
  • domain - Extract domain without subdomain
  • subdomain - Extract subdomain from URI

Enum Extensions

  • displayName - Convert enum to human-readable string
  • toJson() - Convert enum to JSON string
  • fromString() - Find enum value by string name

Range Extensions (Integer)

  • to() - Create inclusive range with optional step
  • until() - Create exclusive range with optional step
  • inRange() - Check if integer is in range

Range Extensions (Double)

  • to() - Create inclusive range with optional step
  • inRange() - Check if double is in range

String Template Extensions

  • format() - Format string with named placeholders
  • formatList() - Format string with positional placeholders
  • interpolate() - Interpolate string with custom resolver
  • repeat() - Repeat string with optional separator

Base64 Extensions (String)

  • toBase64() - Encode string to Base64
  • fromBase64() - Decode Base64 string
  • isBase64 - Check if string is valid Base64
  • toBase64Bytes() - Convert Base64 string to bytes

Base64 Extensions (List

  • toBase64String() - Encode byte list to Base64 string

Validation Extensions (String)

  • isStrongPassword - Validate strong password (min 8 chars, upper, lower, number, special)
  • isWeakPassword - Check if password is weak
  • passwordStrength - Get password strength score (0.0-1.0)
  • isCreditCard - Validate credit card number with Luhn algorithm
  • isPostalCode - Validate postal codes (US, UK, Canada formats)
  • isPhoneNumber - Validate phone numbers
  • isMACAddress - Validate MAC addresses

Changed #

  • Updated README.md to use consistent <details> sections for all extension types
  • Improved documentation structure with collapsible sections for Duration and Bool extensions
  • Enhanced features table to include all new extension types

1.0.0 - 2025-01-16 #

Initial Release #

This is the initial release of mayr_dart_extensions as a pure Dart package, migrated from the previous Flutter-based package.

Features

Bool Extensions

  • choose(trueValue, falseValue) - Select value based on boolean
  • toInt() - Convert to integer (1 for true, 0 for false)
  • toYesNo() - Convert to string representation
  • not - Returns negation of the boolean

DateTime Extensions

  • Checkers: isAfternoon, isMorning, isEvening, isNight, isToday, isTomorrow, isYesterday, isSameDay(), isInPast, isInFuture
  • Utilities: startOfDay()
  • Manipulators: addDays(), addMonths(), addYears(), addHours(), addMinutes(), addSeconds(), subDays(), subMonths(), subYears(), subHours(), subMinutes(), subSeconds()
  • Age: toAge(), isAgeOlder(), isAgeYounger(), isAgeEqualTo(), isAgeBetween()
  • Formatting: format(), toDayOrdinal(), toTimeAgoString(), toTimeString(), toShortDate()

Duration Extensions

  • delay() - Delays execution for the duration
  • toReadableString() - Human-readable format (e.g., '2h 30m')
  • isLongerThan() - Compare durations
  • isShorterThan() - Compare durations

Dynamic Extensions

  • nullOnDebug<T>() - Returns null in debug mode
  • onlyOnDebug<T>() - Returns value only in debug mode
  • maybe<T>() - Randomly returns null based on probability
  • orDefault() - Returns fallback value if null

Number Extensions

  • Comparisons: isEqual(), isGreaterThan(), isLessThan(), isBetween(), isPositive, isNegativeNumber, isZero
  • Clamping: clampMin(), clampMax()
  • Integer: isEvenNumber, isOddNumber, times(), timesIndexed()
  • Random: randomLess(), randomMore()
  • Double: toDecimalPlaces()
  • Formatting: formatAsCurrency(), formatAsDecimal(), formatAsNumber()
  • Duration: days, hours, minutes, seconds, milliseconds, microseconds

String Extensions

  • Utilities: matchesRegExp(), toBool, toDateTime(), toRegExp(), toUri(), limit(), mask(), reverse(), isBlank, isNotBlank, removeWhitespace(), countOccurrences(), truncate(), wrap(), removePrefix(), removeSuffix()
  • Pretty Printing: prettyJson(), prettyXml(), prettyYaml()
  • Casing: camelCase, capitalised, kebabCase, pascalCase, snakeCase, titleCase
  • Case Checkers: isCamelCase, isPascalCase, isSnakeCase, isKebabCase, isTitleCase, isCapitalised, isUpperCase, isLowerCase
  • Pattern Checkers: isEmail, isURL, isUlid, isUuid, isSlug, isHexColor, isIPAddress, isNum, isAlphabetOnly, isNumericOnly

List/Iterable Extensions

  • Query: firstOrNull(), lastOrNull(), singleWhereOrNull(), containsWhere(), indexWhereOrNull()
  • Safe Access: getOrNull(), getOrDefault()
  • Transformations: chunked(), mapIndexed(), whereNotNull(), distinctBy(), flatten(), sortedBy(), sortedByDesc(), flip()
  • Aggregations: sumBy(), averageBy(), min(), max(), countWhere()
  • Mutations: insertIf(), replaceWhere(), removeWhereNot(), updateWhere(), addIf(), addAllIf(), append(), appendAll(), appendIf(), appendAllIf(), pop(), filter(), unique()
  • Utility: isNullOrEmpty(), joinToString(), forEachIndexed()

Map Extensions

  • Safe Access: getOrNull(), getOrDefault()
  • Transformations: mapKeys(), mapValues(), filterKeys(), filterValues(), invert()
  • Merge: merge(), mergeIfAbsent(), combine()
  • Utility: keysWhere(), valuesWhere(), toQueryString()

Set Extensions

  • toggle() - Add if missing, remove if present
  • intersects() - Check for intersection
  • isSubsetOf() - Check if subset
  • isSupersetOf() - Check if superset
  • unionAll() - Union of multiple sets
  • without() - Remove element

Humanize Extensions

  • Duration: humanize() - Convert to "2 hours, 3 minutes"
  • DateTime: humanize() - Relative time ("just now", "3 hours ago", etc.)
  • Numbers: humanizeNumber(), humanizeOrdinal(), humanizeCount(), humanizePercentage(), humanizeFileSize()

Object Extensions

  • let() - Transform object inline
  • also() - Execute side effects while maintaining object for chaining

Tools

  • MayrDateTimeFormats - Common date/time format patterns

Changed #

  • Package renamed from mayr_extensions to mayr_dart_extensions
  • Migrated to pure Dart (removed all Flutter dependencies)
  • Updated ownership to MayR Labs
  • Removed Flutter-specific extensions (will be available in separate mayr_flutter_extensions package)

Removed #

  • BuildContext extensions (moved to mayr_flutter_extensions)
  • Widget extensions (moved to mayr_flutter_extensions)
  • Image widget extensions (moved to mayr_flutter_extensions)
  • Text widget extensions (moved to mayr_flutter_extensions)
  • TextStyle extensions (moved to mayr_flutter_extensions)
  • StatelessWidget extensions (moved to mayr_flutter_extensions)
  • InkWellManager utility (moved to mayr_flutter_extensions)
  • String.copyToClipboard() method (requires Flutter, moved to mayr_flutter_extensions)

Note: This is a new package publication. For Flutter-specific extensions, use the companion package mayr_flutter_extensions.

1
likes
160
points
15
downloads

Documentation

Documentation
API reference

Publisher

verified publishermayrlabs.com

Weekly Downloads

A comprehensive set of handy Dart extensions to make your code cleaner, shorter, and more expressive. Pure Dart package with zero Flutter dependencies.

Repository (GitHub)
View/report issues
Contributing

Topics

#extensions #utilities #dart #productivity #toolkit

License

MIT (license)

Dependencies

get_time_ago, intl, xml, yaml

More

Packages that depend on mayr_dart_extensions