dartkt 1.0.4

  • Readme
  • Changelog
  • Example
  • Installing
  • new58

DartKT #

A dart library for lazier programmers.

Getting Started #

Add dependence of dartkt to your project. The last version is 1.0.2 .

dependencies:
    ... ...
    dartkt: ^1.0.2

Functions #

Functions in the library are ported from kotlin, also included some useful utils like http.

Here is a list for cognition:

ClassMethodDefinitionNote
KTObjectExtensionalsoT also(void Function(T) block)
letR let<R>(R Function(T) block)
takeIfT takeIf(bool Function(T) block)
takeUnlessT takeUnless(bool Function(T) block)
HttpMethodGET, HEAD, POST, PUT, DELETE
HttpResponse
HttpError
httphttpFuture<HttpResponse> http(String url, HttpMethod method, {Map<String, String> param,String mimeType='application/json', String body, Map<String, String> postParam, Map<String, String> fileParam, Map<String, String> headers, int timeout=15})
httpGetFuture<HttpResponse> httpGet(String url, {Map<String, String> param, Map<String, String> headers})
httpPostFuture<HttpResponse> httpPost(String url, {Map<String, String> param, String body, Map<String, String> headers})
DownloadStateStart, Progress, Complete, Error
DownloadCallbackvoid Function(DownloadState state, int position, int filesize, String error)
downloaddownloadFuture<bool> download(String url, String localFile, DownloadCallback callback)
KTPairtoListList<T> toList()
KTTripletoListList<A> toList()
KTStringExtensionsubstringBeforeString substringBefore(Pattern pattern)
substringAfterString substringAfter(Pattern pattern)
substringBeforeLastString substringBeforeLast(Pattern pattern)
substringAfterLastString substringAfterLast(Pattern pattern)
removeRangeString removeRange(int startIdx, int endIdx)
removePrefixString removePrefix(Pattern pattern)
removeSuffixString removeSuffix(Pattern pattern)
removeSurroundingString removeSurrounding(Pattern pattern)
replaceBeforeString replaceBefore(Pattern pattern, String replacement)
replaceAfterString replaceAfter(Pattern pattern, String replacement)
replaceAfterLastString replaceAfterLast(Pattern pattern, String replacement)
replaceBeforeLastString replaceBeforeLast(Pattern pattern, String replacement)
linesList<String> lines()
dropString drop(int n)
dropLastString dropLast(int n)
filterString filter(bool Function(String) block)
filterIndexedString filterIndexed(bool Function(int, String) block)
filterNotString filterNot(bool Function(String) block)
reversedString reversed()
toListList<String> toList()
mapList<T> map<T>(T Function(String) block)
mapIndexedList<T> mapIndexed<T>(T Function(int, String) block)
forEachforEach(void Function(String) action)
forEachIndexedforEachIndexed(void Function(int, String) action)
reduceString reduce(String Function(String, String) block)
reduceIndexedString reduceIndexed(String Function(int, String, String) block)
toIntint toInt()
toDoubledouble toDouble()
toBoolbool toBool()
base64encodeString base64encode()
base64decodeString base64decode()
toIntListList<int> toIntList()
lastPathPartString lastPathPart()
getPathDirectoryString getPathDirectory()
toJsonEncodedString toJsonEncoded()
toTitleUpperCaseString toTitleUpperCase()
appendPathPartString appendPathPart(String part)
extensionString extension()
replaceTagString replaceTag(String tag, String Function() block)
skipEmptyLineString skipEmptyLine()
toPairKTPair<String, String> toPair()
savesave(File f)
asFileWriteTextFile asFileWriteText(String s)
asFileReadTextString asFileReadText()
asFileMkdirsasFileMkdirs()
asFileFile asFile()
hashString hash([String alg])
md5sha1String get md5sha1
KTListExtension<T>findT find(bool Function(T) block)
findLastT findLast(bool Function(T) block)
indexOfFirstint indexOfFirst(bool Function(T) block)
indexOfLastint indexOfLast(bool Function(T) block)
dropList<T> drop(int n)
dropLastList<T> dropLast(int n)
filterList<T> filter(bool Function(T) block)
filterIndexedList<T> filterIndexed(bool Function(int, T) block)
filterNotList<T> filterNot(bool Function(T) block)
sliceList<T> slice(int startIdx, int endIdx)
sortByList<T> sortBy(int Function(T, T) block)
sortByDescendingList<T> sortByDescending(int Function(T, T) block)
map2List<R> map2<R>(R Function(T) block)overrided
map2IndexedList<R> map2Indexed<R>(R Function(int, T) block)
distinctList<T> distinct()
distinctByList<T> distinctBy<R>(R Function(T) block)
allbool all(bool Function(T) block)
anybool any(bool Function(T) block)
countint count(bool Function(T) block)
forEachIndexedforEachIndexed(void Function(int, T) block)
nonebool none(bool Function(T) block)
reduceIndexedT reduceIndexed(T Function(int, T, T) block)
minusminus(List<T> list)
joinToStringString joinToString([String sep = ',', String Function(T) block])
toStringListList<String> toStringList()
toMapMap<K, V> toMap<K, V>()
mapToC mapTo<R, C extends List<R>>(C dest, R Function(T))
mapIndexedToC mapIndexedTo<R, C extends List<R>>(C dest, R Function(int, T) block)
filterToC filterTo<C extends List<T>>(C dest, bool Function(T) block)
filterIndexedToC filterIndexedTo<C extends List<T>>(C dest, bool Function(int, T) block)
filterNotToC filterNotTo<C extends List<T>>(C dest, bool Function(T) block)
toGridDataList<List<T>> toGridData([int column = 1])
KTListListExtension<T>toListDataList<T> toListData()
KTSetExtension<T>findT find(bool Function(T) block)
findLastT findLast(bool Function(T) block)
indexOfFirstint indexOfFirst(bool Function(T) block)
indexOfLastint indexOfLast(bool Function(T) block)
dropSet<T> drop(int n)
dropLastSet<T> dropLast(int n)
filterSet<T> filter(bool Function(T) block)
filterIndexedSet<T> filterIndexed(bool Function(int, T) block)
filterNotSet<T> filterNot(bool Function(T) block)
sliceSet<T> slice(int startIdx, int endIdx)
sortBySet<T> sortBy(int Function(T, T) block)
sortByDescendingSet<T> sortByDescending(int Function(T, T) block)
map2Set<R> map2<R>(R Function(T) block)overrided
map2IndexedSet<R> map2Indexed<R>(R Function(int, T) block)
distinctSet<T> distinct()
distinctBySet<T> distinctBy<R>(R Function(T) block)
allbool all(bool Function(T) block)
anybool any(bool Function(T) block)
countint count(bool Function(T) block)
forEachIndexedforEachIndexed(void Function(int, T) block)
nonebool none(bool Function(T) block)
reduceIndexedT reduceIndexed(T Function(int, T, T) block)
minusminus(Set<T> s)
joinToStringString joinToString([String sep = ',', String Function(T) block])
toStringListSet<String> toStringList()
toMapMap<K, V> toMap<K, V>()
mapToC mapTo<R, C extends Set<R>>(C dest, R Function(T) block)
mapIndexedToC mapIndexedTo<R, C extends Set<R>>(C dest, R Function(int, T) block)
filterToC filterTo<C extends Set<T>>(C dest, bool Function(T) block)
filterIndexedToC filterIndexedTo<C extends Set<T>>(C dest, bool Function(int, T) block)
filterNotToC filterNotTo<C extends Set<T>>(C dest, bool Function(T) block)
KTMapExtension<K, V>toListList<KTPair<K, V>> toList()
mapToListList<R> mapToList<R>(R Function(MapEntry<K, V>) block)
forEachEntryforEachEntry(void Function(MapEntry<K, V>) block)
allbool all(bool Function(MapEntry<K, V>) block)
anybool any(bool Function(MapEntry<K, V>) block)
countint count(bool Function(MapEntry<K, V>) block)
nonebool none(bool Function(MapEntry<K, V>) block)
filterKeysMap<K, V> filterKeys(bool Function(K) block)
filterValuesMap<K, V> filterValues(bool Function(V) block)
filterMap<K, V> filter(bool Function(MapEntry<K, V>) block)
filterNotMap<K, V> filterNot(bool Function(MapEntry<K, V>) block)
addadd(Map<K, V> m)
minusminus(Map<K, V> m)
filterToMap<K, V> filterTo<M extends Map<K, V>>(M dest, bool Function(MapEntry<K, V>) block)
filterNotToMap<K, V> filterNotTo<M extends Map<K, V>>(M dest, bool Function(MapEntry<K, V>) block)
filterKeysToMap<K, V> filterKeysTo<M extends Map<K, V>>(M dest, bool Function(K) block)
filterValuesToMap<K, V> filterValuesTo<M extends Map<K, V>>(M dest, bool Function(V) Block)
mapToMap<K2, V2> mapTo<K2, V2, C extends Map<K2, V2>>(C dest, MapEntry<K2, V2> Function(MapEntry<K, V>) block)
mapToListToList<R> mapToListTo<R, C extends List<R>>(C dest, R Function(MapEntry<K, V>) block)
mapKeysToMap<K2, V2> mapKeysTo<K2, V2, C extends Map<K2, V2>>(C dest, MapEntry<K2, V2> Function(K) block)
mapKeysToListToList<R> mapKeysToListTo<R, C extends List<R>>(C dest, R Function(K) block)
mapValuesToMap<K2, V2> mapValuesTo<K2, V2, C extends Map<K2, V2>>(C dest, MapEntry<K2, V2> Function(V) block)
mapValuesToListToList<R> mapValuesToListTo<R, C extends List<R>>(C dest, R Function(V) block)
RegexUtilisStringRegbool isStringReg(String str, int type)
isNumberRegbool isNumberReg(String str, int type)
isEmailbool isEmail(String str)
isPhoneNumberbool isPhoneNumber(String str)
isCellPhoneNumberbool isCellPhoneNumber(String str)
isChinesePhoneNumberbool isChinesePhoneNumber(String str)
isIdCardNumberbool isIdCardNumber(String str)
isShortIdCardNumberbool isShortIdCardNumber(String str)
isUrlbool isUrl(String str)
isDomainbool isDomain(String str)
isValidAccountbool isValidAccount(String str)
isValidPasswordbool isValidPassword(String str)
isStrongPasswordbool isStrongPassword(String str)
isDatebool isDate(String str)
isValidXmlbool isValidXml(String str)
isBlankLinebool isBlankLine(String str)
isValidHtmlbool isValidHtml(String str)
isValidQQNumberbool isValidQQNumber(String str)
isValidPostCodebool isValidPostCode(String str)
isValidIPAddressbool isValidIPAddress(String str)

