{"version":3,"file":"index.cjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["/**\n * A minimal subset of the {@link File} interface: the fields `accept` reads.\n *\n * @see https://developer.mozilla.org/en-US/docs/Web/API/File\n */\nexport interface FileWithType {\n  /** The file name, e.g. `my-photo.png`. */\n  name?: string;\n  /** The MIME type, e.g. `image/png`. */\n  type?: string;\n}\n\n/**\n * Check if the provided file should be accepted by an `<input type=\"file\">`\n * with the given `accept` attribute value.\n *\n * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/file#attr-accept\n *\n * Inspired by https://github.com/enyo/dropzone.\n *\n * @param file The file to check. When omitted or `null`, the file is accepted.\n * @param acceptedFiles One or more MIME types and/or file extensions, either as\n * a comma-delimited string or an array. When omitted or empty, any file is accepted.\n * @returns `true` if the file matches (or when there is nothing to match against).\n */\nexport default function accept(file?: FileWithType | null, acceptedFiles?: string | string[]): boolean {\n  if (file && acceptedFiles) {\n    const acceptedFilesArray = Array.isArray(acceptedFiles) ? acceptedFiles : acceptedFiles.split(\",\");\n    if (acceptedFilesArray.length === 0) {\n      return true;\n    }\n    const fileName = file.name || \"\";\n    const mimeType = (file.type || \"\").toLowerCase();\n    const baseMimeType = mimeType.replace(/\\/.*$/, \"\");\n\n    return acceptedFilesArray.some(type => {\n      const validType = type.trim().toLowerCase();\n      if (validType.charAt(0) === \".\") {\n        return fileName.toLowerCase().endsWith(validType);\n      } else if (validType.endsWith(\"/*\")) {\n        // This is something like an image/* MIME type.\n        return baseMimeType === validType.replace(/\\/.*$/, \"\");\n      }\n      return mimeType === validType;\n    });\n  }\n  return true;\n}\n"],"mappings":";;;;;;;;;;;;;;AAyBA,SAAwB,OAAO,MAA4B,eAA4C;CACrG,IAAI,QAAQ,eAAe;EACzB,MAAM,qBAAqB,MAAM,QAAQ,aAAa,IAAI,gBAAgB,cAAc,MAAM,GAAG;EACjG,IAAI,mBAAmB,WAAW,GAChC,OAAO;EAET,MAAM,WAAW,KAAK,QAAQ;EAC9B,MAAM,YAAY,KAAK,QAAQ,GAAA,CAAI,YAAY;EAC/C,MAAM,eAAe,SAAS,QAAQ,SAAS,EAAE;EAEjD,OAAO,mBAAmB,MAAK,SAAQ;GACrC,MAAM,YAAY,KAAK,KAAK,CAAC,CAAC,YAAY;GAC1C,IAAI,UAAU,OAAO,CAAC,MAAM,KAC1B,OAAO,SAAS,YAAY,CAAC,CAAC,SAAS,SAAS;QAC3C,IAAI,UAAU,SAAS,IAAI,GAEhC,OAAO,iBAAiB,UAAU,QAAQ,SAAS,EAAE;GAEvD,OAAO,aAAa;EACtB,CAAC;CACH;CACA,OAAO;AACT"}