filepond-plugin-image-validate-size
Advanced tools
Comparing version 1.0.0 to 1.0.1
/* | ||
* FilePondPluginImageValidateSize 1.0.0 | ||
* FilePondPluginImageValidateSize 1.0.1 | ||
* Licensed under MIT, https://opensource.org/licenses/MIT | ||
@@ -9,12 +9,37 @@ * Please visit https://pqina.nl/filepond for details. | ||
const getImageSize = file => | ||
new Promise((resolve, reject) => { | ||
const image = document.createElement('img'); | ||
image.src = URL.createObjectURL(file); | ||
const intervalId = setInterval(() => { | ||
if (image.naturalWidth && image.naturalHeight) { | ||
clearInterval(intervalId); | ||
URL.revokeObjectURL(image.src); | ||
resolve({ | ||
width: image.naturalWidth, | ||
height: image.naturalHeight | ||
}); | ||
} | ||
}, 1); | ||
}); | ||
var plugin$1 = ({ addFilter, utils }) => { | ||
// get quick reference to Type utils | ||
const { Type, replaceInString } = utils; | ||
const { Type, replaceInString, isFile } = utils; | ||
// required file size | ||
const validateFile = (file, size) => { | ||
// get image | ||
const validateFile = (file, { minWidth, minHeight, maxWidth, maxHeight }) => | ||
new Promise((resolve, reject) => { | ||
getImageSize(file).then(({ width, height }) => { | ||
// validation result | ||
if (width < minWidth || height < minHeight) { | ||
reject('TOO_SMALL'); | ||
} else if (width > maxWidth || height > maxHeight) { | ||
reject('TOO_BIG'); | ||
} | ||
return true; | ||
}; | ||
// all is well | ||
resolve(); | ||
}); | ||
}); | ||
@@ -28,3 +53,7 @@ // called for each file that is loaded | ||
new Promise((resolve, reject) => { | ||
if (!isImage(file) || !query('GET_ALLOW_IMAGE_VALIDATE_SIZE')) { | ||
if ( | ||
!isFile(file) || | ||
!isImage(file) || | ||
!query('GET_ALLOW_IMAGE_VALIDATE_SIZE') | ||
) { | ||
resolve(file); | ||
@@ -34,4 +63,4 @@ return; | ||
// required dimensions | ||
const size = { | ||
// get required dimensions | ||
const bounds = { | ||
minWidth: query('GET_IMAGE_VALIDATE_SIZE_MIN_WIDTH'), | ||
@@ -43,24 +72,29 @@ minHeight: query('GET_IMAGE_VALIDATE_SIZE_MIN_HEIGHT'), | ||
const labels = { | ||
tooSmall: query('GET_IMAGE_VALIDATE_SIZE_LABEL_IMAGE_SIZE_TOO_SMALL'), | ||
tooBig: query('GET_IMAGE_VALIDATE_SIZE_LABEL_IMAGE_SIZE_TOO_BIG'), | ||
minSize: query('GET_IMAGE_VALIDATE_SIZE_LABEL_EXPECTED_MIN_SIZE'), | ||
maxSize: query('GET_IMAGE_VALIDATE_SIZE_LABEL_EXPECTED_MAX_SIZE') | ||
validateFile(file, bounds) | ||
.then(() => { | ||
resolve(file); | ||
}) | ||
.catch(error => { | ||
const status = { | ||
TOO_SMALL: { | ||
label: query( | ||
'GET_IMAGE_VALIDATE_SIZE_LABEL_IMAGE_SIZE_TOO_SMALL' | ||
), | ||
bounds: query('GET_IMAGE_VALIDATE_SIZE_LABEL_EXPECTED_MIN_SIZE') | ||
}, | ||
TOO_BIG: { | ||
label: query( | ||
'GET_IMAGE_VALIDATE_SIZE_LABEL_IMAGE_SIZE_TOO_BIG' | ||
), | ||
bounds: query('GET_IMAGE_VALIDATE_SIZE_LABEL_EXPECTED_MAX_SIZE') | ||
} | ||
}[error]; | ||
// validation result | ||
}; | ||
const result = validateFile(file, size); | ||
if (result === true) { | ||
resolve(file); | ||
return; | ||
} | ||
//query('GET_IMAGE_VALIDATE_SIZE_LABEL_IMAGE_SIZE_TOO_BIG'), | ||
reject({ | ||
status: { | ||
main: labels[result.status], | ||
sub: replaceInString(labels[result.requirements], size) | ||
} | ||
}); | ||
reject({ | ||
status: { | ||
main: status.label, | ||
sub: replaceInString(status.bounds, bounds) | ||
} | ||
}); | ||
}); | ||
}) | ||
@@ -77,6 +111,6 @@ ); | ||
// required dimensions | ||
imageValidateSizeMinWidth: [1, Type.INT], | ||
imageValidateSizeMinWidth: [1, Type.INT], // needs to be atleast one pixel | ||
imageValidateSizeMinHeight: [1, Type.INT], | ||
imageValidateSizeMaxWidth: [null, Type.INT], | ||
imageValidateSizeMaxHeight: [null, Type.INT], | ||
imageValidateSizeMaxWidth: [65535, Type.INT], // maximum size of JPEG, fine for now I guess | ||
imageValidateSizeMaxHeight: [65535, Type.INT], | ||
@@ -83,0 +117,0 @@ // label to show when an image is too small or image is too big |
/* | ||
* FilePondPluginImageValidateSize 1.0.0 | ||
* FilePondPluginImageValidateSize 1.0.1 | ||
* Licensed under MIT, https://opensource.org/licenses/MIT | ||
* Please visit https://pqina.nl/filepond for details. | ||
*/ | ||
const isImage=e=>/^image/.test(e.type);var plugin$1=({addFilter:e,utils:i})=>{const{Type:E,replaceInString:I}=i;return e("LOAD_FILE",(e,{query:i})=>new Promise((E,I)=>{if(!isImage(e)||!i("GET_ALLOW_IMAGE_VALIDATE_SIZE"))return void E(e);i("GET_IMAGE_VALIDATE_SIZE_MIN_WIDTH"),i("GET_IMAGE_VALIDATE_SIZE_MIN_HEIGHT"),i("GET_IMAGE_VALIDATE_SIZE_MAX_WIDTH"),i("GET_IMAGE_VALIDATE_SIZE_MAX_HEIGHT"),i("GET_IMAGE_VALIDATE_SIZE_LABEL_IMAGE_SIZE_TOO_SMALL"),i("GET_IMAGE_VALIDATE_SIZE_LABEL_IMAGE_SIZE_TOO_BIG"),i("GET_IMAGE_VALIDATE_SIZE_LABEL_EXPECTED_MIN_SIZE"),i("GET_IMAGE_VALIDATE_SIZE_LABEL_EXPECTED_MAX_SIZE");return void E(e)})),{options:{allowImageValidateSize:[!0,E.BOOLEAN],imageValidateSizeMinWidth:[1,E.INT],imageValidateSizeMinHeight:[1,E.INT],imageValidateSizeMaxWidth:[null,E.INT],imageValidateSizeMaxHeight:[null,E.INT],imageValidateSizeLabelImageSizeTooSmall:["Image is too small",E.STRING],imageValidateSizeLabelImageSizeTooBig:["Image is too big",E.STRING],imageValidateSizeLabelExpectedMinSize:["Minimum size is {minWidth} × {minHeight}",E.STRING],imageValidateSizeLabelExpectedMaxSize:["Maximum size is {maxWidth} × {maxHeight}",E.STRING]}}};"undefined"!=typeof navigator&&document&&document.dispatchEvent(new CustomEvent("FilePond:pluginloaded",{detail:plugin$1}));export default plugin$1; | ||
const isImage=e=>/^image/.test(e.type),getImageSize=e=>new Promise((i,t)=>{const a=document.createElement("img");a.src=URL.createObjectURL(e);const I=setInterval(()=>{a.naturalWidth&&a.naturalHeight&&(clearInterval(I),URL.revokeObjectURL(a.src),i({width:a.naturalWidth,height:a.naturalHeight}))},1)});var plugin$1=({addFilter:e,utils:i})=>{const{Type:t,replaceInString:a,isFile:I}=i;return e("LOAD_FILE",(e,{query:i})=>new Promise((t,E)=>{if(!I(e)||!isImage(e)||!i("GET_ALLOW_IMAGE_VALIDATE_SIZE"))return void t(e);const _={minWidth:i("GET_IMAGE_VALIDATE_SIZE_MIN_WIDTH"),minHeight:i("GET_IMAGE_VALIDATE_SIZE_MIN_HEIGHT"),maxWidth:i("GET_IMAGE_VALIDATE_SIZE_MAX_WIDTH"),maxHeight:i("GET_IMAGE_VALIDATE_SIZE_MAX_HEIGHT")};((e,{minWidth:i,minHeight:t,maxWidth:a,maxHeight:I})=>new Promise((E,_)=>{getImageSize(e).then(({width:e,height:n})=>{e<i||n<t?_("TOO_SMALL"):(e>a||n>I)&&_("TOO_BIG"),E()})}))(e,_).then(()=>{t(e)}).catch(e=>{const t={TOO_SMALL:{label:i("GET_IMAGE_VALIDATE_SIZE_LABEL_IMAGE_SIZE_TOO_SMALL"),bounds:i("GET_IMAGE_VALIDATE_SIZE_LABEL_EXPECTED_MIN_SIZE")},TOO_BIG:{label:i("GET_IMAGE_VALIDATE_SIZE_LABEL_IMAGE_SIZE_TOO_BIG"),bounds:i("GET_IMAGE_VALIDATE_SIZE_LABEL_EXPECTED_MAX_SIZE")}}[e];E({status:{main:t.label,sub:a(t.bounds,_)}})})})),{options:{allowImageValidateSize:[!0,t.BOOLEAN],imageValidateSizeMinWidth:[1,t.INT],imageValidateSizeMinHeight:[1,t.INT],imageValidateSizeMaxWidth:[65535,t.INT],imageValidateSizeMaxHeight:[65535,t.INT],imageValidateSizeLabelImageSizeTooSmall:["Image is too small",t.STRING],imageValidateSizeLabelImageSizeTooBig:["Image is too big",t.STRING],imageValidateSizeLabelExpectedMinSize:["Minimum size is {minWidth} × {minHeight}",t.STRING],imageValidateSizeLabelExpectedMaxSize:["Maximum size is {maxWidth} × {maxHeight}",t.STRING]}}};"undefined"!=typeof navigator&&document&&document.dispatchEvent(new CustomEvent("FilePond:pluginloaded",{detail:plugin$1}));export default plugin$1; |
/* | ||
* FilePondPluginImageValidateSize 1.0.0 | ||
* FilePondPluginImageValidateSize 1.0.1 | ||
* Licensed under MIT, https://opensource.org/licenses/MIT | ||
@@ -43,3 +43,4 @@ * Please visit https://pqina.nl/filepond for details. | ||
var Type = utils.Type, | ||
replaceInString = utils.replaceInString; | ||
replaceInString = utils.replaceInString, | ||
isFile = utils.isFile; | ||
@@ -77,3 +78,7 @@ // required file size | ||
return new Promise(function(resolve, reject) { | ||
if (!isImage(file) || !query('GET_ALLOW_IMAGE_VALIDATE_SIZE')) { | ||
if ( | ||
!isFile(file) || | ||
!isImage(file) || | ||
!query('GET_ALLOW_IMAGE_VALIDATE_SIZE') | ||
) { | ||
resolve(file); | ||
@@ -80,0 +85,0 @@ return; |
/* | ||
* FilePondPluginImageValidateSize 1.0.0 | ||
* FilePondPluginImageValidateSize 1.0.1 | ||
* Licensed under MIT, https://opensource.org/licenses/MIT | ||
* Please visit https://pqina.nl/filepond for details. | ||
*/ | ||
!function(e,i){"object"==typeof exports&&"undefined"!=typeof module?module.exports=i():"function"==typeof define&&define.amd?define(i):e.FilePondPluginImageValidateSize=i()}(this,function(){"use strict";var e=function(e){return/^image/.test(e.type)},i=function(e){return new Promise(function(i,t){var a=document.createElement("img");a.src=URL.createObjectURL(e);var n=setInterval(function(){a.naturalWidth&&a.naturalHeight&&(clearInterval(n),URL.revokeObjectURL(a.src),i({width:a.naturalWidth,height:a.naturalHeight}))},1)})},t=function(t){var a=t.addFilter,n=t.utils,E=n.Type,I=n.replaceInString,_=function(e,t){var a=t.minWidth,n=t.minHeight,E=t.maxWidth,I=t.maxHeight;return new Promise(function(t,_){i(e).then(function(e){var i=e.width,o=e.height;i<a||o<n?_("TOO_SMALL"):(i>E||o>I)&&_("TOO_BIG"),t()})})};return a("LOAD_FILE",function(i,t){var a=t.query;return new Promise(function(t,n){if(!e(i)||!a("GET_ALLOW_IMAGE_VALIDATE_SIZE"))return void t(i);var E={minWidth:a("GET_IMAGE_VALIDATE_SIZE_MIN_WIDTH"),minHeight:a("GET_IMAGE_VALIDATE_SIZE_MIN_HEIGHT"),maxWidth:a("GET_IMAGE_VALIDATE_SIZE_MAX_WIDTH"),maxHeight:a("GET_IMAGE_VALIDATE_SIZE_MAX_HEIGHT")};_(i,E).then(function(){t(i)})["catch"](function(e){var i={TOO_SMALL:{label:a("GET_IMAGE_VALIDATE_SIZE_LABEL_IMAGE_SIZE_TOO_SMALL"),bounds:a("GET_IMAGE_VALIDATE_SIZE_LABEL_EXPECTED_MIN_SIZE")},TOO_BIG:{label:a("GET_IMAGE_VALIDATE_SIZE_LABEL_IMAGE_SIZE_TOO_BIG"),bounds:a("GET_IMAGE_VALIDATE_SIZE_LABEL_EXPECTED_MAX_SIZE")}}[e];n({status:{main:i.label,sub:I(i.bounds,E)}})})})}),{options:{allowImageValidateSize:[!0,E.BOOLEAN],imageValidateSizeMinWidth:[1,E.INT],imageValidateSizeMinHeight:[1,E.INT],imageValidateSizeMaxWidth:[65535,E.INT],imageValidateSizeMaxHeight:[65535,E.INT],imageValidateSizeLabelImageSizeTooSmall:["Image is too small",E.STRING],imageValidateSizeLabelImageSizeTooBig:["Image is too big",E.STRING],imageValidateSizeLabelExpectedMinSize:["Minimum size is {minWidth} × {minHeight}",E.STRING],imageValidateSizeLabelExpectedMaxSize:["Maximum size is {maxWidth} × {maxHeight}",E.STRING]}}};return"undefined"!=typeof navigator&&document&&document.dispatchEvent(new CustomEvent("FilePond:pluginloaded",{detail:t})),t}); | ||
!function(e,i){"object"==typeof exports&&"undefined"!=typeof module?module.exports=i():"function"==typeof define&&define.amd?define(i):e.FilePondPluginImageValidateSize=i()}(this,function(){"use strict";var e=function(e){return/^image/.test(e.type)},i=function(e){return new Promise(function(i,t){var a=document.createElement("img");a.src=URL.createObjectURL(e);var n=setInterval(function(){a.naturalWidth&&a.naturalHeight&&(clearInterval(n),URL.revokeObjectURL(a.src),i({width:a.naturalWidth,height:a.naturalHeight}))},1)})},t=function(t){var a=t.addFilter,n=t.utils,E=n.Type,I=n.replaceInString,_=n.isFile,o=function(e,t){var a=t.minWidth,n=t.minHeight,E=t.maxWidth,I=t.maxHeight;return new Promise(function(t,_){i(e).then(function(e){var i=e.width,o=e.height;i<a||o<n?_("TOO_SMALL"):(i>E||o>I)&&_("TOO_BIG"),t()})})};return a("LOAD_FILE",function(i,t){var a=t.query;return new Promise(function(t,n){if(!_(i)||!e(i)||!a("GET_ALLOW_IMAGE_VALIDATE_SIZE"))return void t(i);var E={minWidth:a("GET_IMAGE_VALIDATE_SIZE_MIN_WIDTH"),minHeight:a("GET_IMAGE_VALIDATE_SIZE_MIN_HEIGHT"),maxWidth:a("GET_IMAGE_VALIDATE_SIZE_MAX_WIDTH"),maxHeight:a("GET_IMAGE_VALIDATE_SIZE_MAX_HEIGHT")};o(i,E).then(function(){t(i)})["catch"](function(e){var i={TOO_SMALL:{label:a("GET_IMAGE_VALIDATE_SIZE_LABEL_IMAGE_SIZE_TOO_SMALL"),bounds:a("GET_IMAGE_VALIDATE_SIZE_LABEL_EXPECTED_MIN_SIZE")},TOO_BIG:{label:a("GET_IMAGE_VALIDATE_SIZE_LABEL_IMAGE_SIZE_TOO_BIG"),bounds:a("GET_IMAGE_VALIDATE_SIZE_LABEL_EXPECTED_MAX_SIZE")}}[e];n({status:{main:i.label,sub:I(i.bounds,E)}})})})}),{options:{allowImageValidateSize:[!0,E.BOOLEAN],imageValidateSizeMinWidth:[1,E.INT],imageValidateSizeMinHeight:[1,E.INT],imageValidateSizeMaxWidth:[65535,E.INT],imageValidateSizeMaxHeight:[65535,E.INT],imageValidateSizeLabelImageSizeTooSmall:["Image is too small",E.STRING],imageValidateSizeLabelImageSizeTooBig:["Image is too big",E.STRING],imageValidateSizeLabelExpectedMinSize:["Minimum size is {minWidth} × {minHeight}",E.STRING],imageValidateSizeLabelExpectedMaxSize:["Maximum size is {maxWidth} × {maxHeight}",E.STRING]}}};return"undefined"!=typeof navigator&&document&&document.dispatchEvent(new CustomEvent("FilePond:pluginloaded",{detail:t})),t}); |
{ | ||
"name": "filepond-plugin-image-validate-size", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Image Size Validation Plugin for FilePond", | ||
@@ -14,3 +14,6 @@ "homepage": "https://pqina.nl/filepond", | ||
"url": "https://pqina.nl" | ||
}, | ||
"peerDependencies": { | ||
"filepond": "^1.8.0" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
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
15493
283
1