A grab-bag of miscellaneous, lightweight utility code for Dart. Functionality includes (but is not limited to):
List<int>.asUint8Listconverts aList<int>to aUint8Listwithout copying, if possible.
-
flattenDeeprecursively flattens nestedIterables into a singleIterablesequence. -
List.reversereverses aListin place. rain -
List.rotateLeftrotates aListin place. -
List.sortWithKeysorts aListby computing and caching sort keys, which can be significantly faster if comparisons are expensive. -
List.sortWithAsyncKeyis a version ofsortWithKeythat allows the sort key to be computed asynchronously. -
Iterable.startsWithreturns whether oneIterablestarts with the same sequence of elements as anotherIterable. -
Iterable.padLeftandIterable.padRightadd elements to anIterableto have a specified length. -
zipLongestis a version ofzipthat stops only after the longestIterableis exhausted instead of the shortest. -
LinkedHashMap.sort. -
mergeMapss combines anIterableofMaps into a singleMap. -
Map<K, Future<V>>.waitwaits forFuturevalues in aMap(in parallel if possible).
-
clampclamps aComparableobject to be within a specified range. -
compareIterablescompares twoIterables in a manner similar to string comparison. -
ComparableWrapperwraps a value in aComparableinterface with a specified comparison function.
-
assertsEnabledreturns whetherassertis enabled. -
currentDartFilePathreturns the path to the current.dartfile for Dart VM builds. -
staticTypereturns the static type of an object. -
String.escapeescapes aStringsuch that it can be used as a string literal in generated code.
toStringMatchesverifies that a tested value has a matching type and string representation.
-
lcmcomputes the least-common-multiple of two integers. -
int.floorToMultipleOf,int.ceilToMultipleOf, andint.roundToMultipleOfprovide different ways of rounding a non-negative integer to the nearest multiple of another. -
Rectangle.centerreturns the center of aRectangle.
-
tryAscasts an object and returnsnullon failure instead of throwing aTypeError. -
chainIfallows conditional method chaining based on a condition. -
OutputParameterallows specifying output parameters from functions as a crude mechanism to return multiple values. -
int.padLeftconverts anintto aString, left-padded with zeroes to have a minimum number of digits. -
String.lazySplitis a version ofString.splitthat returns anIterableto tokenize aStringlazily. -
String.partialSplitis a version ofString.splitthat limits the number of returned items. -
String.substringLooseis a version ofString.substringwith less strict bounds. -
Uri.updateQueryParametersadds or replaces query parameters in aUri. -
bool.impliesreturns whether oneboollogically implies another. -
Future.castcasts aFuture<T>to aFuture<R>. -
PollableFutureis an implementation ofFuturethat allows synchronously retrieving the value if it has already been completed. -
hoursOnly,minutesOnly,secondsOnly,millisecondsOnly, andmicrosecondsOnlyretrieve specific components of aDuration. -
DateTime.toStringWithOffsetandDateTime.toIso8601StringWithOffsetare versions ofDateTime.toStringandDateTime.totoIso8601Stringthat include timezone offsets.
-
tryParseBoolparses aboolfrom aString?. -
tryParseIntandtryParseDoubleare wrappers aroundint.tryParseanddouble.tryParsethat acceptnullarguments. -
List<Enum>.tryParseparses anEnumvalue from aString?. -
tryParseDurationparses aDurationfrom aString?.
-
randMaxIntportably returns the maximum value allowed byRandom.nextInt. -
Random.nextIntFromreturns a random integer in a specified range. -
lazyShufflershuffles aListlazily. -
RepeatableRandomwraps an existing pseudo-random number generator to allow a random sequence to be easily restarted and to allow the seed to be retrieved.
-
readableDurationreturns aDurationas a human-readable string. -
readableNumberreturns a number as a human-readable string with SI prefixes and units.
ExpiringPeriodicTimeris a periodicTimerthat automatically stops after a time limit.
-
getTerminalSizeattempts to get the number of columns and lines of a terminal. -
wordWrapwraps a string to a maximum line length. -
ArgResults.parseOptionValuereduces some boilerplate when parsing option values frompackage:args.