Skip to content

Commit 9b9b61e

Browse files
committed
open source
1 parent f52ae7c commit 9b9b61e

14 files changed

+2880
-59
lines changed

.babelrc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"presets": [
3+
["@babel/preset-env", {
4+
"exclude": ["transform-typeof-symbol"],
5+
"modules": false,
6+
"targets": {
7+
"browsers": [
8+
"last 3 versions",
9+
"edge >= 12",
10+
"ie 11"
11+
]
12+
}
13+
}]
14+
]
15+
}

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dist/* linguist-vendored=false

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
npm-debug.log
1+
npm-debug.log
2+
node_modules/

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@
55
https://pqina.nl/filepond/docs/patterns/plugins/file-validate-size/
66

77
The File Size Validation plugin is used to block files that are too large to upload. Set a maximum size for single files and a maximum size for all files.
8+
9+
[Demo](https://pqina.github.io/filepond-plugin-file-validate-size/)

dist/filepond-plugin-file-validate-size.esm.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
/*
2-
* FilePondPluginFileValidateSize 2.1.1
3-
* Licensed under MIT, https://opensource.org/licenses/MIT
4-
* Please visit https://pqina.nl/filepond for details.
1+
/*!
2+
* FilePondPluginFileValidateSize 2.1.2
3+
* Licensed under MIT, https://opensource.org/licenses/MIT/
4+
* Please visit https://pqina.nl/filepond/ for details.
55
*/
66

77
/* eslint-disable */
8-
var plugin$1 = ({ addFilter, utils }) => {
8+
9+
const plugin = ({ addFilter, utils }) => {
910
// get quick reference to Type utils
1011
const { Type, replaceInString, toNaturalFileSize } = utils;
1112

@@ -132,13 +133,13 @@ var plugin$1 = ({ addFilter, utils }) => {
132133
};
133134
};
134135

136+
// fire pluginloaded event if running in browser, this allows registering the plugin when using async script tags
135137
const isBrowser =
136138
typeof window !== 'undefined' && typeof window.document !== 'undefined';
137-
138139
if (isBrowser) {
139140
document.dispatchEvent(
140-
new CustomEvent('FilePond:pluginloaded', { detail: plugin$1 })
141+
new CustomEvent('FilePond:pluginloaded', { detail: plugin })
141142
);
142143
}
143144

144-
export default plugin$1;
145+
export default plugin;

dist/filepond-plugin-file-validate-size.esm.min.js

Lines changed: 6 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 27 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,28 @@
1-
/*
2-
* FilePondPluginFileValidateSize 2.1.1
3-
* Licensed under MIT, https://opensource.org/licenses/MIT
4-
* Please visit https://pqina.nl/filepond for details.
1+
/*!
2+
* FilePondPluginFileValidateSize 2.1.2
3+
* Licensed under MIT, https://opensource.org/licenses/MIT/
4+
* Please visit https://pqina.nl/filepond/ for details.
55
*/
66

77
/* eslint-disable */
8+
89
(function(global, factory) {
910
typeof exports === 'object' && typeof module !== 'undefined'
1011
? (module.exports = factory())
1112
: typeof define === 'function' && define.amd
12-
? define(factory)
13-
: (global.FilePondPluginFileValidateSize = factory());
13+
? define(factory)
14+
: ((global = global || self),
15+
(global.FilePondPluginFileValidateSize = factory()));
1416
})(this, function() {
1517
'use strict';
1618

17-
var plugin$1 = function(_ref) {
19+
var plugin = function plugin(_ref) {
1820
var addFilter = _ref.addFilter,
1921
utils = _ref.utils;
20-
2122
// get quick reference to Type utils
2223
var Type = utils.Type,
2324
replaceInString = utils.replaceInString,
24-
toNaturalFileSize = utils.toNaturalFileSize;
25-
26-
// filtering if an item is allowed in hopper
25+
toNaturalFileSize = utils.toNaturalFileSize; // filtering if an item is allowed in hopper
2726

2827
addFilter('ALLOW_HOPPER_ITEM', function(file, _ref2) {
2928
var query = _ref2.query;
@@ -33,32 +32,33 @@
3332
}
3433

3534
var sizeMax = query('GET_MAX_FILE_SIZE');
35+
3636
if (sizeMax !== null && file.size >= sizeMax) {
3737
return false;
3838
}
3939

4040
var sizeMin = query('GET_MIN_FILE_SIZE');
41+
4142
if (sizeMin !== null && file.size <= sizeMin) {
4243
return false;
4344
}
4445

4546
return true;
46-
});
47-
48-
// called for each file that is loaded
47+
}); // called for each file that is loaded
4948
// right before it is set to the item state
5049
// should return a promise
50+
5151
addFilter('LOAD_FILE', function(file, _ref3) {
5252
var query = _ref3.query;
5353
return new Promise(function(resolve, reject) {
5454
// if not allowed, all fine, exit
5555
if (!query('GET_ALLOW_FILE_SIZE_VALIDATION')) {
5656
resolve(file);
5757
return;
58-
}
58+
} // reject or resolve based on file size
5959

60-
// reject or resolve based on file size
6160
var sizeMax = query('GET_MAX_FILE_SIZE');
61+
6262
if (sizeMax !== null && file.size >= sizeMax) {
6363
reject({
6464
status: {
@@ -69,10 +69,10 @@
6969
}
7070
});
7171
return;
72-
}
72+
} // reject or resolve based on file size
7373

74-
// reject or resolve based on file size
7574
var sizeMin = query('GET_MIN_FILE_SIZE');
75+
7676
if (sizeMin !== null && file.size <= sizeMin) {
7777
reject({
7878
status: {
@@ -83,10 +83,10 @@
8383
}
8484
});
8585
return;
86-
}
86+
} // returns the current option value
8787

88-
// returns the current option value
8988
var totalSizeMax = query('GET_MAX_TOTAL_FILE_SIZE');
89+
9090
if (totalSizeMax !== null) {
9191
// get the current total file size
9292
var currentTotalSize = query('GET_ACTIVE_ITEMS').reduce(function(
@@ -95,9 +95,8 @@
9595
) {
9696
return total + item.fileSize;
9797
},
98-
0);
98+
0); // get the size of the new file
9999

100-
// get the size of the new file
101100
if (currentTotalSize > totalSizeMax) {
102101
reject({
103102
status: {
@@ -109,34 +108,26 @@
109108
});
110109
return;
111110
}
112-
}
111+
} // file is fine, let's pass it back
113112

114-
// file is fine, let's pass it back
115113
resolve(file);
116114
});
117115
});
118-
119116
return {
120117
options: {
121118
// Enable or disable file type validation
122119
allowFileSizeValidation: [true, Type.BOOLEAN],
123-
124120
// Max individual file size in bytes
125121
maxFileSize: [null, Type.INT],
126-
127122
// Min individual file size in bytes
128123
minFileSize: [null, Type.INT],
129-
130124
// Max total file size in bytes
131125
maxTotalFileSize: [null, Type.INT],
132-
133126
// error labels
134127
labelMinFileSizeExceeded: ['File is too small', Type.STRING],
135128
labelMinFileSize: ['Minimum file size is {filesize}', Type.STRING],
136-
137129
labelMaxFileSizeExceeded: ['File is too large', Type.STRING],
138130
labelMaxFileSize: ['Maximum file size is {filesize}', Type.STRING],
139-
140131
labelMaxTotalFileSizeExceeded: [
141132
'Maximum total size exceeded',
142133
Type.STRING
@@ -147,16 +138,18 @@
147138
]
148139
}
149140
};
150-
};
141+
}; // fire pluginloaded event if running in browser, this allows registering the plugin when using async script tags
151142

