-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(casing): add variable name casing
- Loading branch information
1 parent
5af86fd
commit edcc78a
Showing
8 changed files
with
66 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
KEY1=VALUE1 | ||
KEY2=VALUE2 | ||
KEY2=VALUE2 | ||
TEST_KEY=TEST_VALUE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,4 +6,5 @@ void run() { | |
print(Env.key3); | ||
print(Env.key4); | ||
print(Env.key5); | ||
print(Env.testKey); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Helper functions related to strings | ||
|
||
/// Method to convert camelCases to snake_cases | ||
String camelCaseToSnakeCase(String input) { | ||
return input.replaceAllMapped( | ||
RegExp('([A-Z])|([0-9]+)'), | ||
(match) => '_${match.group(0)!.toLowerCase()}', | ||
); | ||
} | ||
|
||
/// Method that will returns | ||
/// [a] if [a] is not null or an empty string. Otherwise, | ||
/// [b] will be returned. | ||
String ifFalsy(String? a, String b) { | ||
return validate(a, (x) => (x ?? '').isNotEmpty) ? a! : b; | ||
} | ||
|
||
/// Method to normalize the [input] string to .ENV | ||
/// compatible keys. | ||
/// | ||
/// For example: | ||
/// `isStudent1` will have an output of `IS_STUDENT_1` | ||
String normalize(String input) { | ||
return camelCaseToSnakeCase(input).toUpperCase(); | ||
} | ||
|
||
/// Method to decide whether a [String] input | ||
/// returns `true` or `false` through the predicate function | ||
/// or not. | ||
bool validate(String? input, BoolFn predicate) { | ||
return predicate(input); | ||
} | ||
|
||
/// Type Definition: function with a [String] as a parameter | ||
/// returning a [bool] | ||
typedef BoolFn = bool Function(String?); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,12 @@ | ||
test_string=test_string | ||
testString=testString | ||
TEST_STRING=TEST_STRING | ||
testInt=123 | ||
TEST_INT=123 | ||
testDouble=1.23 | ||
TEST_DOUBLE=1.23 | ||
TEST_BOOL=true | ||
testBool=true | ||
testDynamic=123abc | ||
TEST_DYNAMIC=123abc | ||
SYSTEM_VAR=system_var |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters