# All files / src/_utils filename.ts

100% Statements 12/12
80% Branches 4/5
100% Functions 2/2
100% Lines 12/12

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
    2114x
    119x
    119x

    119x
    108x

    11x
    11x
    11x

    11x

    14x
    226x

    226x

     export function parseFilename(str: string) {
      const fileExt = getFileExtension(str)
      const isFilename = Boolean(fileExt)

      if (!isFilename) {
        return { filename: '', extension: '', isFilename }
      }

      const cutoff = fileExt ? str.length - fileExt.length : str.length
      const filename = str.substring(0, cutoff - 1)
      const extension = str.substring(cutoff)

      return { filename, extension, isFilename }
    }

    export function getFileExtension(filename: string) {
      const extPos = filename.lastIndexOf('.')

      return extPos < 0 ? '' : filename.substring(extPos + 1)
    }