stringMap method
A mapping of text keys to scalar values, converted to text.
Implementation
Map<String, String>? stringMap(String key) {
final value = map[key];
if (value == null) {
return null;
}
if (value is! YamlMap) {
throw valueError(key, 'expected a mapping, found ${describe(value)}.');
}
final result = <String, String>{};
for (final MapEntry(key: entryKey, value: node) in value.nodes.entries) {
final name = (entryKey as YamlNode).value;
final entryValue = node.value;
if (name is! String) {
throw ConfigException(
'${keyPath(key)}: keys must be text.',
span: SourceSpanLike.of(entryKey),
file: file,
);
}
if (entryValue is String || entryValue is num || entryValue is bool) {
result[name] = entryValue.toString();
} else {
throw ConfigException(
'${keyPath(key)}.$name: expected text, found '
'${describe(entryValue)}.',
span: SourceSpanLike.of(node),
file: file,
);
}
}
return result;
}