diff --git a/example/pubspec.lock b/example/pubspec.lock index d6bbb38..aec392c 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -15,6 +15,6 @@ packages: path: ".." relative: true source: path - version: "1.2.1" + version: "1.2.2" sdks: dart: ">=3.4.0 <4.0.0" diff --git a/lib/src/case/case.dart b/lib/src/case/case.dart index 323822e..7f03221 100644 --- a/lib/src/case/case.dart +++ b/lib/src/case/case.dart @@ -15,7 +15,9 @@ extension Case on String { ? preserveAcronym ? (word.isUpperCase() ? word : word.toLowerCase()) : word.toLowerCase() - : word.capitalize(), + : word.isUpperCase() + ? word + : word.capitalize(), ) .toList() .join(); @@ -26,7 +28,11 @@ extension Case on String { /// uppercase. It is set to `false` by default String capitalize({bool capitalizeAll = false}) => switch (capitalizeAll) { true => toUpperCase(), - false => isEmpty ? '' : this[0].toUpperCase() + substring(1), + false => isEmpty + ? '' + : this[0] == this[0].toUpperCase() + ? this[0].toUpperCase() + substring(1).toLowerCase() + : this[0].toUpperCase() + substring(1), }; /// Decapitalizes the first character of the string diff --git a/pubspec.yaml b/pubspec.yaml index 2d8f88b..58a56bb 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: stringr description: Comprehensive string manipulation plugin for dart. Handles operations on latin, non latin and grapheme clusters alike! Features inspured from VocaJs -version: 1.2.1 +version: 1.2.2 homepage: https://github.com/Chinmay-KB/stringr environment: diff --git a/test/case/case_test.dart b/test/case/case_test.dart index 99c4f6a..4a17a6a 100644 --- a/test/case/case_test.dart +++ b/test/case/case_test.dart @@ -26,6 +26,8 @@ void main() { expect("excuse moi".capitalize(capitalizeAll: true), "EXCUSE MOI"); expect("".capitalize(), ""); expect("macBook".capitalize(), "MacBook"); + expect("HELLO".capitalize(), "Hello"); + expect("HeLLo".capitalize(), "Hello"); expect("яблоко".capitalize(), "Яблоко"); expect("420".capitalize(), "420"); expect("".capitalize(), "");