All files / backend/src/utils content-formats.ts

71.42% Statements 5/7
14.28% Branches 1/7
50% Functions 1/2
83.33% Lines 5/6

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            2x                                                 25x 25x 25x 25x    
/**
 * Content Format Utilities
 *
 * Functions for identifying and validating content file types.
 */
 
export const SUPPORTED_CONTENT_EXTENSIONS = ['md', 'markdown', 'html', 'qmd'] as const;
 
export type ContentExtension = (typeof SUPPORTED_CONTENT_EXTENSIONS)[number];
 
/**
 * Check if a file path has a valid content file extension
 * @param filePath - Path to check
 * @returns True if the file has a supported content extension
 */
export function allValidContentFilesExt(filePath: string | undefined): boolean {
  return Boolean(
    filePath &&
      (filePath.endsWith('.md') ||
        filePath.endsWith('.markdown') ||
        filePath.endsWith('.qmd') ||
        filePath.endsWith('.html'))
  );
}
 
/**
 * Check if a file is a content file based on its extension
 * @param filePath - Path to check
 * @returns True if the file is a content file
 */
export function isContentFile(filePath: string | undefined): boolean {
  Iif (filePath === undefined) return false;
  const parts = filePath.split('.');
  const extension = parts[parts.length - 1];
  return SUPPORTED_CONTENT_EXTENSIONS.includes(extension as ContentExtension);
}