nmApplyRecordRepair function

String nmApplyRecordRepair(
  1. String raw,
  2. String operation, {
  3. Map<String, Object?> params = const {},
})

Pre-parse record repairs (transformations.json's record_repairs array) operate on the raw pre-parse record text, not a single extracted field's value — a separate pipeline stage from nmPreviewTransformation's per-field operations, per the schema-1.2 contract.

Implementation

String nmApplyRecordRepair(String raw, String operation, {Map<String, Object?> params = const {}}) {
  return switch (operation) {
    'repair_unquoted_thousands_separator' => raw.replaceAllMapped(
      RegExp('(\\d)${RegExp.escape(params['group_separator']?.toString() ?? ',')}(?=\\d)'),
      (m) => m.group(1)!,
    ),
    'normalize_line_endings' => raw.replaceAll('\r\n', '\n').replaceAll('\r', '\n'),
    'remove_bom' => raw.startsWith('') ? raw.substring(1) : raw,
    _ => throw FormatException('Unsupported record repair: $operation'),
  };
}