UNPKG

filepond

Version:

FilePond, where files go to stretch their bits.

45 lines (44 loc) • 1.49 kB
/*! * FilePond v5.0.2 * Copyright (c) 2017-2026 Pqina B.V. * Released under the MIT License * https://filepond.com */ import { createValidatorExtension as p } from "./common/createValidatorExtension.js"; import { isString as a, isFileEntry as u, isBlobOrFile as c } from "../utils/test.js"; import { upperCaseFirstLetter as d } from "../utils/string.js"; const L = p({ name: "FileMimeTypeValidator", props: { accept: [], format: (l) => l.map((n) => { const [r, i] = n.split("/"); return i === "*" ? `fileMainType${d(r)}` : i.toUpperCase(); }).join(", ") }, factory: ({ props: l, didSetProps: n }) => { let r = [], i = [], o = []; return n(({ accept: e }) => { r = (a(e) ? e.split(",") : e).map( (t) => a(t) ? t.trim().toLowerCase() : t ).filter((t) => a(t) ? t.length === 0 ? !1 : !t.startsWith(".") : !0), i = r.filter(a), o = r.map((t) => a(t) ? t.includes("*") ? new RegExp("^" + t.split("*")[0], "i") : new RegExp("^" + t + "$", "i") : t); }), { validateEntry: (e) => { const { format: t } = l, { type: s } = e.file; return o.some( (f) => f.test(s.toLowerCase()) ) ? null : { code: "VALIDATION_FILE_MIME_TYPE_MISMATCH", values: { accept: t(i), count: r.length } }; }, canValidateEntry: (e) => !u(e) || !c(e.file) || o.length === 0 ? !1 : !!e.file.type }; } }); export { L as FileMimeTypeValidator };