File tree Expand file tree Collapse file tree 3 files changed +35
-3
lines changed Expand file tree Collapse file tree 3 files changed +35
-3
lines changed Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " svelte-file-dropzone" ,
3
- "version" : " 0.0.11 " ,
3
+ "version" : " 0.0.12-beta.0 " ,
4
4
"description" : " Svelte component for fileupload and file dropzone" ,
5
5
"svelte" : " src/index.js" ,
6
6
"module" : " dist/index.mjs" ,
18
18
"author" : " thecodejack" ,
19
19
"license" : " MIT" ,
20
20
"dependencies" : {
21
- "attr-accept" : " ^2.2.2" ,
22
21
"file-selector" : " ^0.2.2"
23
22
},
24
23
"devDependencies" : {
Original file line number Diff line number Diff line change
1
+ /**
2
+ * Check if the provided file type should be accepted by the input with accept attribute.
3
+ * https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Input#attr-accept
4
+ *
5
+ * Inspired by https://github.com/enyo/dropzone
6
+ *
7
+ * @param file {File} https://developer.mozilla.org/en-US/docs/Web/API/File
8
+ * @param acceptedFiles {string}
9
+ * @returns {boolean }
10
+ */
11
+
12
+ export default function ( file , acceptedFiles ) {
13
+ if ( file && acceptedFiles ) {
14
+ const acceptedFilesArray = Array . isArray ( acceptedFiles )
15
+ ? acceptedFiles
16
+ : acceptedFiles . split ( "," ) ;
17
+ const fileName = file . name || "" ;
18
+ const mimeType = ( file . type || "" ) . toLowerCase ( ) ;
19
+ const baseMimeType = mimeType . replace ( / \/ .* $ / , "" ) ;
20
+
21
+ return acceptedFilesArray . some ( ( type ) => {
22
+ const validType = type . trim ( ) . toLowerCase ( ) ;
23
+ if ( validType . charAt ( 0 ) === "." ) {
24
+ return fileName . toLowerCase ( ) . endsWith ( validType ) ;
25
+ } else if ( validType . endsWith ( "/*" ) ) {
26
+ // This is something like a image/* mime type
27
+ return baseMimeType === validType . replace ( / \/ .* $ / , "" ) ;
28
+ }
29
+ return mimeType === validType ;
30
+ } ) ;
31
+ }
32
+ return true ;
33
+ }
Original file line number Diff line number Diff line change 1
- import accepts from "attr-accept" ;
1
+ import accepts from "./ attr-accept" ;
2
2
3
3
// Error codes
4
4
export const FILE_INVALID_TYPE = "file-invalid-type" ;
You can’t perform that action at this time.
0 commit comments