martijnversluis/ChordSheetJS

View on GitHub
script/build_chord_suffix_normalize_mapping.ts

Summary

Maintainability
A
0 mins
Test Coverage
import { EOL } from 'os';

interface BuildOptions {
  force: boolean;
  release: boolean;
}

export default function buildChordSuffixNormalizeMapping(_: BuildOptions, data: string): string {
  const suffixes = data
    .split(EOL)
    .map((line) => {
      const variants = line.split(/,\s*/);
      return variants.reduce((acc, variant) => ({ ...acc, [variant]: variants[0] }), {});
    })
    .reduce((acc, set) => ({ ...acc, ...set }), {});

  const json = JSON.stringify(suffixes, null, 2);
  return `const mapping: Record<string, string> = ${json};${EOL}${EOL}export default mapping;`;
}