152143
var isBrowser =
153144
typeof window !== 'undefined' && typeof window.document !== 'undefined';
154145

155146
if (isBrowser) {
156147
document.dispatchEvent(
157-
new CustomEvent('FilePond:pluginloaded', { detail: plugin$1 })
148+
new CustomEvent('FilePond:pluginloaded', {
149+
detail: plugin
150+
})
158151
);
159152
}
160153

161-
return plugin$1;
154+
return plugin;
162155
});

dist/filepond-plugin-file-validate-size.min.js

Lines changed: 6 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.html

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>FilePond Plugin File Validate Size Demo</title>
7+
<link href="https://unpkg.com/filepond/dist/filepond.css" rel="stylesheet">
8+
</head>
9+
<body>
10+
11+
<input type="file"/>
12+
13+
<script src="./dist/filepond-plugin-file-validate-size.js"></script>
14+
<script src="https://unpkg.com/filepond/dist/filepond.js"></script>
15+
16+
<script>
17+
// Register the plugin with FilePond
18+
FilePond.registerPlugin(FilePondPluginFileValidateSize);
19+
20+
// Get a reference to the file input element
21+
const inputElement = document.querySelector('input[type="file"]');
22+
23+
// Create the FilePond instance
24+
const pond = FilePond.create(inputElement, {
25+
maxFileSize: '100KB'
26+
});
27+
</script>
28+
29+
</body>
30+
</html>

0 commit comments

Comments
 (0)