Pub Version GitHub Top Language Dart GitHub Actions

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 name property 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 an AuthProvider value. To comply with the convention, this enumeration also has this method. However, in this case, it’s just a call to the name property.

      final provider = AuthProvider...;
      provider.string() == provider.name; // true
    
  • With method toAuthProvider(), the String class has been extended to give it the ability to return the corresponding AuthProvider value. In case the string does not contain a valid representation of an AuthProvider value, this method returns a FormatException.


extensions

DateTime extension methods

  • bool belongsTo(DateTimeRange dateTimeRange)

    This method returns whether this date belongs to the dateTimeRange date 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 other date (this ⩾ other).

  • bool isBeforeOrAtSameMomentAs(DateTime other)

    This method returns if this date is before or at the same moment as other date (this ⩽ other).

  • bool isBetween({required DateTime start, required DateTime end})

    This method returns if this date is between start date and end date, excluding the extremes (start < this < end).

  • bool isBetweenOrAtSameMomentAs({required DateTime start, required DateTime end})

    This method returns whether this date is between start and end dates, or at the same moment as start date or end date (that is, extremes are included: start ⩽ this ⩽ end).

    This method might look like a duplicate of belongsTo() method, but while belongsTo() takes a DateTimeRange into account, this refers to two DateTime.

  • int get thisMonthLastDay

    This 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, assign true to firstUpperCase.

  • 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, assign true to firstUpperCase.

  • 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, assign true to firstUpperCase.

  • 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, assign true to firstUpperCase.

  • 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, assign true to firstUpperCase.

  • 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, assign true to firstUpperCase (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, assign true to firstsUpperCase (in this case, it is ensured by referencing the first occurrences in the string of the following regular expressions: '([a-zA-z])' and r'(\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, assign true to firstUpperCase (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 other date range, that is, it is completely included in it (other.startstartother.end, and other.startendother.end).

  • bool overlapsWith(DateTimeRange other)

    This method returns if this date range overlaps, in part or completely, with the other date 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.

    decimals indicates exactly how many decimals the representation of this number will have, regardless of how many decimals this number has. If decimals is specified, maxDecimals is ignored.

    maxDecimals indicates 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 duration

    This 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

  • List<String> allCurrenciesSymbols()

    This method returns the list of all currency symbols found in this string. If no currency symbol is encountered, an empty list is returned.

  • String firstCurrencySymbol()

    This method returns the first currency symbol found in this string. If no currency symbol is encountered, an empty string is returned.

  • 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 splitPattern in uppercase. If this string is empty, an empty string is returned.

    The default splitPattern is 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 false to the trim parameter.

  • 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 false to the trim parameter.

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.


Read this documentation in pages.docs.

Libraries

helpers_plethora