All files / src/shared/lib/helpers filePaths.ts

100% Statements 16/16
88.88% Branches 8/9
100% Functions 3/3
100% Lines 13/13

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 392x   2x         56x       56x       56x 9x     47x     2x           19x       19x 19x     2x 33x  
import stripInvalidFilenameCharacters from "./stripInvalidFilenameCharacters";
 
export const getROMFileStem = (
  overrideName: string,
  projectName: string,
): string => {
  const source =
    stripInvalidFilenameCharacters(overrideName).trim().length > 0
      ? overrideName
      : kebabCase(projectName.trim());
 
  const stem = stripInvalidFilenameCharacters(source)
    .replace(/(\.gb|\.gbc|\.pocket|\.gba)$/i, "")
    .trim();
 
  if (stem.replace(/-/g, "").length === 0) {
    return "game";
  }
 
  return stem;
};
 
export const getROMFilename = (
  overrideName: string,
  projectName: string,
  isColorOnly: boolean,
  buildType: "rom" | "pocket" | "web" | "gba",
): string => {
  const fileExt = buildType === "gba" ? "gba"
    : buildType === "pocket" ? "pocket" 
    : isColorOnly ? "gbc" 
    : "gb";
  const fileStem = getROMFileStem(overrideName, projectName);
  return `${fileStem}.${fileExt}`;
};
 
export const kebabCase = (string: string): string =>
  string.toLocaleLowerCase().replace(/[ ]+/g, "-");