toStringJson static method
Converts JSON to a string with optional transformations.
Implementation
static String? toStringJson(
dynamic json, {
bool trim = true,
bool makeUppercase = false,
bool makeLowercase = false,
bool makeCapitalized = false,
}) {
if (json == null) return null;
String? result = json is String ? json : json.toString();
if (trim) result = result.trim();
if (makeUppercase) {
result = result.toUpperCase();
} else if (makeLowercase) {
result = result.toLowerCase();
} else if (makeCapitalized) {
result = result
.split(' ')
.map((String w) {
if (w.isEmpty) return w;
return w[0].toUpperCase() + w.substringSafe(1).toLowerCase();
})
.join(' ');
}
return result.isEmpty ? null : result;
}