feat(proj): init
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
/// Minimal `.env` parser (KEY=VALUE, `#` comments, optional quotes).
|
||||
///
|
||||
/// Kept tiny and dependency-free so config loading is easy to test and does
|
||||
/// not pull `flutter_dotenv` into the production graph.
|
||||
Map<String, String> parseEnvFile(String source) {
|
||||
final values = <String, String>{};
|
||||
|
||||
for (final raw in source.split(RegExp(r'\r?\n'))) {
|
||||
final line = raw.trim();
|
||||
if (line.isEmpty || line.startsWith('#')) continue;
|
||||
|
||||
final separator = line.indexOf('=');
|
||||
if (separator <= 0) continue;
|
||||
|
||||
final key = line.substring(0, separator).trim();
|
||||
if (key.isEmpty) continue;
|
||||
|
||||
var value = line.substring(separator + 1).trim();
|
||||
if (value.length >= 2) {
|
||||
final quote = value[0];
|
||||
if ((quote == '"' || quote == "'") && value.endsWith(quote)) {
|
||||
value = value.substring(1, value.length - 1);
|
||||
}
|
||||
}
|
||||
|
||||
values[key] = value;
|
||||
}
|
||||
|
||||
return values;
|
||||
}
|
||||
|
||||
String normalizeUrl(String url) => url.trim().replaceAll(RegExp(r'/$'), '');
|
||||
|
||||
bool parseEnvFlag(String? raw, {bool fallback = false}) {
|
||||
if (raw == null || raw.trim().isEmpty) return fallback;
|
||||
return switch (raw.trim().toLowerCase()) {
|
||||
'1' || 'true' || 'yes' || 'on' => true,
|
||||
'0' || 'false' || 'no' || 'off' => false,
|
||||
_ => fallback,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user