swarm/test/test_env.dart
randogoth 3cafc4456c move xfay app secret to .env
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-08 12:38:31 +03:00

18 lines
642 B
Dart

import 'dart:io';
/// Loads KEY=VALUE pairs from a `.env` file at the project root.
/// Lines starting with `#` and blank lines are ignored.
/// Returns an empty map if the file does not exist.
Map<String, String> loadEnv() {
final file = File('.env');
if (!file.existsSync()) return {};
final result = <String, String>{};
for (final line in file.readAsLinesSync()) {
final trimmed = line.trim();
if (trimmed.isEmpty || trimmed.startsWith('#')) continue;
final idx = trimmed.indexOf('=');
if (idx < 1) continue;
result[trimmed.substring(0, idx).trim()] = trimmed.substring(idx + 1).trim();
}
return result;
}