filepond-plugin-image-validate-size
Advanced tools
Comparing version 1.0.1 to 1.0.2
/* | ||
* FilePondPluginImageValidateSize 1.0.1 | ||
* FilePondPluginImageValidateSize 1.0.2 | ||
* Licensed under MIT, https://opensource.org/licenses/MIT | ||
@@ -13,2 +13,3 @@ * Please visit https://pqina.nl/filepond for details. | ||
image.src = URL.createObjectURL(file); | ||
image.onerror = reject; | ||
const intervalId = setInterval(() => { | ||
@@ -33,13 +34,15 @@ if (image.naturalWidth && image.naturalHeight) { | ||
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'); | ||
} | ||
getImageSize(file) | ||
.then(({ width, height }) => { | ||
// validation result | ||
if (width < minWidth || height < minHeight) { | ||
reject('TOO_SMALL'); | ||
} else if (width > maxWidth || height > maxHeight) { | ||
reject('TOO_BIG'); | ||
} | ||
// all is well | ||
resolve(); | ||
}); | ||
// all is well | ||
resolve(); | ||
}) | ||
.catch(err => reject()); | ||
}); | ||
@@ -76,16 +79,25 @@ | ||
.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]; | ||
const status = error | ||
? { | ||
TOO_SMALL: { | ||
label: query( | ||
'GET_IMAGE_VALIDATE_SIZE_LABEL_IMAGE_SIZE_TOO_SMALL' | ||
), | ||
details: query( | ||
'GET_IMAGE_VALIDATE_SIZE_LABEL_EXPECTED_MIN_SIZE' | ||
) | ||
}, | ||
TOO_BIG: { | ||
label: query( | ||
'GET_IMAGE_VALIDATE_SIZE_LABEL_IMAGE_SIZE_TOO_BIG' | ||
), | ||
details: query( | ||
'GET_IMAGE_VALIDATE_SIZE_LABEL_EXPECTED_MAX_SIZE' | ||
) | ||
} | ||
}[error] | ||
: { | ||
label: query('GET_IMAGE_VALIDATE_SIZE_LABEL_FORMAT_ERROR'), | ||
details: file.type | ||
}; | ||
@@ -95,3 +107,5 @@ reject({ | ||
main: status.label, | ||
sub: replaceInString(status.bounds, bounds) | ||
sub: error | ||
? replaceInString(status.details, bounds) | ||
: status.details | ||
} | ||
@@ -110,3 +124,9 @@ }); | ||
// required dimensions | ||
// Error thrown when image can not be loaded | ||
imageValidateSizeLabelFormatError: [ | ||
'Image type not supported', | ||
Type.STRING | ||
], | ||
// Required dimensions | ||
imageValidateSizeMinWidth: [1, Type.INT], // needs to be atleast one pixel | ||
@@ -117,3 +137,3 @@ imageValidateSizeMinHeight: [1, Type.INT], | ||
// label to show when an image is too small or image is too big | ||
// Label to show when an image is too small or image is too big | ||
imageValidateSizeLabelImageSizeTooSmall: [ | ||
@@ -120,0 +140,0 @@ 'Image is too small', |
/* | ||
* FilePondPluginImageValidateSize 1.0.1 | ||
* FilePondPluginImageValidateSize 1.0.2 | ||
* Licensed under MIT, https://opensource.org/licenses/MIT | ||
* Please visit https://pqina.nl/filepond for details. | ||
*/ | ||
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; | ||
const isImage=e=>/^image/.test(e.type),getImageSize=e=>new Promise((i,t)=>{const a=document.createElement("img");a.src=URL.createObjectURL(e),a.onerror=t;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:l})=>{e<i||l<t?_("TOO_SMALL"):(e>a||l>I)&&_("TOO_BIG"),E()}).catch(e=>_())}))(e,_).then(()=>{t(e)}).catch(t=>{const I=t?{TOO_SMALL:{label:i("GET_IMAGE_VALIDATE_SIZE_LABEL_IMAGE_SIZE_TOO_SMALL"),details:i("GET_IMAGE_VALIDATE_SIZE_LABEL_EXPECTED_MIN_SIZE")},TOO_BIG:{label:i("GET_IMAGE_VALIDATE_SIZE_LABEL_IMAGE_SIZE_TOO_BIG"),details:i("GET_IMAGE_VALIDATE_SIZE_LABEL_EXPECTED_MAX_SIZE")}}[t]:{label:i("GET_IMAGE_VALIDATE_SIZE_LABEL_FORMAT_ERROR"),details:e.type};E({status:{main:I.label,sub:t?a(I.details,_):I.details}})})})),{options:{allowImageValidateSize:[!0,t.BOOLEAN],imageValidateSizeLabelFormatError:["Image type not supported",t.STRING],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.1 | ||
* FilePondPluginImageValidateSize 1.0.2 | ||
* Licensed under MIT, https://opensource.org/licenses/MIT | ||
@@ -24,2 +24,3 @@ * Please visit https://pqina.nl/filepond for details. | ||
image.src = URL.createObjectURL(file); | ||
image.onerror = reject; | ||
var intervalId = setInterval(function() { | ||
@@ -55,16 +56,20 @@ if (image.naturalWidth && image.naturalHeight) { | ||
return new Promise(function(resolve, reject) { | ||
getImageSize(file).then(function(_ref3) { | ||
var width = _ref3.width, | ||
height = _ref3.height; | ||
getImageSize(file) | ||
.then(function(_ref3) { | ||
var width = _ref3.width, | ||
height = _ref3.height; | ||
// validation result | ||
if (width < minWidth || height < minHeight) { | ||
reject('TOO_SMALL'); | ||
} else if (width > maxWidth || height > maxHeight) { | ||
reject('TOO_BIG'); | ||
} | ||
// validation result | ||
if (width < minWidth || height < minHeight) { | ||
reject('TOO_SMALL'); | ||
} else if (width > maxWidth || height > maxHeight) { | ||
reject('TOO_BIG'); | ||
} | ||
// all is well | ||
resolve(); | ||
}); | ||
// all is well | ||
resolve(); | ||
}) | ||
.catch(function(err) { | ||
return reject(); | ||
}); | ||
}); | ||
@@ -101,16 +106,25 @@ }; | ||
.catch(function(error) { | ||
var 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]; | ||
var status = error | ||
? { | ||
TOO_SMALL: { | ||
label: query( | ||
'GET_IMAGE_VALIDATE_SIZE_LABEL_IMAGE_SIZE_TOO_SMALL' | ||
), | ||
details: query( | ||
'GET_IMAGE_VALIDATE_SIZE_LABEL_EXPECTED_MIN_SIZE' | ||
) | ||
}, | ||
TOO_BIG: { | ||
label: query( | ||
'GET_IMAGE_VALIDATE_SIZE_LABEL_IMAGE_SIZE_TOO_BIG' | ||
), | ||
details: query( | ||
'GET_IMAGE_VALIDATE_SIZE_LABEL_EXPECTED_MAX_SIZE' | ||
) | ||
} | ||
}[error] | ||
: { | ||
label: query('GET_IMAGE_VALIDATE_SIZE_LABEL_FORMAT_ERROR'), | ||
details: file.type | ||
}; | ||
@@ -120,3 +134,5 @@ reject({ | ||
main: status.label, | ||
sub: replaceInString(status.bounds, bounds) | ||
sub: error | ||
? replaceInString(status.details, bounds) | ||
: status.details | ||
} | ||
@@ -135,3 +151,9 @@ }); | ||
// required dimensions | ||
// Error thrown when image can not be loaded | ||
imageValidateSizeLabelFormatError: [ | ||
'Image type not supported', | ||
Type.STRING | ||
], | ||
// Required dimensions | ||
imageValidateSizeMinWidth: [1, Type.INT], // needs to be atleast one pixel | ||
@@ -142,3 +164,3 @@ imageValidateSizeMinHeight: [1, Type.INT], | ||
// label to show when an image is too small or image is too big | ||
// Label to show when an image is too small or image is too big | ||
imageValidateSizeLabelImageSizeTooSmall: [ | ||
@@ -145,0 +167,0 @@ 'Image is too small', |
/* | ||
* FilePondPluginImageValidateSize 1.0.1 | ||
* FilePondPluginImageValidateSize 1.0.2 | ||
* 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,_=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}); | ||
!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),a.onerror=t;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,r=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,r=e.height;i<a||r<n?_("TOO_SMALL"):(i>E||r>I)&&_("TOO_BIG"),t()})["catch"](function(e){return _()})})};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")};r(i,E).then(function(){t(i)})["catch"](function(e){var t=e?{TOO_SMALL:{label:a("GET_IMAGE_VALIDATE_SIZE_LABEL_IMAGE_SIZE_TOO_SMALL"),details:a("GET_IMAGE_VALIDATE_SIZE_LABEL_EXPECTED_MIN_SIZE")},TOO_BIG:{label:a("GET_IMAGE_VALIDATE_SIZE_LABEL_IMAGE_SIZE_TOO_BIG"),details:a("GET_IMAGE_VALIDATE_SIZE_LABEL_EXPECTED_MAX_SIZE")}}[e]:{label:a("GET_IMAGE_VALIDATE_SIZE_LABEL_FORMAT_ERROR"),details:i.type};n({status:{main:t.label,sub:e?I(t.details,E):t.details}})})})}),{options:{allowImageValidateSize:[!0,E.BOOLEAN],imageValidateSizeLabelFormatError:["Image type not supported",E.STRING],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.1", | ||
"version": "1.0.2", | ||
"description": "Image Size Validation Plugin for FilePond", | ||
@@ -5,0 +5,0 @@ "homepage": "https://pqina.nl/filepond", |
@@ -5,2 +5,4 @@ # Image Size Validation plugin for FilePond | ||
https://pqina.nl/filepond | ||
https://pqina.nl/filepond/docs/patterns/plugins/image-validate-size/ | ||
The Image Size Validation plugin handles blocking of images whose dimensions don't fit the required minimum or maximum width and height. |
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
17376
323
8