dartbag 0.7.0+1 dartbag: ^0.7.0+1 copied to clipboard
A grab-bag of miscellaneous, lightweight utility libraries for Dart.
dartbag #
A grab-bag of miscellaneous, lightweight utility code for Dart. Functionality includes (but is not limited to):
byte_data #
List<int>.asUint8List
converts aList<int>
to aUint8List
without copying, if possible.
collection #
-
flattenDeep
recursively flattens nestedIterable
s into a singleIterable
sequence. -
List.reverse
reverses aList
in place. -
List.rotateLeft
rotates aList
in place. -
List.sortWithKey
sorts aList
by computing and caching sort keys, which can be significantly faster if comparisons are expensive. -
List.sortWithAsyncKey
is a version ofsortWithKey
that allows the sort key to be computed asynchronously. -
LinkedHashMap.sort
. -
mergeMaps
s combines anIterable
ofMap
s into a singleMap
.
comparable #
-
clamp
clamps aComparable
object to be within a specified range. -
compareIterables
compares twoIterable
s in a manner similar to string comparison. -
ComparableWrapper
wraps a value in aComparable
interface with a specified comparison function.
debug #
-
assertsEnabled
returns whetherassert
is enabled. -
currentDartFilePath
returns the path to the current.dart
file for Dart VM builds. -
staticType
returns the static type of an object.
matcher #
toStringMatches
verifies that a tested value has a matching type and string representation.
math #
-
lcm
computes the least-common-multiple of two integers. -
int.floorToMultipleOf
,int.ceilToMultipleOf
, andint.roundToMultipleOf
provide different ways of rounding a non-negative integer to the nearest multiple of another. -
Rectangle.center
returns the center of aRectangle
.
misc #
-
chainIf
allows conditional method chaining based on a condition. -
tryAs
casts an object and returnsnull
on failure instead of throwing aTypeError
. -
OutputParameter
allows specifying output parameters from functions as a crude mechanism to return multiple values. -
int.padLeft
converts anint
to aString
, left-padded with zeroes to have a minimum number of digits. -
Uri.updateQueryParameters
adds or replaces query parameters in aUri
. -
bool.implies
returns whether onebool
logically implies another. -
Future.cast
casts aFuture<T>
to aFuture<R>
. -
PollableFuture
is an implementation ofFuture
that allows synchronously retrieving the value if it has already been completed. -
hoursOnly
,minutesOnly
,secondsOnly
,millisecondsOnly
, andmicrosecondsOnly
retrieve specific components of aDuration
. -
DateTime.toStringWithOffset
andDateTime.toIso8601StringWithOffset
are versions ofDateTime.toString
andDateTime.totoIso8601String
that include timezone offsets.
parse #
-
tryParseBool
parses abool
from aString?
. -
tryParseInt
andtryParseDouble
are wrappers aroundint.tryParse
anddouble.tryParse
that acceptnull
arguments. -
List<Enum>.tryParse
parses anEnum
value from aString?
. -
tryParseDuration
parses aDuration
from aString?
.
random #
-
randMaxInt
portably returns the maximum value allowed byRandom.nextInt
. -
Random.nextIntFrom
returns a random integer in a specified range. -
lazyShuffler
shuffles aList
lazily. -
RepeatableRandom
wraps an existing pseudo-random number generator to allow a random sequence to be easily restarted and to allow the seed to be retrieved.
readable_numbers #
-
readableDuration
returns aDuration
as a human-readable string. -
readableNumber
returns a number as a human-readable string with SI prefixes and units.
timer #
ExpiringPeriodicTimer
is a periodicTimer
that automatically stops after a time limit.
tty #
-
getTerminalSize
attempts to get the number of columns and lines of a terminal. -
wordWrap
wraps a string to a maximum line length. -
ArgResults.parseOptionValue
reduces some boilerplate when parsing option values frompackage:args
.