generateKeyword function
Generates a keyword from the given value
.
The generated keyword is based on the value
and can be customized using optional parameters.
Optional Parameters:
splitCamelCase
: Whether to split camel case words in the generated keyword. Default istrue
.removeWordSplitters
: Whether to remove word splitters in the generated keyword. Default istrue
.removeDiacritics
: Whether to remove diacritics in the generated keyword. Default istrue
.forceLowerCase
: Whether to force the generated keyword to be in lowercase. Default istrue
.
Returns the generated keyword as a String.
Implementation
String generateKeyword(
dynamic value, {
bool splitCamelCase = true,
bool removeWordSplitters = true,
bool removeDiacritics = true,
bool forceLowerCase = true,
}) {
if (value == null) return "";
if (value is DateTime) value = value.format();
if (value is Map) value = value.values.join(", ");
if (value is Iterable) value = value.join(", ");
String keyword = value.toString();
if (splitCamelCase) {
keyword = keyword.camelSplitString;
}
if (removeWordSplitters) {
keyword = keyword.removeWordSplitters;
}
if (removeDiacritics) {
keyword = keyword.removeDiacritics;
}
if (forceLowerCase) {
keyword = keyword.toLowerCase();
}
return keyword;
}