From 66260177829f99c48594dd1fdedaefbb91bdce39 Mon Sep 17 00:00:00 2001 From: Noah Halstead Date: Tue, 2 Mar 2021 19:43:34 -0500 Subject: [PATCH 1/8] docs: fix link to accept attribute details --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c5a8870..e22b4b3 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ JavaScript implementation of the "accept" attribute for HTML5 `` +> JavaScript implementation of the "accept" attribute for HTML5 `` -![](https://github.com/react-dropzone/attr-accept/workflows/Test/badge.svg) -[![npm version](https://badge.fury.io/js/attr-accept.svg)](https://badge.fury.io/js/attr-accept) -[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release) +[![npm](https://img.shields.io/npm/v/attr-accept.svg?style=flat-square)](https://www.npmjs.com/package/attr-accept) +![Tests](https://img.shields.io/github/actions/workflow/status/react-dropzone/attr-accept/test.yml?branch=master&style=flat-square&label=tests) See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/file#attr-accept for more information. -Installation -===== +## Installation ```sh npm install --save attr-accept ``` -Usage -===== +## Usage ```javascript var accept = require('attr-accept'); accept({ From 21024c6611abfbe06ba76db66ba9c1186e312588 Mon Sep 17 00:00:00 2001 From: Roland Groza Date: Tue, 8 Oct 2024 20:21:36 +0300 Subject: [PATCH 3/8] docs: add link to contributing doc and close #20 --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index c60c485..04f9623 100644 --- a/README.md +++ b/README.md @@ -42,3 +42,7 @@ accept({ type: 'application/json' }, ['application/json', 'video/*']) // => true ``` + +## Contributing + +Checkout the organization [CONTRIBUTING.md](https://github.com/react-dropzone/.github/blob/main/CONTRIBUTING.md). From fcfe66f1a003039ac50c87632d0f5895450a9080 Mon Sep 17 00:00:00 2001 From: Roland Groza Date: Tue, 8 Oct 2024 20:29:56 +0300 Subject: [PATCH 4/8] ci: add coverage reporter --- .github/workflows/test.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b9c8312..5135dee 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -23,3 +23,12 @@ jobs: run: npm ci - name: Test run: npm test + + coverage: + needs: test + runs-on: ubuntu-latest + steps: + - uses: coverallsapp/github-action@v2.3.0 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + parallel-finished: true From 4e7d61714d7c5734496d229a09d46bbba66d98be Mon Sep 17 00:00:00 2001 From: Roland Groza Date: Tue, 8 Oct 2024 20:33:38 +0300 Subject: [PATCH 5/8] ci: update release workflow node version --- .github/workflows/release.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index d12b83b..b4c91ec 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -10,9 +10,9 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@master - - uses: actions/setup-node@v1 + - uses: actions/setup-node@v4 with: - node-version: "12.x" + node-version: "20.x" - run: npm ci - run: npx semantic-release env: From df08e9ac5e4e2d27b0f235ec2f6e6431b8c62276 Mon Sep 17 00:00:00 2001 From: Roland Groza Date: Tue, 8 Oct 2024 20:39:33 +0300 Subject: [PATCH 6/8] ci: bump actions versions --- .github/workflows/release.yml | 2 +- .github/workflows/test.yml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index b4c91ec..2b22e05 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -9,7 +9,7 @@ jobs: name: release runs-on: ubuntu-latest steps: - - uses: actions/checkout@master + - uses: actions/checkout@v4 - uses: actions/setup-node@v4 with: node-version: "20.x" diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 5135dee..03542eb 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -14,9 +14,9 @@ jobs: node_version: [8, 10, 12] steps: - - uses: actions/checkout@master + - uses: actions/checkout@v4 - name: Use Node.js ${{ matrix.node_version }} - uses: actions/setup-node@v1 + uses: actions/setup-node@v4 with: node-version: ${{ matrix.node_version }} - name: Install From b10f70cdb8e7906df923bfe77178c595915834ea Mon Sep 17 00:00:00 2001 From: Roland Groza Date: Wed, 9 Oct 2024 20:07:25 +0300 Subject: [PATCH 7/8] fix: allow any file if accepted files is an empty array and close #38 --- src/index.js | 3 +++ test/index.js | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/index.js b/src/index.js index a6357ad..305b6dc 100644 --- a/src/index.js +++ b/src/index.js @@ -14,6 +14,9 @@ export default function(file, acceptedFiles) { const acceptedFilesArray = Array.isArray(acceptedFiles) ? acceptedFiles : acceptedFiles.split(',') + if (acceptedFilesArray.length === 0) { + return true + } const fileName = file.name || '' const mimeType = (file.type || '').toLowerCase() const baseMimeType = mimeType.replace(/\/.*$/, '') diff --git a/test/index.js b/test/index.js index 53afede..2ee3bc3 100644 --- a/test/index.js +++ b/test/index.js @@ -307,4 +307,25 @@ describe('accept', () => { ) ).toBe(true) }) + + 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) + }) }) From 42d90f3853cc2a06d924b2bb482eeccc52ba7e55 Mon Sep 17 00:00:00 2001 From: Roland Groza Date: Wed, 9 Oct 2024 20:08:37 +0300 Subject: [PATCH 8/8] docs: fix acceptedFiles arg type --- src/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 305b6dc..4a9917b 100644 --- a/src/index.js +++ b/src/index.js @@ -5,7 +5,7 @@ * Inspired by https://github.com/enyo/dropzone * * @param file {File} https://developer.mozilla.org/en-US/docs/Web/API/File - * @param acceptedFiles {string} + * @param acceptedFiles {string|string[]} * @returns {boolean} */