parseNames static method

Map<String, dynamic> parseNames(
  1. String rawText
)

Implementation

static Map<String, dynamic> parseNames(String rawText) {
  rawText = rawText.trim();
  final parts = rawText.split(" ").where(notNullOrBlank());
  final data = <String, dynamic>{};
  final unhandled = parts.where((p) {
    if (p.contains("@")) {
      data["email"] = p.toLowerCase();
      return false;
    }

    if (isPhone(p)) {
      data["phone"] = p;
      return false;
    }

    return true;
  });

  final names = unhandled.map(capitalize);

  data["firstName"] = joinOrNull(chopList(names));
  data["lastName"] = Lists.lastOrNull(names);
  data["fullName"] = joinOrNull(names);
  return data;
}