findTokens method
Implementation
Map<String, Token> findTokens(
String parent,
Map<String, dynamic> input, [
String? groupType,
]) {
final tokens = <String, Token>{};
if (input.containsKey('value')) {
final cleaned =
parent.substring(0, parent.length - 1); // remove the trailing dot
final name = cleaned.split('.').last;
final end = cleaned.length - name.length - 1;
final path = end > 0 ? cleaned.substring(1, end) : '';
final token = Token(
value: input['value'],
type: input['type'] as String? ?? groupType,
path: path,
name: name,
extensions: input['\$extensions'] as Map<String, dynamic>?,
);
return {
[path, name].where((e) => e.isNotEmpty).join('.'): token,
};
}
for (var entry in input.entries) {
final key = entry.key;
final value = entry.value;
if (value is Map<String, dynamic>) {
tokens.addAll(
findTokens('$parent$key.', value, input['type'] as String?),
);
}
}
return tokens;
}