Skip to content

Commit

Permalink
Fixed styling
Browse files Browse the repository at this point in the history
  • Loading branch information
Fatih Aydın committed Jan 19, 2023
1 parent 5acdf24 commit 1548f90
Show file tree
Hide file tree
Showing 4 changed files with 307 additions and 105 deletions.
9 changes: 6 additions & 3 deletions example/enum_plus_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ void main() {
print(Animal.values.getNamesExcept([0, Animal.HONEY_BEE])); // [CAT]

print(Animal.values.getFriendlyNames()); // [Dog, Cat, Honey Bee]
print(Animal.values.getFriendlyNames(values: [0, Animal.HONEY_BEE])); // [Dog, Honey Bee]
print(Animal.values
.getFriendlyNames(values: [0, Animal.HONEY_BEE])); // [Dog, Honey Bee]
print(Animal.values.getFriendlyNamesExcept([Animal.DOG, 1])); // [Honey Bee]

print(Animal.values.fromName('DOG')); // Animal.DOG
Expand All @@ -56,8 +57,10 @@ void main() {

print(Animal.values.fromNames(['DOG', 'CAT'])); // [Animal.DOG, Animal.CAT]
print(Animal.values.fromNames(['CAT', 'FISH'])); // Bad state: No element
print(Animal.values.fromFriendlyNames(['Honey Bee', 'Cat'])); // [Animal.HONEY_BEE, Animal.CAT]
print(Animal.values.fromFriendlyNames(['Honey Bee', 'Fish'])); // Bad state: No element
print(Animal.values.fromFriendlyNames(
['Honey Bee', 'Cat'])); // [Animal.HONEY_BEE, Animal.CAT]
print(Animal.values
.fromFriendlyNames(['Honey Bee', 'Fish'])); // Bad state: No element

print(Animal.values.hasValue(1)); // true
print(Animal.values.hasValue(Animal.CAT)); // true
Expand Down
8 changes: 6 additions & 2 deletions lib/src/enum_plus_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ mixin EnumPlus implements Enum {

/// Transform the name into a friendly, formatted version.
String getFriendlyName() {
return name.split(RegExp(r'(?<=[a-z])(?=[A-Z])|(?<=[A-Z])(?=[A-Z][a-z])|(_)|(?=[0-9])')).map((word) {
return name
.split(RegExp(
r'(?<=[a-z])(?=[A-Z])|(?<=[A-Z])(?=[A-Z][a-z])|(_)|(?=[0-9])'))
.map((word) {
var tempWord = word.toLowerCase();
return tempWord.replaceFirst(tempWord[0], tempWord[0].toUpperCase());
}).join(' ');
Expand Down Expand Up @@ -175,7 +178,8 @@ extension EnumPlusListExtension<T extends EnumPlus> on Iterable<T> {
return fromValue(enumNameOrValue);
}

if (hasName(enumNameOrValue.toString()) && enumNameOrValue.runtimeType == String) {
if (hasName(enumNameOrValue.toString()) &&
enumNameOrValue.runtimeType == String) {
return fromName(enumNameOrValue);
}

Expand Down
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: enum_plus
description: Simple, extensible and powerful enumeration implementation
version: 1.0.0+1
description: Simple, extensible and powerful enumeration implementation for dart and flutter
version: 1.0.0+2
homepage: https://github.com/aydinfatih/enum_plus
repository: https://github.com/aydinfatih/enum_plus

Expand Down
Loading

0 comments on commit 1548f90

Please sign in to comment.