forked from react-component/upload
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request react-component#101 from react-component/fix-attr-…
…accept make attr-accept inline
- Loading branch information
Showing
4 changed files
with
74 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
function endsWith(str, suffix) { | ||
return str.indexOf(suffix, str.length - suffix.length) !== -1; | ||
} | ||
|
||
export default (file, acceptedFiles) => { | ||
if (file && acceptedFiles) { | ||
const acceptedFilesArray = Array.isArray(acceptedFiles) | ||
? acceptedFiles | ||
: acceptedFiles.split(','); | ||
const fileName = file.name || ''; | ||
const mimeType = file.type || ''; | ||
const baseMimeType = mimeType.replace(/\/.*$/, ''); | ||
|
||
return acceptedFilesArray.some(type => { | ||
const validType = type.trim(); | ||
if (validType.charAt(0) === '.') { | ||
return endsWith(fileName.toLowerCase(), validType.toLowerCase()); | ||
} else if (/\/\*$/.test(validType)) { | ||
// This is something like a image/* mime type | ||
return baseMimeType === validType.replace(/\/.*$/, ''); | ||
} | ||
return mimeType === validType; | ||
}); | ||
} | ||
return true; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters