filepond
Version:
FilePond, where files go to stretch their bits.
80 lines (79 loc) • 2.16 kB
JavaScript
/*!
* FilePond v5.0.2
* Copyright (c) 2017-2026 Pqina B.V.
* Released under the MIT License
* https://filepond.com
*/
import { createExtension as y } from "./common/createExtension.js";
import { naturalFileSizeToBytes as I, bytesToNaturalFileSize as u, getFormatFromFileSize as f } from "../utils/file.js";
import { flattenTree as z } from "../utils/tree.js";
import { Status as o } from "../common/status.js";
import { isBlobOrFile as T } from "../utils/test.js";
const _ = y({
name: "ListSizeValidator",
type: "validator",
props: {
minListSize: 0,
maxListSize: 1 / 0,
byteUnits: void 0
},
factory: ({ didSetProps: c }, { on: p, setExtensionStatus: a, getEntries: x }) => {
const i = {
min: 0,
max: 1 / 0
}, t = {
min: null,
minUnit: null,
max: null,
maxUnit: null
};
let l = !1;
c(({ minListSize: m, maxListSize: e, byteUnits: n }) => {
n = n || f(e) || f(m) || "mega", i.min = I(m || 0), i.max = I(e || 1 / 0);
const [r, d] = u(i.min, { byteUnits: n }).split(" "), [S, A] = u(i.max, { byteUnits: n }).split(" ");
t.min = r, t.minUnit = d, t.max = S, t.maxUnit = A, l = i.min !== 0 || i.max !== 1 / 0, s(x());
});
function s(m) {
if (!l)
return;
const e = z(m).reduce(
// @ts-ignore
(n, r) => n + (T(r.file) ? r.size : 0),
0
);
if (e < i.min)
return a({
type: o.Error,
code: "VALIDATION_INVALID",
subcode: "VALIDATION_LIST_SIZE_UNDERFLOW",
values: {
minSize: t.min,
minSizeUnit: `unit${t.minUnit}`
}
});
if (e > i.max)
return a({
type: o.Error,
code: "VALIDATION_INVALID",
subcode: "VALIDATION_LIST_SIZE_OVERFLOW",
values: {
maxSize: t.max,
maxSizeUnit: `unit${t.maxUnit}`
}
});
a({
type: o.System,
code: "VALIDATION_COMPLETE"
});
}
const L = p("updateEntries", s);
return {
destroy: () => {
L();
}
};
}
});
export {
_ as ListSizeValidator
};