react-dropzone
Advanced tools
Comparing version 10.2.0 to 10.2.1
@@ -605,3 +605,3 @@ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); } | ||
files.forEach(function (file) { | ||
if (fileAccepted(file, accept) && fileMatchSize(file, maxSize, minSize)) { | ||
if (fileAccepted(file, accept) && fileMatchSize(file, minSize, maxSize)) { | ||
acceptedFiles.push(file); | ||
@@ -715,3 +715,3 @@ } else { | ||
var isMultipleAllowed = multiple || fileCount <= 1; | ||
var isDragAccept = fileCount > 0 && allFilesAccepted(draggedFiles, accept, maxSize, minSize); | ||
var isDragAccept = fileCount > 0 && allFilesAccepted(draggedFiles, accept, minSize, maxSize); | ||
var isDragReject = fileCount > 0 && (!isDragAccept || !isMultipleAllowed); | ||
@@ -718,0 +718,0 @@ return _objectSpread({}, state, { |
@@ -9,8 +9,17 @@ function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } | ||
} | ||
export function fileMatchSize(file, maxSize, minSize) { | ||
return file.size <= maxSize && file.size >= minSize; | ||
export function fileMatchSize(file, minSize, maxSize) { | ||
if (isDefined(file.size)) { | ||
if (isDefined(minSize) && isDefined(maxSize)) return file.size >= minSize && file.size <= maxSize;else if (isDefined(minSize)) return file.size >= minSize;else if (isDefined(maxSize)) return file.size <= maxSize; | ||
} | ||
return true; | ||
} | ||
export function allFilesAccepted(files, accept, maxSize, minSize) { | ||
function isDefined(value) { | ||
return value !== undefined && value !== null; | ||
} | ||
export function allFilesAccepted(files, accept, minSize, maxSize) { | ||
return files.every(function (file) { | ||
return fileAccepted(file, accept) && fileMatchSize(file, maxSize, minSize); | ||
return fileAccepted(file, accept) && fileMatchSize(file, minSize, maxSize); | ||
}); | ||
@@ -17,0 +26,0 @@ } // React's synthetic events has event.isPropagationStopped, |
@@ -168,3 +168,3 @@ { | ||
}, | ||
"version": "10.2.0", | ||
"version": "10.2.1", | ||
"engines": { | ||
@@ -171,0 +171,0 @@ "node": ">= 8" |
@@ -584,3 +584,3 @@ /* eslint prefer-template: 0 */ | ||
files.forEach(file => { | ||
if (fileAccepted(file, accept) && fileMatchSize(file, maxSize, minSize)) { | ||
if (fileAccepted(file, accept) && fileMatchSize(file, minSize, maxSize)) { | ||
acceptedFiles.push(file) | ||
@@ -716,3 +716,3 @@ } else { | ||
const isMultipleAllowed = multiple || fileCount <= 1 | ||
const isDragAccept = fileCount > 0 && allFilesAccepted(draggedFiles, accept, maxSize, minSize) | ||
const isDragAccept = fileCount > 0 && allFilesAccepted(draggedFiles, accept, minSize, maxSize) | ||
const isDragReject = fileCount > 0 && (!isDragAccept || !isMultipleAllowed) | ||
@@ -719,0 +719,0 @@ |
@@ -9,9 +9,21 @@ import accepts from 'attr-accept' | ||
export function fileMatchSize(file, maxSize, minSize) { | ||
return file.size <= maxSize && file.size >= minSize | ||
export function fileMatchSize(file, minSize, maxSize) { | ||
if (isDefined(file.size)) { | ||
if (isDefined(minSize) && isDefined(maxSize)) | ||
return file.size >= minSize && file.size <= maxSize | ||
else if (isDefined(minSize)) | ||
return file.size >= minSize | ||
else if (isDefined(maxSize)) | ||
return file.size <= maxSize | ||
} | ||
return true | ||
} | ||
export function allFilesAccepted(files, accept, maxSize, minSize) { | ||
function isDefined(value) { | ||
return value !== undefined && value !== null | ||
} | ||
export function allFilesAccepted(files, accept, minSize, maxSize) { | ||
return files.every(file => { | ||
return fileAccepted(file, accept) && fileMatchSize(file, maxSize, minSize) | ||
return fileAccepted(file, accept) && fileMatchSize(file, minSize, maxSize) | ||
}) | ||
@@ -18,0 +30,0 @@ } |
@@ -5,2 +5,40 @@ beforeEach(() => { | ||
describe('fileMatchSize()', () => { | ||
let utils | ||
beforeEach(async done => { | ||
utils = await import('./index') | ||
done() | ||
}) | ||
it('should return true if the file object doesn\'t have a {size} property', () => { | ||
expect(utils.fileMatchSize({})).toBe(true) | ||
expect(utils.fileMatchSize({size: null})).toBe(true) | ||
}) | ||
it('should return true if the minSize and maxSize were not provided', () => { | ||
expect(utils.fileMatchSize({size: 100})).toBe(true) | ||
expect(utils.fileMatchSize({size: 100}, undefined, undefined)).toBe(true) | ||
expect(utils.fileMatchSize({size: 100}, null, null)).toBe(true) | ||
}) | ||
it('should return true if the file {size} is within the [minSize, maxSize] range', () => { | ||
expect(utils.fileMatchSize({size: 100}, 10, 200)).toBe(true) | ||
expect(utils.fileMatchSize({size: 100}, 10, 99)).toBe(false) | ||
expect(utils.fileMatchSize({size: 100}, 101, 200)).toBe(false) | ||
}) | ||
it('should return true if the file {size} is more than minSize', () => { | ||
expect(utils.fileMatchSize({size: 100}, 100)).toBe(true) | ||
expect(utils.fileMatchSize({size: 100}, 101)).toBe(false) | ||
}) | ||
it('should return true if the file {size} is less than maxSize', () => { | ||
expect(utils.fileMatchSize({size: 100}, undefined, 100)).toBe(true) | ||
expect(utils.fileMatchSize({size: 100}, null, 100)).toBe(true) | ||
expect(utils.fileMatchSize({size: 100}, undefined, 99)).toBe(false) | ||
expect(utils.fileMatchSize({size: 100}, null, 99)).toBe(false) | ||
}) | ||
}) | ||
describe('isIeOrEdge', () => { | ||
@@ -7,0 +45,0 @@ let utils |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
312004
4893
0