camelCase property

String get camelCase

Chuyển đổi chuỗi sang định dạng camelCase. Ví dụ: "hello_world" -> "helloWorld", "MyAwesomeClass" -> "myAwesomeClass"

Implementation

String get camelCase {
  if (isEmpty) return this;

  // Chuyển đổi từ snake_case/kebab-case
  String result = replaceAllMapped(
    RegExp(r'[_-](.)'),
    (match) => match.group(1)!.toUpperCase(),
  );

  // Chuyển chữ cái đầu tiên thành thường nếu không phải là số/ký tự đặc biệt
  if (result.isNotEmpty &&
      result[0].toUpperCase() == result[0] &&
      !RegExp(r'[0-9]').hasMatch(result[0])) {
    return result[0].toLowerCase() + result.substring(1);
  }
  return result;
}