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

100% Statements 20/20
100% Branches 8/8
100% Functions 3/3
100% Lines 17/17

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 39 40 412x   2x         57x       57x       57x 9x     48x     2x           20x 20x 4x 16x 4x   20x 20x     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)$/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",
): string => {
  let fileExt = "gb";
  if (buildType === "pocket") {
    fileExt = "pocket";
  } else if (isColorOnly && !overrideName.endsWith(".gb")) {
    fileExt = "gbc";
  }
  const fileStem = getROMFileStem(overrideName, projectName);
  return `${fileStem}.${fileExt}`;
};
 
export const kebabCase = (string: string): string =>
  string.toLocaleLowerCase().replace(/[ ]+/g, "-");