Superpowers for Dart. Collection of useful static extension methods.
APACHE-2.0 License
Bot releases are hidden (Show)
String?.isNullOrBlank
, String?.isNotNullOrBlank
IterableForthItem
-> IterableFourthItem
int.toChar(): String
String?.orEmpty: bool
String.matches(RexExp): bool
String.urlEncode
and String.urlDecode
buildString
to build a StringBuffer
an immediately return itIterable.takeFirst(n)
and Iterable.takeLast(n)
crashed when n > lengthPublished by simc almost 3 years ago
Map
. all()
, any()
, count()
, filter()
, filterKeys()
, filterNot
, filterValues
, getOrElse()
, mapEntries()
, mapKeys()
, mapValues()
, maxBy()
, maxWith()
, minBy()
, minWith
, none()
, toList()
, toMap()
, orEmpty()
sumBy
is now generic and works equally for num
/int
/double
min()
/max()
which returned the wrong item for reversed ordered listsplus()
/minus()
and plusOrNull
/minusOrNull
to num
which handle null
Iterable.second
returns T
instead of T?
. Analog to first
isUpperCase
/isLowerCase
now threat only [a-zA-Z]
chars as being uppercaseAlso, all linting issues have been fixed and the README has been drastically improved. Thanks @minhqdao
show
/hide
. This allows the usage of package:collection
and dartx
in the same file.firstOrNullWhere
until dartx
can export package:collection
itselfDirectory.file
and Directory.directory
extensions to quickly create file/directory referencestime
packageIterable<T>.zip(other, transform)
now supports zipping iterables of other types the T
. This is a breaking change because it is now required to add types in the transform function.
final amounts = [2, 3, 4];
final animals = ['dogs', 'birds', 'cats'];
final all = amounts.zip(animals, (int amount, String animal) => '$amount $animal');
// lambda types are now required: ⇧ ⇧
// all: ['2 dogs', '3 birds', '4 cats']
String
extensions
String removePrefix(String prefix)
String removeSuffix(String suffix)
String removeSurrounding({String prefix, String suffix})
final name = 'James Bond'.removePrefix('James '); // Bond
final milliseconds = '100ms'.removeSuffix('ms'); // 100
final text = '<p>Some HTML</p>'.removeSurrounding(prefix: '<p>', suffix: '</p>'); // Some HTML
List
extension void swap(int, int)
which swaps the elements in the indices provided.
final list = [1, 2, 3, 4];
list.swap(0, 2); // [3, 2, 1, 4]
collection
to support Flutter 1.20 (which uses collection: 1.3.0-nullsafety
)crypto
Iterable<T>.containsAny(Iterable<T>)
extensionIterable<num>.median()
extensionIterable<T>.asStream()
extension converts any Iterable to a StreamIterable<T>.cached
extension creates a cached Iterable
preventing lazy operators such as .map
to execute againIterable<Iterable<T>>.flatten()
typesafe and return Iterable<T>
instead of Iterable<dynamic>
Iterable<T>.chunkWhile(bool Function(T, T) predicate): Iterable<List<E>>
extension splits a collection into a lazy Iterables of chunks, where chunks are created as long as predicate
is true for a pair of entries.Iterable<T>.splitWhen(bool Function(E, E) predicate): Iterable<List<E>>
extension splits a collection into a lazy Iterable
, where each split will be make if predicate
returns true
for a pair of entries.Iterable<Future<T>>.asStreamAwaited(): Stream<T>
extension to create a stream from a group of futures.String.isNullOrEmpty
extensionString.toInt({int radix})
extension as alias for int.parse(String, {int radix})
(also String.toIntOrNull({int radix})
)String.chars
in favour of String.characters
from the official characters
package.Comparable<T>.rangeTo(Comparable<T> end)
extension to create ranges of DateTime
or String
.num.between(num first, num endInclusive): bool
extensionnum.inRange(Range<num> range): bool
extensionComparable<T>.between(T first, T endInclusive): bool
extensionComparable<T>.inRange(ComparableRange<T> range): bool
extensionThanks to our external contributors @ThinkDigitalSoftware, @shinayser, @yongjhih, @AKushWarrior, @rrousselGit, @simolus3 and @MohiuddinM!
int.rangeTo(int)
extensionComparable
<
, <=
, >=
and >
operators.quiver
dependencyString.md5
to calculate a MD5 digestFileSystemEntity.withName(String newName)
to get a File
with a different nameFileSystemEntity.extension
to get the file extensionCallable.invoke()
is now marked as Deprecated
in favour of darts call()
method. It will not be removed though, until darts .call()
methods gets auto-completion.Comparable.coerceIn()
, Comparable.coerceAtLeast()
and Comparable.coerceAtMost()
num.toBytes()
.thenBy()
and .thenWith()
extensions for Liststime.dart
library for time extensionsPublished by simc almost 5 years ago
Function.curry()
, Function.invoke()
, Function.partial()
and Function.flip()
'string'.reversed
now correctly handles grapheme clusters (like emoji)'string'.chars
now returns the grapheme clusters instead of Rune
sPublished by simc almost 5 years ago
Published by simc almost 5 years ago