UNPKG

filepond

Version:

FilePond, where files go to stretch their bits.

55 lines (54 loc) • 1.55 kB
/*! * FilePond v5.0.2 * Copyright (c) 2017-2026 Pqina B.V. * Released under the MIT License * https://filepond.com */ import { createValidatorExtension as F } from "./common/createValidatorExtension.js"; import { isFileEntry as E, isBlobOrFile as S } from "../utils/test.js"; import { naturalFileSizeToBytes as m, bytesToNaturalFileSize as r, getFormatFromFileSize as l } from "../utils/file.js"; const p = F({ name: "FileSizeValidator", props: { minSize: 0, maxSize: 1 / 0, byteUnits: void 0 }, factory: ({ didSetProps: o }) => { const t = { min: 0, max: 1 / 0 }, i = { min: null, minUnit: null, max: null, maxUnit: null }; return o(({ minSize: n, maxSize: a, byteUnits: e }) => { e = e || l(a) || l(n) || "mega", t.min = m(n), t.max = m(a); const [s, u] = r(t.min, { byteUnits: e }).split(" "), [x, c] = r(t.max, { byteUnits: e }).split(" "); i.min = s, i.minUnit = u, i.max = x, i.maxUnit = c; }), { validateEntry: (n) => { const { size: a } = n.file; return a < t.min ? { code: "VALIDATION_FILE_SIZE_UNDERFLOW", values: { minSize: i.min, minSizeUnit: `unit${i.minUnit}` } } : a > t.max ? { code: "VALIDATION_FILE_SIZE_OVERFLOW", values: { maxSize: i.max, maxSizeUnit: `unit${i.maxUnit}` } } : null; }, canValidateEntry: (n) => E(n) && S(n.file) }; } }); export { p as FileSizeValidator };