file-selector

  • Version 4.0.0
  • Published
  • 374 kB
  • No dependencies
  • MIT license

Install

npm i file-selector
yarn add file-selector
pnpm add file-selector

Overview

Convert DataTransfer object to a list of File objects

Index

Variables

variable DEFAULT_MIME_TYPES

const DEFAULT_MIME_TYPES: Map<string, string>;
  • A small set of the most common file extensions, bundled into the main entry so that fromEvent guesses a MIME type for typeless files out of the box.

    This is the single source of truth for these defaults: the full extension-to-MIME table (COMMON_MIME_TYPES, exposed via the file-selector/mime subpath) spreads this map in rather than redefining these entries, so no value is duplicated across modules.

    See https://github.com/react-dropzone/file-selector/issues/127

Functions

function fromEvent

fromEvent: (
evt: Event | any,
{ mimeTypes }?: FromEventOptions
) => Promise<(FileWithPath | DataTransferItem)[]>;
  • Convert a DragEvent's DataTrasfer object to a list of File objects NOTE: If some of the items are folders, everything will be flattened and placed in the same list but the paths will be kept as a {path} property.

    EXPERIMENTAL: A list of https://developer.mozilla.org/en-US/docs/Web/API/FileSystemHandle objects can also be passed as an arg and a list of File objects will be returned.

    Parameter evt

    Parameter options

Interfaces

interface FileWithPath

interface FileWithPath extends File {}

    property handle

    readonly handle?: FileSystemFileHandle;

      property path

      readonly path: string;

        property relativePath

        readonly relativePath: string;

          interface FromEventOptions

          interface FromEventOptions {}

            property mimeTypes

            mimeTypes?: Map<string, string>;
            • Extension-to-MIME lookup used to set type on files the browser left typeless. Defaults to a small built-in set of common types (DEFAULT_MIME_TYPES).

              The full extension-to-MIME table (~1,200 entries) is not bundled into the main entry; import it from the file-selector/mime subpath when broader coverage is needed:

              import {fromEvent} from 'file-selector';
              import {COMMON_MIME_TYPES} from 'file-selector/mime';
              await fromEvent(evt, {mimeTypes: COMMON_MIME_TYPES});

              See https://github.com/react-dropzone/file-selector/issues/127

            Package Files (2)

            Dependencies (0)

            No dependencies.

            Dev Dependencies (12)

            Peer Dependencies (0)

            No peer dependencies.

            Badge

            To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

            You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/file-selector.

            • Markdown
              [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/file-selector)
            • HTML
              <a href="https://www.jsdocs.io/package/file-selector"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>