sharedPostProcess top-level property

List<FigSuggestion> Function(String, [List<String>?]) sharedPostProcess
final

共享的后处理函数

Implementation

final List<FigSuggestion> Function(String, [List<String>?]) sharedPostProcess =
    (String out, [List<String>? tokens]) {
  return out
      .split('\n')
      .where((line) => line.trim().isNotEmpty)
      .map<FigSuggestion?>((line) {
        try {
          final data = json.decode(line) as Map<String, dynamic>;
          final name =
              data['name']?.toString() ?? data['Name']?.toString() ?? '';
          final description =
              data['id']?.toString() ?? data['ID']?.toString() ?? '';

          if (name.isEmpty) return null;

          return FigSuggestion(
            name: name,
            description: description,
            icon: 'fig://icon?type=docker',
          );
        } catch (error) {
          print('Error parsing Docker data: $error');
          return null;
        }
      })
      .where((suggestion) => suggestion != null)
      .cast<FigSuggestion>()
      .toList();
};