splitBaseAndExt.js

  1. /**
  2. * Split the base and extension (including the ".") of a file path.
  3. * @param {*} filePath
  4. * @returns (array) [base, ext]
  5. */
  6. const splitBaseAndExt = (filePath) => {
  7. const pos = filePath.lastIndexOf('.');
  8. return [pos === -1 ? filePath : filePath.substring(0, pos), pos === -1 ? '' : filePath.substring(pos)];
  9. };
  10. export default splitBaseAndExt;