MCPcopy Create free account
hub / github.com/react-dropzone/react-dropzone / pickerOptionsFromAccept

Function pickerOptionsFromAccept

src/utils/index.js:237–275  ·  view source on GitHub ↗
(accept)

Source from the content-addressed store, hash-verified

235 * @returns {{accept: string[]}[]}
236 */
237export function pickerOptionsFromAccept(accept) {
238 if (isDefined(accept)) {
239 const acceptForPicker = Object.entries(accept)
240 .filter(([mimeType, ext]) => {
241 let ok = true;
242
243 if (!isMIMEType(mimeType)) {
244 console.warn(
245 `Skipped "${mimeType}" because it is not a valid MIME type. Check https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types for a list of valid MIME types.`
246 );
247 ok = false;
248 }
249
250 if (!Array.isArray(ext) || !ext.every(isExt)) {
251 console.warn(
252 `Skipped "${mimeType}" because an invalid file extension was provided.`
253 );
254 ok = false;
255 }
256
257 return ok;
258 })
259 .reduce(
260 (agg, [mimeType, ext]) => ({
261 ...agg,
262 [mimeType]: ext,
263 }),
264 {}
265 );
266 return [
267 {
268 // description is required due to https://crbug.com/1264708
269 description: "Files",
270 accept: acceptForPicker,
271 },
272 ];
273 }
274 return accept;
275}
276
277/**
278 * Convert the `{accept}` dropzone prop to an array of MIME types/extensions.

Callers 1

useDropzoneFunction · 0.90

Calls 2

isDefinedFunction · 0.85
isMIMETypeFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…