All files / src/helpers extMatchesStr.js

100% Statements 1/1
100% Branches 0/0
100% Functions 0/0
100% Lines 1/1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20                                104x      
import {extname} from '../utils/path'
 
/**
 * Test whether a file name has the given extension
 *
 * @function extMatchesStr
 * @param {String} filePath Input file path
 * @param {String} extension The extension to test. An empty string will match a file with no extension.
 * @returns {Boolean} Whether it matched or not.
 *
 * @example
 * var matches = io.extMatchesStr('path/to/data.tsv', 'tsv')
 * console.log(matches) // `true`
 */
export default function extMatchesStr (filePath, extension) {
  // Chop '.' off extension returned by extname
  var ext = extname(filePath).slice(1)
  return ext === extension
}