getTokensOfType function

Map<String, dynamic> getTokensOfType(
  1. String type, {
  2. required Map<String, dynamic> tokenSetData,
  3. Map<String, dynamic>? fallbackSetData,
})

Returns a map of all tokens for a specific type.

When fallbackSetData is set tokenSetData gets merged and overridden with the provided map.

Implementation

Map<String, dynamic> getTokensOfType(
  String type, {
  required Map<String, dynamic> tokenSetData,
  Map<String, dynamic>? fallbackSetData,
}) {
  final tokens = Map.fromEntries(
    tokenSetData.entries.where((element) => hasNestedType(element, type: type)),
  );

  if (fallbackSetData != null) {
    final fallbackTokens = Map.fromEntries(
      fallbackSetData.entries
          .where((element) => hasNestedType(element, type: type)),
    );

    return overrideAndMergeTokenSet(fallbackTokens, withSet: tokens);
  }

  return tokens;
}