{"id":13552478,"url":"https://github.com/simc/dartx","last_synced_at":"2026-01-11T13:33:55.612Z","repository":{"id":35345146,"uuid":"215669170","full_name":"simc/dartx","owner":"simc","description":"Superpowers for Dart. Collection of useful static extension methods.","archived":false,"fork":false,"pushed_at":"2024-07-24T21:34:38.000Z","size":351,"stargazers_count":1091,"open_issues_count":24,"forks_count":88,"subscribers_count":12,"default_branch":"master","last_synced_at":"2025-04-08T10:32:05.811Z","etag":null,"topics":["dart","flutter","hacktoberfest","static-extension","superpowers"],"latest_commit_sha":null,"homepage":"https://pub.dev/packages/dartx","language":"Dart","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/simc.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-10-17T00:25:56.000Z","updated_at":"2025-03-19T11:33:28.000Z","dependencies_parsed_at":"2024-01-19T07:03:28.875Z","dependency_job_id":"cd701b63-e161-48a7-b739-2f207e91b1e2","html_url":"https://github.com/simc/dartx","commit_stats":null,"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simc%2Fdartx","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simc%2Fdartx/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simc%2Fdartx/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simc%2Fdartx/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/simc","download_url":"https://codeload.github.com/simc/dartx/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254436949,"owners_count":22070947,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dart","flutter","hacktoberfest","static-extension","superpowers"],"created_at":"2024-08-01T12:02:04.628Z","updated_at":"2026-01-11T13:33:55.606Z","avatar_url":"https://github.com/simc.png","language":"Dart","readme":"\u003cimg src=\"https://raw.githubusercontent.com/leisim/dartx/master/.github/logo.svg?sanitize=true\" width=\"500px\"\u003e\n\n[![Dart CI](https://github.com/leisim/dartx/workflows/Dart%20CI/badge.svg?branch=master)](https://github.com/leisim/dartx/actions) [![Codecov](https://img.shields.io/codecov/c/github/leisim/dartx.svg)](https://codecov.io/gh/leisim/dartx) [![dartx](https://img.shields.io/pub/v/dartx?label=dartx)](https://pub.dev/packages/dartx) [![flutterx](https://img.shields.io/pub/v/flutterx?label=flutterx)](https://pub.dev/packages/flutterx)\n\n_If you miss an extension, please open an issue or pull request_\n\n### Resources:\n\n- [Documentation](https://pub.dev/documentation/dartx/latest/dartx/dartx-library.html)\n- [Pub Package](https://pub.dev/packages/dartx)\n- [GitHub Repository](https://github.com/leisim/dartx)\n\nOn this page you can find some of the extensions. Take a look at the docs to see all of them.\n\n## Getting started 🎉\n\nAdd the following to your `pubspec.yaml`:\n\n```dart\ndependencies:\n  dartx: any\n```\n\nAfter you import the library, you can use the extensions.\n\n```dart\nimport 'package:dartx/dartx.dart';\n\nfinal slice = [1, 2, 3, 4, 5].slice(1, -2); // [2, 3, 4]\n```\n\n## Iterable\n\n### .slice()\n\nReturns elements at indices between `start` (inclusive) and `end` (inclusive).\n\n```dart\nfinal list = [0, 1, 2, 3, 4, 5];\nfinal last = list.slice(-1); // [5]\nfinal lastHalf = list.slice(3); // [3, 4, 5]\nfinal allButFirstAndLast = list.slice(1, -2); // [1, 2, 3, 4]\n```\n\n### .sortedBy() \u0026 .thenBy()\n\nSort lists by multiple properties.\n\n```dart\nfinal dogs = [\n  Dog(name: \"Tom\", age: 3),\n  Dog(name: \"Charlie\", age: 7),\n  Dog(name: \"Bark\", age: 1),\n  Dog(name: \"Cookie\", age: 4),\n  Dog(name: \"Charlie\", age: 2),\n];\n\nfinal sorted = dogs\n    .sortedBy((dog) =\u003e dog.name)\n    .thenByDescending((dog) =\u003e dog.age);\n// Bark, Charlie (7), Charlie (2), Cookie, Tom\n```\n\n### .distinctBy()\n\nGet distinct elements from a list.\n\n```dart\nfinal list = ['this', 'is', 'a', 'test'];\nfinal distinctByLength = list.distinctBy((it) =\u003e it.length); // ['this', 'is', 'a']\n```\n\n### .flatten()\n\nGet a new lazy `Iterable` of all elements from all collections in a collection.\n\n```dart\nfinal nestedList = [[1, 2, 3], [4, 5, 6]];\nfinal flattened = nestedList.flatten(); // [1, 2, 3, 4, 5, 6]\n```\n\n### .chunkWhile() \u0026 .splitWhen()\n\nChunk entries as long as two elements match a predicate:\n\n```dart\nfinal list = [1, 2, 4, 9, 10, 11, 12, 15, 16, 19, 20, 21];\nfinal increasingSubSequences = list.chunkWhile((a, b) =\u003e a + 1 == b);\n\n// increasingSubSequences = [[1, 2], [4], [9, 10, 11, 12], [15, 16], [19, 20, 21]]\n```\n\n`splitWhen` is the opposite of `chunkWhile` that starts a new chunk every time\nthe predicate _didn't_ match.\n\n## int\n\n### buildString()\n\nBuilds new string by populating newly created `StringBuffer` using provided `builderAction`\nand then converting it to `String`.\n\n```dart\nfinal word = buildString((sb) {\n  for (var i = 0; i \u003c 10; i++) {\n    sb.write(i);\n  }\n});\n// 0123456789\n```\n\n### .ordinal\n\nReturns an ordinal number of `String` type for any integer\n\n```dart\nfinal a = 1.ordinal();  // 1st\nfinal b = 108.ordinal();  // 108th\n```\n\n## String\n\n### .capitalize\n\nReturns a copy of the string having its first letter uppercased, or the original string, if it's empty or already starts with an upper case letter.\n\n```dart\nfinal word = 'abcd'.capitalize(); // Abcd\nfinal anotherWord = 'Abcd'.capitalize(); // Abcd\n```\n\n### .decapitalize\n\nReturns a copy of the string having its first letter lowercased, or the original string, if it's empty or already starts with a lower case letter.\n\n```dart\nfinal word = 'abcd'.decapitalize(); // abcd\nfinal anotherWord = 'Abcd'.decapitalize(); // abcd\n```\n\n### .isAscii\n\nReturns `true` if the string is ASCII encoded.\n\n```dart\nfinal isAscii = 'abc123 !,.~'.isAscii; // true\nfinal isNotAscii = '§3'.isAscii; // false\n```\n\n### .isBlank\n\nReturns `true` if this string is empty or consists solely of whitespace characters.\n\n```dart\nfinal notBlank = '   .'.isBlank; // false\nfinal blank = '  '.isBlank; // true\n```\n\n### .isDouble\n\nReturns `true` if the string can be parsed as a double.\n\n```dart\nfinal a = ''.isDouble; // false\nfinal b = 'a'.isDouble; // false\nfinal c = '1'.isDouble; // true\nfinal d = '1.0'.isDouble; // true\nfinal e = '123456789.987654321'.isDouble; // true\nfinal f = '1,000'.isDouble; // false\n```\n\n### .isInt\n\nReturns `true` if the string can be parsed as an integer.\n\n```dart\nfinal a = ''.isInt; // false\nfinal b = 'a'.isInt; // false\nfinal c = '1'.isInt; // true\nfinal d = '1.0'.isInt; // false\nfinal e = '1,000'.isInt; // false\n```\n\n### .isLatin1\n\nReturns `true` if the string is Latin 1 encoded.\n\n```dart\nfinal isLatin1 = '§Êü'.isLatin1; // true\nfinal isNotLatin1 = 'ő'.isLatin1; // false\n```\n\n### .isLowerCase\n\nReturns `true` if the entire string is lower case.\n\n```dart\nfinal a = 'abc'.isLowerCase; // true\nfinal b = 'abC'.isLowerCase; // false\nfinal c = '   '.isLowerCase; // true\nfinal d = ''.isLowerCase; // false\n```\n\n### .isNotBlank\n\nReturns `true` if this string is not empty and contains characters except whitespace characters.\n\n```dart\nfinal blank = '  '.isNotBlank; // false\nfinal notBlank = '   .'.isNotBlank; // true\n```\n\n### .isNullOrEmpty\n\nReturns `true` if the String is either `null` or empty.\n\n```dart\nfinal isNull = null.isNullOrEmpty; // true\nfinal isEmpty = ''.isNullOrEmpty; // true\nfinal isBlank = ' '.isNullOrEmpty; // false\nfinal isLineBreak = '\\n'.isNullOrEmpty; // false\n```\n\n### .isNotNullOrEmpty\n\nReturns `true` if the String is neither `null` nor empty.\n\n```dart\nfinal isNull = null.isNullOrEmpty; // true\nfinal isEmpty = ''.isNullOrEmpty; // true\nfinal isBlank = ' '.isNullOrEmpty; // false\nfinal isLineBreak = '\\n'.isNullOrEmpty; // false\n```\n\n### .isNullOrBlank\n\nReturns `true` if the String is either `null` or blank.\n\n```dart\nfinal isNull = null.isNullOrBlank; // true\nfinal isEmpty = ''.isNullOrBlank; // true\nfinal isBlank = ' '.isNullOrBlank; // true\nfinal isLineBreak = '\\n'.isNullOrBlank; // true\nfinal isFoo = ' foo '.isNullOrBlank; // false\n```\n\n### .isNotNullOrBlank\n\nReturns `true` if the String is neither `null` nor blank.\n\n```dart\nfinal isNull = null.isNullOrBlank; // true\nfinal isEmpty = ''.isNullOrBlank; // true\nfinal isBlank = ' '.isNullOrBlank; // true\nfinal isLineBreak = '\\n'.isNullOrBlank; // true\nfinal isFoo = ' foo '.isNullOrBlank; // true\n```\n\n### .isUpperCase\n\nReturns `true` if the entire string is upper case.\n\n```dart\nfinal a = 'ABC'.isUpperCase; // true\nfinal b = 'ABc'.isUpperCase; // false\nfinal c = '   '.isUpperCase; // true\nfinal d = ''.isUpperCase; // false\n```\n\n### .md5\n\nCalculates the MD5 digest and returns the value as a string of hexadecimal digits.\n\n```dart\nfinal a = 'abc'.md5; // 900150983cd24fb0d6963f7d28e17f72\nfinal b = 'ഐ⌛酪Б👨‍👨‍👧‍👦'.md5; // c7834eff7c967101cfb65b8f6d15ad46\n```\n\n### .urlEncode\n\nTranslates a string into application/x-www-form-urlencoded format using a specific encoding scheme.\n\n```dart\nconst originalUrl = 'Hello Ladies + Gentlemen, a signed OAuth request!';\nfinal encodedUrl = originalUrl.urlEncode;\n// 'Hello%20Ladies%20+%20Gentlemen,%20a%20signed%20OAuth%20request!'\n```\n\n### .urlDecode\n\nDecodes an application/x-www-form-urlencoded string using a specific encoding scheme.\n\n```dart\nconst encodedUrl = 'Hello%20Ladies%20+%20Gentlemen,%20a%20signed%20OAuth%20request!';\nfinal decodedUrl = encodingUrl.urlDecode;\n// 'Hello Ladies + Gentlemen, a signed OAuth request!'\n```\n\n### .removePrefix(), .removeSuffix() and .removeSurrounding()\n\nRemove a prefix, a suffix, or both from a given string:\n\n```dart\nfinal name = 'James Bond'.removePrefix('James '); // Bond\nfinal milliseconds = '100ms'.removeSuffix('ms'); // 100\nfinal text = '\u003cp\u003eSome HTML\u003c/p\u003e'\n  .removeSurrounding(prefix: '\u003cp\u003e', suffix: '\u003c/p\u003e'); // Some HTML\n```\n\n### .reversed\n\nReturns a new string with characters in reversed order.\n\n```dart\nfinal emptyString = ''.reversed; // ''\nfinal reversed = 'abc🤔'.reversed; // '🤔cba'\n```\n\n### .slice()\n\nReturns a new substring containing all characters including indices [start] and [end].\nIf [end] is omitted, it is being set to `lastIndex`.\n\n```dart\nfinal sliceOne = 'awesomeString'.slice(0,6)); // awesome\nfinal sliceTwo = 'awesomeString'.slice(7)); // String\n```\n\n### .toDoubleOrNull()\n\nParses the string as a `double` and returns the result or `null` if the String is not a valid representation of a number.\n\n```dart\nfinal numOne = '1'.toDoubleOrNull(); // 1.0\nfinal numTwo = '1.2'.toDoubleOrNull(); // 1.2\nfinal blank = ''.toDoubleOrNull(); // null\n```\n\n### .toInt()\n\nParses the string as an integer and returns the result. The radix (base) thereby defaults to 10. Throws a `FormatException` if parsing fails.\n\n```dart\nfinal a = '1'.toInt(); // 1\nfinal b = '100'.toInt(radix: 2); // 4\nfinal c = '100'.toInt(radix: 16); // 256\nfinal d = '1.0'.toInt(); // throws FormatException\n```\n\n### .toIntOrNull()\n\nParses the string as an integer or returns `null` if it is not a number.\n\n```dart\nfinal number = '12345'.toIntOrNull(); // 12345\nfinal notANumber = '123-45'.toIntOrNull(); // null\n```\n\n### .toUtf8()\n\nConverts String to UTF-8 encoding.\n\n```dart\nfinal emptyString = ''.toUtf8(); // []\nfinal hi = 'hi'.toUtf8(); // [104, 105]\nfinal emoji = '😄'.toUtf8(); // [240, 159, 152, 132]\n\n```\n\n### .toUtf16()\n\nConverts String to UTF-16 encoding.\n\n```dart\nfinal emptyString = ''.toUtf16(); // []\nfinal hi = 'hi'.toUtf16(); // [104, 105]\nfinal emoji = '😄'.toUtf16(); // [55357, 56836]\n```\n\n### .orEmpty()\n\nReturns the string if it is not `null`, or the empty string otherwise.\n\n```dart\nString? nullableStr;\nfinal str = nullableStr.orEmpty(); // ''\n```\n\n### .matches()\n\nReturns `true` if this char sequence matches the given regular expression.\n\n```dart\nprint('as'.matches(RegExp('^.s\\$'))) // true\nprint('mst'.matches(RegExp('^.s\\$'))) // false\n```\n\n### Time utils\n\nDartx exports [@jogboms](https://github.com/jogboms) great [⏰ time.dart](https://github.com/jogboms/time.dart) package so you can do the following:\n\n```dart\nint secondsInADay = 1.days.inSeconds;\n\nDuration totalTime = [12.5.seconds, 101.milliseconds, 2.5.minutes].sum();\n\nDateTime oneWeekLater = DateTime.now() + 1.week;\n```\n\nCheck out [⏰ time.dart](https://github.com/jogboms/time.dart) for more information and examples.\n\n## num\n\n### .coerceIn()\n\nEnsures that this value lies in the specified range.\n\n```dart\nfinal numberInRange = 123.coerceIn(0, 1000); // 123\nfinal numberOutOfRange = -123.coerceIn(0, 1000); // 0\n```\n\n### .toBytes()\n\nConverts this value to binary form.\n\n### .toChar()\n\nConverts this value to character\n\n```dart\nfinal character = 97.toChar(); // a\n```\n\n## range\n\n### rangeTo\n\nCreates a range between two ints (upwards, downwards and with custom steps)\n\n```dart\n// upwards with default step size 1\nfor (final i in 1.rangeTo(5)) {\n  print(i); // 1, 2, 3, 4, 5\n}\n// downwards with custom step\nfor (final i in 10.rangeTo(2).step(2)) {\n  print(i); // 10, 8, 6, 4, 2\n}\n```\n\n## Function\n\n### .partial(), .partial2() ...\n\nApplies some of the required arguments to a function and returns a function which takes the remaining arguments.\n\n```dart\nvoid greet(String firstName, String lastName) {\n  print('Hi $firstName $lastName!');\n}\n\nfinal greetStark = greet.partial('Stark');\ngreetStark('Sansa'); // Hi Sansa Stark!\ngreetStark('Tony'); // Hi Tony Stark!\n```\n\n## File\n\n### .name\n\nGet the name and extension of a file.\n\n```dart\nfinal file = File('some/path/testFile.dart');\nprint(file.name); // testFile.dart\nprint(file.nameWithoutExtension); // testFile\n```\n\n### .appendText()\n\nAppend text to a file.\n\n```dart\nawait File('someFile.json').appendText('{test: true}');\n```\n\n### .isWithin()\n\nChecks if a file is inside a directory.\n\n```dart\nfinal dir = Directory('some/path');\nFile('some/path/file.dart').isWithin(dir); // true\n```\n\n## Directory\n\n### .file(String)\n\nReferences a file within a `Directory`\n\n```dart\nDirectory androidDir = Directory('flutter-app/android');\nFile manifestFile = androidDir.file(\"app/src/main/AndroidManifest.xml\");\n```\n\nReferences a directory within a `Directory`\n\n### .directory(String)\n\n```dart\nDirectory androidDir = Directory('flutter-app/android');\nDirectory mainSrc = androidDir.directory(\"app/src/main\");\n```\n\n### .contains(FileSystemEntity entity, {bool recursive = false})\n\nChecks if a `Directory` contains a `FileSystemEntity`. This can be a `File` or a `Directory`.\n\nUse the `recursive` argument to include the subdirectories.\n\n```dart\nfinal File someFile = File('someFile.txt');\nfinal Directory someDir = Directory('some/dir');\n\nfinal Directory parentDir = Directory('parent/dir');\n\nparentDir.contains(someFile);\nparentDir.contains(someDir);\nparentDir.contains(someFile, recursive: true);\nparentDir.contains(someDir, recursive: true);\n```\n\nThis is the `async` method, which returns a `Future\u003cbool\u003e`.\n\n### .containsSync(FileSystemEntity entity, {bool recursive = false})\n\nSame as `.contains(FileSystemEntity entity, {bool recursive = false})` but synchronous. Returns a `bool`.\n\n## License\n\n```plain\nCopyright 2019 Simon Leier\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n   http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n```\n","funding_links":[],"categories":["Dart"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimc%2Fdartx","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsimc%2Fdartx","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimc%2Fdartx/lists"}