attr-accept
Advanced tools
Comparing version
{ | ||
"name": "attr-accept", | ||
"description": "JavaScript implementation of the \"accept\" attribute for HTML5 <input type=\"file\">", | ||
"version": "2.2.2", | ||
"version": "2.2.3", | ||
"main": "dist/index.js", | ||
@@ -6,0 +6,0 @@ "module": "dist/es/index.js", |
# attr-accept | ||
JavaScript implementation of the "accept" attribute for HTML5 `<input type="file">` | ||
> JavaScript implementation of the "accept" attribute for HTML5 `<input type="file">` | ||
 | ||
[](https://badge.fury.io/js/attr-accept) | ||
[](https://github.com/semantic-release/semantic-release) | ||
[](https://www.npmjs.com/package/attr-accept) | ||
 | ||
See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/file#accept for more information. | ||
See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/file#attr-accept for more information. | ||
Installation | ||
===== | ||
## Installation | ||
```sh | ||
@@ -16,4 +14,3 @@ npm install --save attr-accept | ||
Usage | ||
===== | ||
## Usage | ||
```javascript | ||
@@ -49,1 +46,5 @@ var accept = require('attr-accept'); | ||
``` | ||
## Contributing | ||
Checkout the organization [CONTRIBUTING.md](https://github.com/react-dropzone/.github/blob/main/CONTRIBUTING.md). |
@@ -8,3 +8,3 @@ /** | ||
* @param file {File} https://developer.mozilla.org/en-US/docs/Web/API/File | ||
* @param acceptedFiles {string} | ||
* @param acceptedFiles {string|string[]} | ||
* @returns {boolean} | ||
@@ -18,2 +18,5 @@ */ | ||
: acceptedFiles.split(',') | ||
if (acceptedFilesArray.length === 0) { | ||
return true | ||
} | ||
const fileName = file.name || '' | ||
@@ -20,0 +23,0 @@ const mimeType = (file.type || '').toLowerCase() |
@@ -310,2 +310,23 @@ /* eslint no-unused-expressions: 0 */ | ||
}) | ||
it('should allow any file if the accepted files is an empty array or string', () => { | ||
expect( | ||
accept( | ||
{ | ||
name: 'testfile.jpg', | ||
type: 'img/jpeg' | ||
}, | ||
'' | ||
) | ||
).toBe(true) | ||
expect( | ||
accept( | ||
{ | ||
name: 'testfile.pdf', | ||
type: 'random/type' | ||
}, | ||
[] | ||
) | ||
).toBe(true) | ||
}) | ||
}) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
375
0.81%49
2.08%16755
-7.61%12
-14.29%