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

100% Statements 16/16
100% Branches 7/7
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 372x   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)$/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 => {
  const fileExt =
    buildType === "pocket" ? "pocket" : isColorOnly ? "gbc" : "gb";
  const fileStem = getROMFileStem(overrideName, projectName);
  return `${fileStem}.${fileExt}`;
};
 
export const kebabCase = (string: string): string =>
  string.toLocaleLowerCase().replace(/[ ]+/g, "-");