helpers_plethora 2.0.3
helpers_plethora: ^2.0.3 copied to clipboard
An helpful variety of extensions and enumerations.
Helpers Plethora #
An helpful variety of enumerations and extensions.
I have developed this package based on need in some of my personal projects. However, I believe that this package contains a good amount of code that is useful for others as well, which is why I have published it and keep updating it.
enumerations #
AuthProvider #
In this enumeration are enumerated several authentication providers.
Although at this time the only feature introduced for this enumeration is to obtain the name string of the provider, the idea is to add several others in the course of future updates.
-
The
nameproperty returns the name of the authentication provider.final provider = AuthProvider.github; provider.name; // GitHub -
In my packages, by convention, I always provide the
string()method to enumerations. This method returns the corresponding string value of anAuthProvidervalue. To comply with the convention, this enumeration also has this method. However, in this case, it’s just a call to thenameproperty.final provider = AuthProvider...; provider.string() == provider.name; // true -
With method
toAuthProvider(), theStringclass has been extended to give it the ability to return the correspondingAuthProvidervalue. In case the string does not contain a valid representation of anAuthProvidervalue, this method returns aFormatException.
extensions #
DateTime extension methods #
-
bool belongsTo(DateTimeRange dateTimeRange)This method returns whether this date belongs to the
dateTimeRangedate range (including extremes) or not (dateTimeRange.start⩽ this ⩽dateTimeRange.end). -
bool isAfterOrAtSameMomentAs(DateTime other)This method returns if this date is after or at the same moment as
otherdate (this ⩾other). -
bool isBeforeOrAtSameMomentAs(DateTime other)This method returns if this date is before or at the same moment as
otherdate (this ⩽other). -
bool isBetween({required DateTime start, required DateTime end})This method returns if this date is between
startdate andenddate, excluding the extremes (start< this <end). -
bool isBetweenOrAtSameMomentAs({required DateTime start, required DateTime end})This method returns whether this date is between
startandenddates, or at the same moment asstartdate orenddate (that is, extremes are included:start⩽ this ⩽end).This method might look like a duplicate of
belongsTo()method, but whilebelongsTo()takes aDateTimeRangeinto account, this refers to twoDateTime. -
int get thisMonthLastDayThis getter method returns the number of the last day of the month of this date.
-
String toStringE({bool firstUpperCase = false, String? locale})This method returns the localized string representation of this date with:
- the short name of the day of the week
of this date. Location is determined by
locale. In order to ensure that the first letter of the string is uppercase, assigntruetofirstUpperCase. -
String toStringEEEE({bool firstUpperCase = false, String? locale})This method returns the localized string representation of this date with:
- the full name of the day of the week
of this date. Location is determined by
locale. In order to ensure that the first letter of the string is uppercase, assigntruetofirstUpperCase. -
String toStringHm({String? locale})This method returns the localized string representation of:
- the time of this date in the “hh:mm” format.
Location is determined by
locale. -
String toStringMMM({bool firstUpperCase = false, String? locale})This method returns the localized string representation of this date with:
- the short name of the month
of this date. Location is determined by
locale. In order to ensure that the first letter of the string is uppercase, assigntruetofirstUpperCase. -
String toStringMMMM({bool firstUpperCase = false, String? locale})This method returns the localized string representation of this date with:
- the full name of the month
of this date. Location is determined by
locale. In order to ensure that the first letter of the string is uppercase, assigntruetofirstUpperCase. -
String toStringyMMd()This method returns:
- this date in the “yyyy-mm-dd” format.
-
String toStringyMMM({bool firstUpperCase = false, String? locale})This method returns the localized string representation of this date with:
- the year and
- the short name of the month
of this date. Location is determined by
locale. In order to ensure that the first letter of the string is uppercase, assigntruetofirstUpperCase. -
String toStringyMMMd({bool firstUpperCase = false, String? locale})This method returns the localized string representation of this date with:
- the year,
- the short name of the month and
- the day number
of this date. Location is determined by
locale. In order to ensure that the first letter of the string is uppercase, assigntruetofirstUpperCase(in this case, it is ensured by referencing the first occurrence in the string of the following regular expression:'([a-zA-z])'). -
String toStringyMMMEd({bool firstsUpperCase = false, String? locale})This method returns the localized string representation of this date with:
- the year,
- the short name of the month,
- the short name of the day and
- the day number
of this date. Location is determined by
locale. In order to ensure that the first letters of the string is uppercase, assigntruetofirstsUpperCase(in this case, it is ensured by referencing the first occurrences in the string of the following regular expressions:'([a-zA-z])'andr'(\s[a-zA-Z])'). -
String toStringyMMMM({bool firstUpperCase = false, String? locale})This method returns the localized string representation of this date with:
- the year and
- the full name of the month
of this date. Location is determined by
locale. In order to ensure that the first letter of the string is uppercase, assigntruetofirstUpperCase(in this case, it is ensured by referencing the first occurrence in the string of the following regular expression:'([a-zA-z])').
DateTimeRange extension methods #
-
bool belongsTo(DateTimeRange other)This method returns if this date range belongs to the
otherdate range, that is, it is completely included in it (other.start⩽start⩽other.end, andother.start⩽end⩽other.end). -
bool overlapsWith(DateTimeRange other)This method returns if this date range overlaps, in part or completely, with the
otherdate range.
double extension methods #
-
String toStringWithThousandsSeparator({int? decimals, String? locale, int maxDecimals = 1})This method returns the matching string of this number, with the thousands separator, which depends on
locale.decimalsindicates exactly how many decimals the representation of this number will have, regardless of how many decimals this number has. Ifdecimalsis specified,maxDecimalsis ignored.maxDecimalsindicates the maximum number of decimals that this representation will have. In the event that this representation would end with non-significant zeros, the latter would be eliminated, and this representation will contain only the significant decimal places.
int extension methods #
-
String toStringWithThousandsSeparator({String? locale})This method returns the matching string of this number, with the thousands separator, which depends on
locale.
List<T extends Comparable<T>> extension methods #
-
List<T> distinctSort()This method returns this list sorted and without repetitions.
List<DateTimeRange> extension methods #
-
Duration get durationThis method returns the sum of the duration of all intervals in this list after eliminating all duplicate intervals (which overlap some interval already present in this list).
To eliminate duplicate ranges this method uses the
minimize()method. -
List<DateTimeRange> minimize()This method returns a list of date ranges that covers the entirety of the period of the sum of all date ranges in this list, but without repeating any overlap.
List<T extends num> extension methods #
-
List<T> progressiveSum()This method returns a list of numbers, where each one is equal to the sum of the elements of this list up to that point.
-
T sum(T initialValue)This method returns the sum of all numbers in the list starting from the
initialValue.
String extension methods #
-
String firstsUpperCase({String splitPattern = ' ', bool trim = true})This method returns this same string, but with the first alphabetic character of all substrings determined by the
splitPatternin uppercase. If this string is empty, an empty string is returned.The default
splitPatternis given by the space string (' ').Before capitalizing all the first few characters, the leading and trailing whitespaces of this string are eliminated. To change this behavior just assign
falseto thetrimparameter. -
String firstUpperCase({bool trim = true})This method returns this same string, but with the first alphabetic character uppercase. If this string is empty, an empty string is returned.
Before making the first character uppercase, the leading and trailing whitespaces of this string are eliminated. To change this behavior just assign
falseto thetrimparameter.
TimeOfDay extension methods #
-
bool isAfter(TimeOfDay other)Returns if this time is after the
other(this >other). -
bool isBefore(TimeOfDay other)Returns if this time is before the
other(this >other). -
String toStringHm({String? locale})Returns the localized string representation of this time with:
- the
hours and - and the
minutes.
Location is determined by
locale. - the
Read this documentation in pages.docs.