1.0.4 #

  • More Functions

1.0.3 #

  • Add Set Extension

1.0.1 #

  • Initial version

example/dartkt_example.dart

import 'package:dartkt/dartkt.dart';

void main() {
  var list = [1, 2, 3];
  var list2 = list.map2((it) => 'item: $it');
  print(list2);
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  dartkt: ^1.0.4

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:dartkt/dartkt.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
20
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
90
Overall:
Weighted score of the above. [more]
58
Learn more about scoring.

We analyzed this package on Jan 16, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.0
  • pana: 0.13.4

Maintenance issues and suggestions

Make sure dartdoc successfully runs on your package's source files. (-10 points)

exitCode: 255 stdout: parsing /tmp/pub-dartlang-dartdocBBLAZT/pkg/lib/dartkt.dart... parsing /dart-sdk/lib/core/core.dart... parsing /dart-sdk/lib/collection/collection.dart... parsing /dart-sdk/lib/internal/internal.dart... parsing /dart-sdk/lib/async/async.dart... parsing /dart-sdk/lib/convert/convert.dart... parsing /dart-sdk/lib/typed_data/typed_data.dart... parsing /dart-sdk/lib/math/math.dart... parsing /tmp/pub-dartlang-dartdocBBLAZT/pkg/lib/src/bytearray_extension.dart... parsing /dart-sdk/lib/io/io.dart... parsing /dart-sdk/lib/developer/developer.dart... parsing /dart-sdk/lib/isolate/isolate.dart... parsing /dart-sdk/lib/_http/http.dart... parsing /tmp/pub-dartlang-dartdocBBLAZT/pkg/lib/src/config_extension.dart... parsing /tmp/pub-dartlang-dartdocBBLAZT/pkg/lib/src/list_extension.dart... parsing /tmp/pub-dartlang-dartdocBBLAZT/pkg/lib/src/pair_extension.dart... parsing /tmp/pub-dartlang-dartdocBBLAZT/pkg/lib/src/object_extension.dart... parsing /tmp/pub-dartlang-dartdocBBLAZT/pkg/lib/src/map_extension.dart... parsing /tmp/pub-dartlang-dartdocBBLAZT/pkg/lib/src/download_extension.dart... parsing /tmp/pub-dartlang-dartdocBBLAZT/pkg/lib/src/string_extension.dart... [...] parsing /dart-sdk/lib/web_audio/dart2js/web_audio_dart2js.dart... parsing /dart-sdk/lib/web_sql/dart2js/web_sql_dart2js.dart... parsing /dart-sdk/lib/js/dart2js/js_dart2js.dart... parsing /dart-sdk/lib/js/_js.dart... parsing /dart-sdk/lib/mirrors/mirrors.dart... parsing /dart-sdk/lib/html/dartium/nativewrappers.dart... parsing /dart-sdk/lib/cli/cli.dart... parsing /dart-sdk/lib/wasm/wasm.dart... parsing /dart-sdk/lib/_internal/js_runtime/lib/js_primitives.dart... parsing /dart-sdk/lib/_internal/js_runtime/lib/shared/async_await_error_codes.dart... parsing /tmp/pub-cache-dirFXYNRO/hosted/pub.dartlang.org/charcode-1.1.2/lib/html_entity.dart... parsing /tmp/pub-cache-dirFXYNRO/hosted/pub.dartlang.org/charcode-1.1.2/lib/charcode.dart... parsing /tmp/pub-cache-dirFXYNRO/hosted/pub.dartlang.org/collection-1.14.12/lib/algorithms.dart... parsing /tmp/pub-cache-dirFXYNRO/hosted/pub.dartlang.org/collection-1.14.12/lib/iterable_zip.dart... parsing /tmp/pub-cache-dirFXYNRO/hosted/pub.dartlang.org/collection-1.14.12/lib/priority_queue.dart... parsing /tmp/pub-cache-dirFXYNRO/hosted/pub.dartlang.org/collection-1.14.12/lib/wrappers.dart... parsing /tmp/pub-cache-dirFXYNRO/hosted/pub.dartlang.org/collection-1.14.12/lib/equality.dart... Initialized dartdoc with 105 libraries in 38.7 seconds documenting dartkt Generating docs for library dartkt from package:dartkt/dartkt.dart... stderr: Documenting dartkt... warning: unresolved doc reference [String alg], from package-dartkt: file:///tmp/pub-dartlang-dartdocBBLAZT/pkg warning: unresolved doc reference [int column = 1], from package-dartkt: file:///tmp/pub-dartlang-dartdocBBLAZT/pkg warning: dartkt has no library level documentation comments, from dartkt: (file:///tmp/pub-dartlang-dartdocBBLAZT/pkg/lib/dartkt.dart:1:9) Unhandled exception: type 'DynamicTypeImpl' is not a subtype of type 'InterfaceType' #0 TypeParameterElementType._interfaceType (package:dartdoc/src/element_type.dart:213:39) #1 DefinedElementType.instantiatedType (package:dartdoc/src/element_type.dart:284:12) #2 Extension._couldApplyTo (package:dartdoc/src/model/extension.dart:41:49) #3 Extension.couldApplyTo (package:dartdoc/src/model/extension.dart:31:7) #4 ExtensionTarget.potentiallyApplicableExtensions.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.7.0 <3.0.0
convert ^2.1.1 2.1.1
crypto ^2.1.4 2.1.4
Transitive dependencies
charcode 1.1.2
collection 1.14.12
typed_data 1.1.6
Dev dependencies
pedantic ^1.8.0
test ^1.6.0