New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

filepond-plugin-image-validate-size

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

filepond-plugin-image-validate-size - npm Package Compare versions

Comparing version 1.0.2 to 1.1.0

54

dist/filepond-plugin-image-validate-size.esm.js
/*
* FilePondPluginImageValidateSize 1.0.2
* FilePondPluginImageValidateSize 1.1.0
* Licensed under MIT, https://opensource.org/licenses/MIT

@@ -13,3 +13,6 @@ * Please visit https://pqina.nl/filepond for details.

image.src = URL.createObjectURL(file);
image.onerror = reject;
image.onerror = err => {
clearInterval(intervalId);
reject(err);
};
const intervalId = setInterval(() => {

@@ -32,17 +35,32 @@ if (image.naturalWidth && image.naturalHeight) {

// required file size
const validateFile = (file, { minWidth, minHeight, maxWidth, maxHeight }) =>
const validateFile = (file, bounds, measure) =>
new Promise((resolve, reject) => {
const onReceiveSize = ({ width, height }) => {
const { minWidth, minHeight, maxWidth, maxHeight } = bounds;
// validation result
if (width < minWidth || height < minHeight) {
reject('TOO_SMALL');
} else if (width > maxWidth || height > maxHeight) {
reject('TOO_BIG');
}
// all is well
resolve();
};
getImageSize(file)
.then(({ width, height }) => {
// validation result
if (width < minWidth || height < minHeight) {
reject('TOO_SMALL');
} else if (width > maxWidth || height > maxHeight) {
reject('TOO_BIG');
.then(onReceiveSize)
.catch(() => {
// no custom measure method supplied, exit here
if (!measure) {
reject();
return;
}
// all is well
resolve();
})
.catch(err => reject());
// try fallback if defined by user, else reject
measure(file, bounds)
.then(onReceiveSize)
.catch(() => reject());
});
});

@@ -74,3 +92,6 @@

validateFile(file, bounds)
// get optional custom measure function
const measure = query('GET_IMAGE_VALIDATE_SIZE_MEASURE');
validateFile(file, bounds, measure)
.then(() => {

@@ -129,4 +150,7 @@ resolve(file);

// Custom function to use as image measure
imageValidateSizeMeasure: [null, Type.FUNCTION],
// Required dimensions
imageValidateSizeMinWidth: [1, Type.INT], // needs to be atleast one pixel
imageValidateSizeMinWidth: [1, Type.INT], // needs to be at least one pixel
imageValidateSizeMinHeight: [1, Type.INT],

@@ -133,0 +157,0 @@ imageValidateSizeMaxWidth: [65535, Type.INT], // maximum size of JPEG, fine for now I guess

/*
* FilePondPluginImageValidateSize 1.0.2
* FilePondPluginImageValidateSize 1.1.0
* 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),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;
const isImage=e=>/^image/.test(e.type),getImageSize=e=>new Promise((i,a)=>{const t=document.createElement("img");t.src=URL.createObjectURL(e),t.onerror=(e=>{clearInterval(E),a(e)});const E=setInterval(()=>{t.naturalWidth&&t.naturalHeight&&(clearInterval(E),URL.revokeObjectURL(t.src),i({width:t.naturalWidth,height:t.naturalHeight}))},1)});var plugin$1=({addFilter:e,utils:i})=>{const{Type:a,replaceInString:t,isFile:E}=i;return e("LOAD_FILE",(e,{query:i})=>new Promise((a,I)=>{if(!E(e)||!isImage(e)||!i("GET_ALLOW_IMAGE_VALIDATE_SIZE"))return void a(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")},l=i("GET_IMAGE_VALIDATE_SIZE_MEASURE");((e,i,a)=>new Promise((t,E)=>{const I=({width:e,height:a})=>{const{minWidth:I,minHeight:_,maxWidth:l,maxHeight:n}=i;e<I||a<_?E("TOO_SMALL"):(e>l||a>n)&&E("TOO_BIG"),t()};getImageSize(e).then(I).catch(()=>{a?a(e,i).then(I).catch(()=>E()):E()})}))(e,_,l).then(()=>{a(e)}).catch(a=>{const E=a?{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")}}[a]:{label:i("GET_IMAGE_VALIDATE_SIZE_LABEL_FORMAT_ERROR"),details:e.type};I({status:{main:E.label,sub:a?t(E.details,_):E.details}})})})),{options:{allowImageValidateSize:[!0,a.BOOLEAN],imageValidateSizeLabelFormatError:["Image type not supported",a.STRING],imageValidateSizeMeasure:[null,a.FUNCTION],imageValidateSizeMinWidth:[1,a.INT],imageValidateSizeMinHeight:[1,a.INT],imageValidateSizeMaxWidth:[65535,a.INT],imageValidateSizeMaxHeight:[65535,a.INT],imageValidateSizeLabelImageSizeTooSmall:["Image is too small",a.STRING],imageValidateSizeLabelImageSizeTooBig:["Image is too big",a.STRING],imageValidateSizeLabelExpectedMinSize:["Minimum size is {minWidth} × {minHeight}",a.STRING],imageValidateSizeLabelExpectedMaxSize:["Maximum size is {maxWidth} × {maxHeight}",a.STRING]}}};"undefined"!=typeof navigator&&document&&document.dispatchEvent(new CustomEvent("FilePond:pluginloaded",{detail:plugin$1}));export default plugin$1;
/*
* FilePondPluginImageValidateSize 1.0.2
* FilePondPluginImageValidateSize 1.1.0
* Licensed under MIT, https://opensource.org/licenses/MIT

@@ -24,3 +24,6 @@ * Please visit https://pqina.nl/filepond for details.

image.src = URL.createObjectURL(file);
image.onerror = reject;
image.onerror = function(err) {
clearInterval(intervalId);
reject(err);
};
var intervalId = setInterval(function() {

@@ -50,25 +53,39 @@ if (image.naturalWidth && image.naturalHeight) {

var validateFile = function validateFile(file, _ref2) {
var minWidth = _ref2.minWidth,
minHeight = _ref2.minHeight,
maxWidth = _ref2.maxWidth,
maxHeight = _ref2.maxHeight;
var validateFile = function validateFile(file, bounds, measure) {
return new Promise(function(resolve, reject) {
var onReceiveSize = function onReceiveSize(_ref2) {
var width = _ref2.width,
height = _ref2.height;
var minWidth = bounds.minWidth,
minHeight = bounds.minHeight,
maxWidth = bounds.maxWidth,
maxHeight = bounds.maxHeight;
// validation result
if (width < minWidth || height < minHeight) {
reject('TOO_SMALL');
} else if (width > maxWidth || height > maxHeight) {
reject('TOO_BIG');
}
// all is well
resolve();
};
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');
.then(onReceiveSize)
.catch(function() {
// no custom measure method supplied, exit here
if (!measure) {
reject();
return;
}
// all is well
resolve();
})
.catch(function(err) {
return reject();
// try fallback if defined by user, else reject
measure(file, bounds)
.then(onReceiveSize)
.catch(function() {
return reject();
});
});

@@ -81,4 +98,4 @@ });

// should return a promise
addFilter('LOAD_FILE', function(file, _ref4) {
var query = _ref4.query;
addFilter('LOAD_FILE', function(file, _ref3) {
var query = _ref3.query;
return new Promise(function(resolve, reject) {

@@ -102,3 +119,6 @@ if (

validateFile(file, bounds)
// get optional custom measure function
var measure = query('GET_IMAGE_VALIDATE_SIZE_MEASURE');
validateFile(file, bounds, measure)
.then(function() {

@@ -157,4 +177,7 @@ resolve(file);

// Custom function to use as image measure
imageValidateSizeMeasure: [null, Type.FUNCTION],
// Required dimensions
imageValidateSizeMinWidth: [1, Type.INT], // needs to be atleast one pixel
imageValidateSizeMinWidth: [1, Type.INT], // needs to be at least one pixel
imageValidateSizeMinHeight: [1, Type.INT],

@@ -161,0 +184,0 @@ imageValidateSizeMaxWidth: [65535, Type.INT], // maximum size of JPEG, fine for now I guess

/*
* FilePondPluginImageValidateSize 1.0.2
* FilePondPluginImageValidateSize 1.1.0
* 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),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});
!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=function(e){clearInterval(n),t(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,r=function(e,t,a){return new Promise(function(n,E){var I=function(e){var i=e.width,a=e.height,I=t.minWidth,_=t.minHeight,r=t.maxWidth,l=t.maxHeight;i<I||a<_?E("TOO_SMALL"):(i>r||a>l)&&E("TOO_BIG"),n()};i(e).then(I)["catch"](function(){return a?void a(e,t).then(I)["catch"](function(){return E()}):void E()})})};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")},l=a("GET_IMAGE_VALIDATE_SIZE_MEASURE");r(i,E,l).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],imageValidateSizeMeasure:[null,E.FUNCTION],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.2",
"version": "1.1.0",
"description": "Image Size Validation Plugin for FilePond",

@@ -5,0 +5,0 @@ "homepage": "https://pqina.nl/filepond",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc