string_extensions 0.6.1
string_extensions: ^0.6.1 copied to clipboard
Useful String extensions to save you time in production. Feel free to contribute with PR.
0.6.1 New Extensions #
formatFileSize: Formats aStringrepresenting bytes to show the proper file size.
String foo = '24117248';
String formatted = foo.formatFileSize; // returns '23 MB'
0.6.0 Breaking Changes, New Extensions & Bug Fixes #
- Project depends on
crypto(3.0.2) due to newmd5method wich returns the MD5 hash of theString. - Bug fixes for various methods,
after,before,toTitleCase,openCloseWrappers,removeFirstAndLastAny. - Various improvements.
0.5.1 Bug fix #
- Fixes
titleCasenot trimming whitespaces.
0.5.0 Breaking Changes & New Extensions #
- All methods will now trim the
Stringbefore operations. toSnakeCase: Converts aStringto snake case format.
0.4.5 New extensions #
addAfter: Adds aStringafter the first occurence of a specific pattern.addBefore: Adds aStringbefore the first occurence of a specific pattern.
0.4.4 New Extensions #
-
removeAfter: Removes everything after the first occurence of a specific pattern. -
removeBefore: Removes everything before the first occurence of a specific pattern.
Thanks to zonaro
-
wrap: Wraps aStringbetween twoStrings. -
getOppositeChar: Returns the opposite wrap char of theString. -
isOpenWrapChar: Check ifStringis a open wrap char:<,{,[,",'. -
isCloseWrapChar: Checks ifStringis a close wrap char:>,},],",'. -
removeFirstAny: Continuously removes from the beginning of aStringanyStringcontained in [patterns]. -
removeLastAny: Continuously removes from the end of aStringanyStringcontained in [patterns]. -
removeFirstAndLastAny: Continuously removes from the beggining and end of aStringanyStringcontained in [patterns]. -
removeLastEqual: Remove aStringfrom the end of other string if equal [pattern]. -
removeFirstEqual: Remove aStringin the beginning of other string if equal [pattern]. -
removeFirstAndLastEqual: RemoveStringfrom the beginning and the end ofStringif equal [pattern]. -
containsAny: Check ifStringcontains anyStrings of [list]. -
containsAll: Check ifStringcontains allStrings of [list].
0.4.3 New Extensions #
Thanks to zonaro
-
isBlank: Checks if aStringisnullempty or contains only whitespaces. -
isNotBlank: Checks if aStringis NOTnullempty or contains only whitespaces. -
asIf: Compares aStringto another and returns the first if equal, otherwise returns the second one. -
ifBlank(String default): Checks if aStringis blank and gives it a default value.
0.4.2 Minor improvements & New Extensions #
- Returns the
Stringafter a character / word.
after(String pattern)
- Returns the
Stringbefore a character / word.
before(String pattern)
- Gets Jaro distance to check
Stringsimilarity. The higher the number the similar the twoStrings/
getJaro(String wordToCompare)
0.4.1 Minor improvements & New Extensions #
- Converts the
Stringto aboolvalue if possible.
tooBool
0.4.0 Breaking Changes & New Extensions #
Breaking changes #
Following extension methods are now created using get and can now being accessed without ().
- capitalize
- countWords
- removeNumbers
- onlyLatin
- onlyGreek
- isNull
- isIpv4
- isIpv6
- isUrl
- isDate
- isMail
- isNumber
- isStrongPassword
- isGuid
- isLatin
- isGreek
- onlyNumbers
- removeLetters
- charOccurences
- mostFrequent
- reverse
- toSlug
- toCamelCase
- toTitleCase
- toArray
- replaceGreek
- stripHtml
- hasSameCharacters
- shuffle
New Extensions
- Truncates
Stringwith "..." when more thanncharacters.
truncate(int maxChars)
- Truncates
Stringin the middle with "..." keeping maxncharacters.
truncateMiddle(int maxChars)
- Quotes a
Stringadding " at the start & at the end.
quote
- Trims leading and trailing spaces, so as extra spaces in between words.
trimAll
0.3.5 New Extensions #
- Returns the month name of the
DateTime(inStringformat).
getMonthFromDate(locale:'en')
- Returns the first day of the month from the provided
DateTime(inStringformat).
firstDayOfMonth(locale:'en')
- Returns the last day of the month from the provided
DateTime(inStringformat).
latsDayOfMonth(locale:'en')
- Returns left side of the
Stringstarting fromchar.
leftOf(String char)
- Returns right side of the
Stringstarting fromchar.
rightOf(String char)
0.3.4 New Extensions #
-
formatWithMasknow accepts optional parameterspecialCharwhich defaults to '#' -
Add a
Stringat the beginning of yourString.
prepend(String prefix)
- Adds
-operator subtracting a text from aString - Returns the day name of the
DateTime(inStringformat).
String date = '2021-10-23';
String day = date.getDayFromDate(); // returns 'Saturday'
String grDay = date.getDayFromDate(locale:'el'); // returns 'Σάββατο'
0.3.3 New Extensions #
- Removes the first
ncharacters of theString.
removeFirst(int n)
- Removes the last
ncharacters of theString.
removeLast(int n)
- Trims the
Stringto have exactlyncharacters. Ifnis larger than theStringlength, the sameStringis returned.
maxChars(int n)
- Reverses slash provided the slash direction (
int). 0 for / to \ and 1 for \ to /.
reverseSlash(int direction)
- Returns the character at
index.
charAt(int index)
- Checks if a string is
null.
isNull()
- Do something if a string is
null.
ifNull(Function())
- Provide default value if a string is
null.
defaultValue(String defaultValue)
- Append a
Stringat the end of yourString.
append(String suffix)
- Formats the
Stringto properly show currency amount.
toPriceFormat({String? currencySymbol})
0.3.2 Bug Fixes & New Extensions #
Bug fixes & New Extensions #
- Returns only the Greek characters of the
String.
onlyGreek()
- Checkes whether the
Stringhas only Latin characters.
isLatin()
- Checkes whether the
Stringhas only Greek characters.
isGreek()
onlyLetters()is nowonlyLatin()characters.- The
countWordsextension now correctly counts only words, excluding numbers and symbols from words. For example,Hello 5 2asd friend !word count will return 3 words.
0.3.1 New extensions #
-
Added
String?operators>, >=, <, <=to compareStringlengths. -
isIn(Iterable<String>), checks if a givenStringis in anIterable<String>. -
formatWithMask(String mask), formats aStringwith a specific mask.
0.3.0 New extensions & Code improvements #
Successfully converts library to extend String? from String.
Further code optimization and bug fixes.
New extensions
- Converts the
Stringto anumvalue if possible, else returnsnull.
toNum()
- Converts the
Stringtointif possible, else returnsnull.
toInt()
- Converts the
Stringtodoubleif possible, else returnsnull.
toDouble()
0.2.4 New extensions #
Improves and renames toStringArray (toArray now)
Adds a new extension that counts specific charater occurences in a String.
charCount(String char)
0.2.3 New extensions #
- Squeezes a
Stringto a character
squeeze(String x);
- Check if the
Stringis consisted of same characters.
hasSameCharacters();
- Shuffles the word's letters.
shuffle();
- Gets the Levenshtein distance of two
String
getLevenshtein();
- Checks if a
Stringis a validUrl.
isUrl();
- Checks if a
Stringis a validDate.
isDate();
0.2.2 New extensions #
- Repeats a
Stringx times
repeat(int x);
- Check if the
Stringis a valid Ipv6
isIpv6();
- Check if the
Stringis anum
isNumber();
- An extension that makes easier handling empty strings.
ifEmpty(()=>print('The string is empty'));
0.2.1 Downgrade test library version #
Some projects were breaking due to they depending on test_api:3.0.0 version.
0.2.0 Adds tests #
0.1.4 New extension #
Method to check whether a String is a valid Guid.
isGuid()
0.1.3 New extensions #
- Method to get a
List<String>from aString.
toStringArray()
- Method to strip all
HTMLcode from aString.
stripHtml()
- Method to check whether a
Stringis a strong password.
isStrongPassword()
0.1.2 New extensions & Code refactor #
-
Adds isEmpty checks on all extensions.
-
Given a
Stringand a pattern, finds the starting indices of all occurrences of the pattern in theString.findPattern({required String pattern})
0.1.1 New extensions #
Useful method to normalize greek text for more performant text searches.
replaceGreek()
0.1.0 New extensions #
first({int count})
last({int count})
toSlug()