@@ -76,13 +76,26 @@ function isDefined(value) {
7676 return value !== undefined && value !== null ;
7777}
7878
79+ /**
80+ *
81+ * @param {object } options
82+ * @param {File[] } options.files
83+ * @param {string|string[] } [options.accept]
84+ * @param {number } [options.minSize]
85+ * @param {number } [options.maxSize]
86+ * @param {boolean } [options.multiple]
87+ * @param {number } [options.maxFiles]
88+ * @param {(f: File) => FileError|FileError[]|null } [options.validator]
89+ * @returns
90+ */
7991export function allFilesAccepted ( {
8092 files,
8193 accept,
8294 minSize,
8395 maxSize,
8496 multiple,
8597 maxFiles,
98+ validator,
8699} ) {
87100 if (
88101 ( ! multiple && files . length > 1 ) ||
@@ -94,7 +107,8 @@ export function allFilesAccepted({
94107 return files . every ( ( file ) => {
95108 const [ accepted ] = fileAccepted ( file , accept ) ;
96109 const [ sizeMatch ] = fileMatchSize ( file , minSize , maxSize ) ;
97- return accepted && sizeMatch ;
110+ const customErrors = validator ? validator ( file ) : null ;
111+ return accepted && sizeMatch && ! customErrors ;
98112 } ) ;
99113}
100114
@@ -287,3 +301,13 @@ export function isExt(v) {
287301/**
288302 * @typedef {Object.<string, string[]> } AcceptProp
289303 */
304+
305+ /**
306+ * @typedef {object } FileError
307+ * @property {string } message
308+ * @property {ErrorCode|string } code
309+ */
310+
311+ /**
312+ * @typedef {"file-invalid-type"|"file-too-large"|"file-too-small"|"too-many-files" } ErrorCode
313+ */
0 commit comments