saropa_dart_utils 0.5.12 copy "saropa_dart_utils: ^0.5.12" to clipboard
saropa_dart_utils: ^0.5.12 copied to clipboard

Boilerplate reduction tools and human-readable extension methods by Saropa

Saropa Dart Utils #

Boilerplate reduction tools and human-readable extension methods for Flutter/Dart.

pub.dev style: saropa lints license: GPL

Installation #

dependencies:
  saropa_dart_utils: ^0.5.11
import 'package:saropa_dart_utils/saropa_dart_utils.dart';

Features #

String Extensions #

// Null safety
String? text;
text.isNullOrEmpty;        // true
"hello".notNullOrEmpty;    // true

// Case manipulation
"hello world".titleCase();           // "Hello world"
"hello world".capitalizeWords();     // "Hello World"

// Formatting
"Saropa".wrapSingleQuotes();         // 'Saropa'
"Saropa".encloseInParentheses();     // (Saropa)

// Truncation
"Long text here".truncateWithEllipsis(10);  // "Long text…"

// Cleaning
"www.saropa.com".removeStart("www.");  // "saropa.com"
"  extra   spaces  ".compressSpaces(); // "extra spaces"
"abc123".removeNonNumbers();           // "123"

// Searching
"test@example.com".between("@", ".");  // "example"

// Grammar
"apple".pluralize(3);    // "apples"
"John".possess();        // "John's"
"apple".grammarArticle(); // "an"

// Diacritics
"cafe".removeDiacritics();  // "cafe"

DateTime Extensions #

DateTime date = DateTime(2024, 1, 15);

// Comparisons
date.isToday();
date.isBeforeNow();
date.isSameDateOnly(otherDate);
date.isBetween(start, end);

// Manipulation
date.addYears(1);
date.addMonths(2);
date.addDays(10);
date.nextDay();
date.prevDay();

// Age calculation
DateTime(1990, 5, 15).calculateAgeFromNow();
birthDate.isUnder13();

// List generation
DateTime.now().generateDayList(7);  // Next 7 days

List Extensions #

// Comparison
[1, 2, 3].equalsIgnoringOrder([3, 2, 1]);  // true
['a', 'a', 'b'].topOccurrence();           // 'a'

// Safe access
[1, 2, 3].itemAt(10);  // null (no exception)

// Null-safe operations
items.addIfNotNull(maybeNull);

// Deduplication
[1, 2, 2, 3].unique();  // [1, 2, 3]

Number Extensions #

// Ordinals
1.ordinal();   // "1st"
22.ordinal();  // "22nd"

// Range operations
15.forceBetween(1, 10);  // 10
5.isBetween(1, 10);      // true

// Digit counting
12345.countDigits();  // 5

Iterable Extensions #

[1, 2, 3, 4, 5].randomElement();
[1, 2, 3].containsAll([1, 2]);
[1, 2, 3, 4, 5].countWhere((n) => n > 3);  // 2

Map Extensions #

{'name': 'John', 'age': 30}.formatMap();  // Pretty print
data.removeKeys(['a', 'c']);

Bool Extensions #

"true".toBool();           // true
[true, true, true].allTrue; // true
[false, false].allFalse;    // true

Enum Extensions #

enum Status { active, inactive }

Status.values.byNameTry("active");   // Status.active
Status.values.byNameTry("invalid");  // null (safe)
Status.values.byNameTry("ACTIVE", caseSensitive: false);  // Status.active

Utilities #

// Hex
HexUtils.intToHex(255);   // "FF"
HexUtils.hexToInt("FF");  // 255

// Random
CommonRandom.randomInt(1, 10);
CommonRandom.randomDouble(0.0, 1.0);

// URL
Uri.parse("https://example.com?key=value").hasQueryParameter("key");  // true

Documentation #

Contributing #

PRs and issues welcome!

About Saropa #

Saropa is a technology company focused on personal safety and emergency preparedness. Our flagship product, Saropa Contacts, is a private cloud-connected address book for managing trusted emergency contacts.

Google Play App Store

3
likes
160
points
152
downloads

Publisher

verified publishersaropa.com

Weekly Downloads

Boilerplate reduction tools and human-readable extension methods by Saropa

Homepage
Repository (GitHub)
View/report issues

Documentation

API reference

License

GPL-3.0 (license)

Dependencies

characters, collection, flutter, jiffy

More

Packages that depend on saropa_dart_utils