Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
10 changes: 8 additions & 2 deletions lib/src/case/case.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
2 changes: 2 additions & 0 deletions test/case/case_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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(), "");
Expand Down
Loading