Saropa Dart Utils
Boilerplate reduction tools and human readable extension methods by Saropa
We encourage your to review our public Code of Conduct.
34 extension classes providing 200+ utility methods | 1,000+ test cases ensuring reliability
Table of Contents
Quick Start
Add to your pubspec.yaml:
dependencies:
saropa_dart_utils: ^0.5.7
Import the package:
import 'package:saropa_dart_utils/saropa_dart_utils.dart';
Extension Categories
String Extensions
Null Safety & Checking
String? text;
text.isNullOrEmpty; // true
text.notNullOrEmpty; // false
text = "Hello";
text.isNullOrEmpty; // false
"".isNumeric(); // false
"123".isNumeric(); // true
Case Manipulation
"hello world".titleCase(); // "Hello world"
"hello world".capitalizeWords(); // "Hello World"
"hello".upperCaseFirstChar(); // "Hello"
"HELLO".lowerCaseFirstChar(); // "hELLO"
"helloWorld".insertSpaceBetweenCapitalized(); // "hello World"
Wrapping & Formatting
"Saropa".wrapSingleQuotes(); // 'Saropa'
"Saropa".wrapDoubleQuotes(); // "Saropa"
"Saropa".wrapWith(before: "(", after: ")"); // (Saropa)
"Saropa".encloseInParentheses(); // (Saropa)
Truncation
"Very long text here".truncateWithEllipsis(10); // "Very long โฆ"
"This is a long sentence".truncateWithEllipsisPreserveWords(15); // "This is a longโฆ"
Cleaning & Removing
"www.saropa.com".removeStart("www."); // "saropa.com"
"saropa.com/".removeEnd("/"); // "saropa.com"
" multiple spaces ".compressSpaces(); // "multiple spaces"
"abc123def".removeNonNumbers(); // "123"
"Hello!?".removePunctuation(); // "Hello"
Searching & Extracting
"hello world".isContainsWord("world"); // true
"test@example.com".between("@", "."); // "example"
"path/to/file".betweenLast("/", "."); // "file"
"get-everything-after".getEverythingAfter("-"); // "everything-after"
Pluralization & Grammar
"apple".pluralize(3); // "apples"
"box".pluralize(2); // "boxes"
"John".possess(); // "John's"
"apple".grammarArticle(); // "an"
Diacritics
"cafรฉ".removeDiacritics(); // "cafe"
"cafรฉ".containsDiacritics(); // true
DateTime Extensions
Date Comparisons
DateTime date = DateTime(2024, 1, 1);
date.isToday(); // false
date.isBeforeNow(); // true
date.isAfterNow(); // false
date.isSameDateOnly(DateTime(2024, 1, 1, 12, 0)); // true
date.isBetween(DateTime(2023, 1, 1), DateTime(2025, 1, 1)); // true
Date Manipulation
DateTime date = DateTime(2024, 1, 15);
date.addYears(1); // 2025-01-15
date.addMonths(2); // 2024-03-15
date.addDays(10); // 2024-01-25
date.nextDay(); // 2024-01-16
date.prevDay(); // 2024-01-14
Age Calculation
DateTime birthDate = DateTime(1990, 5, 15);
birthDate.calculateAgeFromNow(); // Current age
birthDate.isUnder13(); // false
Date Ranges
DateTime start = DateTime(2024, 1, 1);
DateTimeRange range = DateTimeRange(start: start, end: start.addDays(30));
range.inRange(DateTime(2024, 1, 15)); // true
Date List Generation
DateTime.now().generateDayList(7); // List of next 7 days
List Extensions
Comparison & Searching
[1, 2, 3].equalsIgnoringOrder([3, 2, 1]); // true
['a', 'a', 'b'].topOccurrence(); // 'a'
[1, 2, 3].containsAny([3, 4, 5]); // true
[1, 2, 3].itemAt(1); // 2
[1, 2, 3].itemAt(10); // null (safe access)
Null-Safe Operations
List<String> items = [];
items.addIfNotNull(null); // List remains empty
items.addIfNotNull("value"); // ["value"]
Unique Lists
[1, 2, 2, 3, 3, 3].unique(); // [1, 2, 3]
Int Extensions
Number Formatting
1.ordinal(); // "1st"
2.ordinal(); // "2nd"
3.ordinal(); // "3rd"
21.ordinal(); // "21st"
Range Operations
5.forceBetween(1, 10); // 5
15.forceBetween(1, 10); // 10
-5.forceBetween(1, 10); // 1
Digit Counting
12345.countDigits(); // 5
Num Extensions
Range Checks
5.isBetween(1, 10); // true
15.isBetween(1, 10); // false
5.isInRange(1, 10); // true (inclusive)
Iterable Extensions
Random Selection
[1, 2, 3, 4, 5].randomElement(); // Random element
Set Operations
[1, 2, 3].containsAll([1, 2]); // true
Filtering & Counting
[1, 2, 3, 4, 5].countWhere((n) => n > 3); // 2
Min/Max on Comparables
[3, 1, 4, 1, 5].smallestOccurrence(); // 1
[3, 1, 4, 1, 5].biggestOccurrence(); // 5
Map Extensions
Formatting
Map<String, dynamic> data = {'name': 'John', 'age': 30};
data.formatMap(); // Pretty-printed map
Key Removal
Map<String, dynamic> data = {'a': 1, 'b': 2, 'c': 3};
data.removeKeys(['a', 'c']); // Removes specified keys
Bool Extensions
String Conversion
"true".toBool(); // true
"false".toBool(); // false
"TRUE".toBool(); // true (case-insensitive)
Iterable Operations
[true, true, false].allTrue; // false
[true, true, true].allTrue; // true
[false, false, false].allFalse; // true
Enum Extensions
Safe Enum Parsing
enum Status { active, inactive, pending }
Status.values.byNameTry("active"); // Status.active
Status.values.byNameTry("invalid"); // null (safe)
Status.values.byNameTry("ACTIVE", caseSensitive: false); // Status.active
Other Utilities
Hex Utilities
HexUtils.intToHex(255); // "FF"
HexUtils.hexToInt("FF"); // 255
Random Utilities
CommonRandom.randomInt(1, 10); // Random int between 1 and 10
CommonRandom.randomDouble(0.0, 1.0); // Random double
Gesture Utilities
SwipeProperties.fromDelta(dx: 100, dy: 10); // Detects horizontal swipe
URL Extensions
Uri url = Uri.parse("https://example.com?key=value");
url.hasQueryParameter("key"); // true
Full API Documentation
For complete documentation of all extensions and utilities, visit:
Browse documentation by category:
Deployment Guide For Developers
-
Update CHANGELOG.md
-
Format
dart format .(note the trailing period ".") -
Test
flutter test -
Execute
dart doc -
Deploy
flutter pub publish
๐ ๐ ๐ฅ ๐ข ๐จ ๐ ๐ค ๐ฏ ๐ก๏ธ ๐ ๐ โฑ๏ธ ๐ ๐ ๐ ๐ ๐ฒ ๐ผ
About Saropa
Saropaยฎ๏ธ is a technology company established in 2010. We have a strong background in financial services, online security and secure web communications.
Our team has extensive experience in top-tier financial technology and we are passionate believers in personal risk management. We are engaged and excited about our vision for family security and this encourages our culture of innovation.
Saropa Contacts is a private, cloud-connected address book that links real people, companies, and emergency groups. It is primarily focused on your trusted emergency groups. Our mission is to reduce the impact of crises everywhere.
In an emergency, get real-time access to all the important people, companies, and services you need - even if you don't know them personally, or if they're not where you expect them to be.
Visit the Saropa Contacts project here: app.saropa.com
PRs, ideas and issues are always welcome! Email for any questions app.dev.utils@saropa.com or find us on Slack Saropa
๐ Saropa
Libraries
- bool/bool_iterable_extensions
- bool/bool_string_extensions
- datetime/date_constant_extensions
- datetime/date_constants
- datetime/date_time_extensions
- datetime/date_time_nullable_extensions
- datetime/date_time_range_utils
- datetime/date_time_utils
- datetime/time_emoji_utils
- double/double_iterable_extensions
- enum/enum_iterable_extensions
- gesture/swipe_properties
- hex/hex_utils
- int/int_extensions
- int/int_iterable_extensions
- int/int_nullable_extensions
- int/int_string_extensions
- int/int_utils
- iterable/comparable_iterable_extensions
- iterable/iterable_extensions
- json/json_utils
- list/list_extensions
- list/list_nullable_extensions
- list/list_of_list_extensions
- list/make_list_extensions
- list/unique_list_extensions
- map/map_extensions
- map/map_nullable_extensions
- num/num_extensions
- num/num_range_extensions
- num/num_utils
- random/common_random
- saropa_dart_utils
- Saropa Dart Utils - Boilerplate reduction tools and human-readable extension methods by Saropa.
- string/string_between_extensions
- string/string_case_extensions
- string/string_character_extensions
- string/string_diacritics_extensions
- string/string_extensions
- string/string_nullable_extensions
- string/string_number_extensions
- string/string_punctuation
- string/string_search_extensions
- string/string_utils
- url/url_extensions