UNPKG

filepond

Version:

FilePond, where files go to stretch their bits.

46 lines (45 loc) • 1.43 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 { isString as E, isFileEntry as a, isFile as s, isBlobOrFile as d } from "../utils/test.js"; import { getExtensionFromFilename as u } from "../utils/file.js"; const A = f({ name: "FileExtensionValidator", props: { accept: [], format: (n) => n.map((o) => o.substring(1)).join(", ").toUpperCase() }, factory: ({ props: n, didSetProps: o }) => { let i = []; function l(t) { return t.map((e) => e.trim()).filter((e) => e.startsWith(".")).map((e) => e.toLowerCase()); } return o(({ accept: t }) => { i = l(E(t) ? t.split(",") : t); }), { validateEntry: (t) => { const { format: e } = n; if (!a(t) || !s(t.file)) return null; const { name: r } = t.file; if (r === void 0) return { code: "VALIDATION_FILE_NAME_MISSING" }; const m = u(r)?.toLowerCase(); return i.some((c) => c === m) ? null : { code: "VALIDATION_FILE_EXTENSION_MISMATCH", values: { accept: e(i), count: i.length } }; }, canValidateEntry: (t) => !a(t) || !s(t.file) ? !1 : !!(d(t.file) && t.file?.name) && i.length > 0 }; } }); export { A as FileExtensionValidator };