letIterableFromCsv function

Iterable<String> letIterableFromCsv(
  1. String input
)

Let's you convert input to an Iterable of Strings if possible, or returns null if the conversion cannot be performed.

The input string can be comma-separated, or it can be a JSON array.

Implementation

Iterable<String> letIterableFromCsv(String input) {
  var temp = input.trim();
  if (temp.isEmpty) return const [];
  if (temp.length > 1 &&
      ((temp.startsWith('[') && temp.endsWith(']')) ||
          (temp.startsWith('{') && temp.endsWith('}')) ||
          (temp.startsWith('(') && temp.endsWith(')')))) {
    temp = temp.substring(1, temp.length - 1);
  }
  return temp.split(',').map((final e) => e.trim());
}