index.js 811 B

1234567891011121314151617181920212223242526
  1. "use strict";
  2. exports.__esModule = true;
  3. exports.default = function (file, acceptedFiles) {
  4. if (file && acceptedFiles) {
  5. var acceptedFilesArray = Array.isArray(acceptedFiles) ? acceptedFiles : acceptedFiles.split(',');
  6. var fileName = file.name || '';
  7. var mimeType = (file.type || '').toLowerCase();
  8. var baseMimeType = mimeType.replace(/\/.*$/, '');
  9. return acceptedFilesArray.some(function (type) {
  10. var validType = type.trim().toLowerCase();
  11. if (validType.charAt(0) === '.') {
  12. return fileName.toLowerCase().endsWith(validType);
  13. } else if (validType.endsWith('/*')) {
  14. // This is something like a image/* mime type
  15. return baseMimeType === validType.replace(/\/.*$/, '');
  16. }
  17. return mimeType === validType;
  18. });
  19. }
  20. return true;
  21. };