mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-14 15:07:33 +08:00
30 lines
782 B
JavaScript
30 lines
782 B
JavaScript
import { isString } from './common.js';
|
|
|
|
export function getFileExtension(filename) {
|
|
if (!filename || !isString(filename)) {
|
|
return '';
|
|
}
|
|
|
|
const parts = filename.split('.');
|
|
return parts[parts.length - 1];
|
|
}
|
|
|
|
export function isFileExtensionSupported(filename, supportedExtensions) {
|
|
if (!supportedExtensions) {
|
|
return false;
|
|
}
|
|
|
|
const supportedExtensionsArray = supportedExtensions.split(',');
|
|
const fileExtension = getFileExtension(filename).toLowerCase();
|
|
|
|
for (let i = 0; i < supportedExtensionsArray.length; i++) {
|
|
const supportedExtension = getFileExtension(supportedExtensionsArray[i]).toLowerCase();
|
|
|
|
if (supportedExtension === fileExtension) {
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|