-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.dart
27 lines (24 loc) · 891 Bytes
/
utils.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import 'dart:io';
final String _dirname = Platform.script.toFilePath();
final String staticFolder = '${Uri.file(_dirname).resolve('../static')}';
/// Throws an error if any of the keys are missing from the object
/// @param obj - The object to check
/// @param keys - The list of keys to check for
/// @throws Exception
void throwIfMissing(Map<String, dynamic> obj, List<String> keys) {
final missing = <String>[];
for (var key in keys) {
if (!obj.containsKey(key) || obj[key] == null) {
missing.add(key);
}
}
if (missing.isNotEmpty) {
throw Exception('Missing required fields: ${missing.join(', ')}');
}
}
/// Returns the contents of a file in the static folder
/// @param fileName - The name of the file to read
/// @returns Contents of static/{fileName}
String getStaticFile(String fileName) {
return File('$staticFolder/$fileName').readAsStringSync();
}