extension_utils 2.0.0
extension_utils: ^2.0.0 copied to clipboard
A comprehensive utility library with real-world extensions for strings, lists, maps, numbers, datetimes, colors, iterables, durations, enums, booleans, URIs, futures, objects, and regex patterns.
Changelog #
2.0.0 #
This is a major release with breaking changes. The package has been modernized for Dart 3.x and Flutter 3.19+.
Breaking Changes #
- Minimum SDK is now
Dart >=3.3.0 <4.0.0andFlutter >=3.19.0 StringUtilsextension now targetsStringinstead ofString?(anti-pattern removed)- Removed redundant methods already present in the Dart/Flutter standard library:
String:startsWith,endsWith,charCount,isNullOrEmpty,isNullOrWhitespacenum:isEven,isOdd,isNegative,clampMap:isEmpty(conflicted with built-in)
ListUtils.removeLast(item)renamed toremoveLastOccurrence(item)to avoid conflict with the built-inList.removeLast()
New Extensions #
bool_utils.dart (new)
toggled– returns the logical inversetoYesNo,toOnOff,toEnabledDisabled– human-readable string representationsifTrue,ifFalse– conditional value helperswhen– pattern-match style dispatch on a bool
uri_utils.dart (new)
appendPath– appends a path segmentwithQueryParam,withQueryParams– adds/replaces query parametersremoveQueryParam– removes a specific query parameterisSecure– checks forhttpsschemehasQueryParams– checks for presence of query parametersisAbsolute– checks if the URI is absolute
future_utils.dart (new)
retryFuture<T>()– top-level function that retries a future factory up to N timeswithTimeout– completes with a fallback if the future exceeds a durationwithFallback– returns a fallback value on any error
object_utils.dart (new)
- Kotlin-style scope functions:
let,also,takeIf,takeUnless
regexp_utils.dart (new)
RegExpPatternsclass with 14 pre-built patterns:email,url,phone,ipv4,ipv6,uuid,hexColor,creditCard,postalCode,date,time,username,slug,htmlTag
color_utils.dart (new)
isLight,isDark,luminance,contrastColorlighten,darken,withHue,withSaturation,withLightnessmix,complementary,grayscaleanalogous,triadic,tetradictoHex,toMaterialColorcontrastRatio,splitComplementary,withOpacityPercent,isAccessibleOn,shade,tint
iterable_utils.dart (new)
- Safe access:
firstOrNull,lastOrNull,singleOrNull - Counting:
count,none - Aggregation:
sumBy,averageBy,maxBy,minBy - Indexed iteration:
forEachIndexed,mapIndexed,whereIndexed - Transformation:
flatMap,chunked,distinctBy - Grouping:
groupBy,associateBy,associateWith
duration_utils.dart (new)
- Predicates:
isZero,isNegative - Derived units:
inWeeks - DateTime arithmetic:
ago,fromNow - Formatting:
formatted,toHhMmSs,toMmSs - Arithmetic:
multipliedBy,dividedBy,percentageOf,toCountdown
Improvements #
string_utils.dart
- Fixed:
toCamelCase,toSnakeCase,toPascalCase,toKebabCase - Fixed:
isEmailregex - Added:
isUrl,isPhoneNumber,mask,truncate,toSlug,initials,reverse,equalsIgnoreCase,fromBase64,toBase64,stripHtml,countOccurrences,wordCount,between,before,after,beforeLast,afterLast,dropLeft,dropRight,removePrefix,removeSuffix,format,formatMap,toHtmlText,repeat - Added:
levenshteinDistance,similarityTo,wordWrap,toSentenceCase,extractNumbers,extractEmails,extractUrls,compactWhitespace,truncateWords,tryParseJson - Added:
StringUtilsNullableextension withisNullOrEmpty,isNullOrBlank,orEmpty,orDefault
list_utils.dart
- Fixed:
sortedBy,sortedByDescendinggenerics - Fixed:
sumByreturn type - Added:
second,third,penultimate,flatten,zip,toPairs,windowed,rotate,swap,move,random,sample,frequencies,mode,median,average,averageBy - Added:
firstWhereOrNull,lastOrNull,intersperse,page,distinct,difference,intersection,cumulativeSum,transpose
map_utils.dart
- Fixed:
shiftmethod logic - Added:
getOrDefault,getOrPut,mapKeys,mapValues,invertMap,mergeWith,toQueryString,flatten,deepGet - Added:
deepMerge,deepSet,compact,renameKey,diff,pick,omit - Added top-level:
mapFromQueryString
number_utils.dart
- Fixed:
toCurrencyStringformatting - Added:
lerp,normalize,factorial,isPrime,toOrdinal,toRoman,toBinary,toHex,toOctal,roundTo,pad,percentage,digitCount,reversed,toRadians,toDegrees - Added:
clampTo,toFileSize,toDuration,toCompact,gcd,lcm,isFibonacci,toWords,safeDivide
datetime_utils.dart
- Fixed:
seasongetter logic - Added:
startOfDay,endOfDay,startOfWeek,endOfWeek,startOfMonth,endOfMonth,startOfYear,endOfYear,timeAgo,format,addWorkdays,nextWeekday,isBetween,age,quarterOfYear,weekOfYear,toUtcIso8601 - Added:
countdown,isBusinessHours,daysInMonth,copyWith,timezoneOffsetString,fiscalQuarter
enum_utils.dart
- Added:
labelgetter for human-readable enum names - Fixed:
when()now throwsArgumentErrorfor unhandled values
Testing #
- Added 540 comprehensive unit tests covering all extensions
1.0.2 #
- Added Enum Utils
- Updated
groupByextension in list to return a map of lists
1.0.1 #
- Added
sortedBy,sortedByDescending,groupBy,takeIf,takeWhile,joinToStringextensions in list - Updated
partitionextension in list/map to return a pair of lists
1.0.0 #
- Initial release
- Added list extensions
- Added map extensions
- Added number extensions
- Added string extensions
- Added datetime extensions