{"name":"file-selector","version":"2.1.2","keywords":["drag-and-drop","html5","file-api","DataTransfer","File"],"author":{"name":"Roland Groza","email":"rolandjitsu@gmail.com"},"license":"MIT","_id":"file-selector@2.1.2","homepage":"https://github.com/react-dropzone/file-selector","bugs":{"url":"https://github.com/react-dropzone/file-selector/issues"},"dist":{"shasum":"fe7c7ee9e550952dfbc863d73b14dc740d7de8b4","tarball":"http://registry-npm.ywwl.com/file-selector/download/file-selector-2.1.2.tgz","fileCount":25,"integrity":"sha512-QgXo+mXTe8ljeqUFaX3QVHc5osSItJ/Km+xpocx0aSqWGMSCf6qYs/VnzZgS864Pjn5iceMRFigeAV7AfTlaig==","signatures":[{"sig":"MEUCIQCyxxp5CZdLMptnKeg3gzblZdChS5DN3OnzdKEoBHDAEQIgFhOEuadJ7vPUqviDtz4kJ2Jo6+fIfaq9Sp3soQ+u+5s=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":623456,"size":124378,"noattachment":false,"key":"/file-selector/-/file-selector-2.1.2.tgz"},"main":"./dist/index.js","types":"./dist/index.d.ts","module":"./dist/es2015/index.js","engines":{"node":">= 12"},"gitHead":"7c0596f2b3d987d54197e92efae51f2ca9cc4c88","scripts":{"lint":"tslint -c tslint.json -p ./tsconfig.spec.json -t stylish","test":"jest --watch","build":"npm-run-all -s compile build:umd","clean":"rm -rf dist/*","compile":"npm-run-all -p compile:es2015 compile:cjs compile:types","lint:fix":"npm run lint -- --fix","prebuild":"npm run clean","test:cov":"jest --coverage","build:umd":"rollup -c ./rollup.config.mjs","compile:cjs":"tsc -p ./tsconfig.cjs.json","pretest:cov":"npm run lint","compile:types":"tsc -p ./tsconfig.types.json","compile:es2015":"tsc -p ./tsconfig.es2015.json"},"_npmUser":{"name":"rolandjitsu","email":"rolandjitsu@gmail.com"},"repository":{"url":"git+https://github.com/react-dropzone/file-selector.git","type":"git"},"_npmVersion":"10.9.1","description":"Convert DataTransfer object to a list of File objects","directories":{},"_nodeVersion":"22.11.0","dependencies":{"tslib":"^2.7.0"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"jest":"^29.7.0","rollup":"^4.24.0","tslint":"^6.1.3","ts-jest":"^29.2.5","camelcase":"^8.0.0","typescript":"^5.6.2","@types/jest":"^29.5.13","@types/node":"^22.7.5","npm-run-all":"^4.1.5","@rollup/plugin-terser":"^0.4.4","jest-environment-jsdom":"^29.7.0","@rollup/plugin-commonjs":"^28.0.0","@rollup/plugin-node-resolve":"^15.3.0"},"_npmOperationalInternal":{"tmp":"tmp/file-selector_2.1.2_1732705744037_0.08268419329475218","host":"s3://npm-registry-packages"},"readme":"<p align=\"center\">\n  <img src=\"https://raw.githubusercontent.com/react-dropzone/.github/main/brand/assets/logo.png\" alt=\"file-selector logo\" width=\"120\" />\n</p>\n\n# file-selector\n\n> A small package for converting a [DragEvent](https://developer.mozilla.org/en-US/docs/Web/API/DragEvent) or [file input](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/file) to a list of File objects.\n\n📖 **[Documentation & live playground →](https://react-dropzone.github.io/file-selector/)**\n\n[![npm](https://img.shields.io/npm/v/file-selector.svg?style=flat-square)](https://www.npmjs.com/package/file-selector)\n![Tests](https://img.shields.io/github/actions/workflow/status/react-dropzone/file-selector/test.yml?branch=main&style=flat-square&label=tests)\n[![coverage](https://img.shields.io/coveralls/github/react-dropzone/file-selector/main?style=flat-square)](https://coveralls.io/github/react-dropzone/file-selector?branch=main)\n[![Open Collective Backers](https://img.shields.io/opencollective/backers/react-dropzone.svg?style=flat-square)](#backers)\n[![Open Collective Sponsors](https://img.shields.io/opencollective/sponsors/react-dropzone.svg?style=flat-square)](#sponsors)\n[![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-2.1-4baaaa.svg?style=flat-square)](https://github.com/react-dropzone/.github/blob/main/CODE_OF_CONDUCT.md)\n\n# Table of Contents\n\n- [Installation](#installation)\n- [Usage](#usage)\n- [Browser Support](#browser-support)\n- [Contribute](#contribute)\n- [Credits](#credits)\n- [Support](#support)\n- [License](#license)\n\n## Installation\n\nYou can install this package from [NPM](https://www.npmjs.com):\n\n```bash\nnpm add file-selector\n```\n\n### CDN\n\nFor CDN usage, load the ESM build directly from a CDN such as [esm.sh](https://esm.sh) or [jsDelivr](https://www.jsdelivr.com/package/npm/file-selector):\n\n```html\n<script type=\"module\">\n  import {fromEvent} from \"https://esm.sh/file-selector\";\n\n  document.addEventListener(\"drop\", async evt => {\n    const files = await fromEvent(evt);\n    console.log(files);\n  });\n</script>\n```\n\n## Usage\n\n### ES6\n\nConvert a [DragEvent](https://developer.mozilla.org/en-US/docs/Web/API/DragEvent) to File objects:\n\n```ts\nimport {fromEvent} from \"file-selector\";\ndocument.addEventListener(\"drop\", async evt => {\n  const files = await fromEvent(evt);\n  console.log(files);\n});\n```\n\nConvert a [change event](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/change_event) for an input type file to File objects:\n\n```ts\nimport {fromEvent} from \"file-selector\";\nconst input = document.getElementById(\"myInput\");\ninput.addEventListener(\"change\", async evt => {\n  const files = await fromEvent(evt);\n  console.log(files);\n});\n```\n\nConvert [FileSystemFileHandle](https://developer.mozilla.org/en-US/docs/Web/API/FileSystemFileHandle) items to File objects:\n\n```ts\nimport {fromEvent} from \"file-selector\";\n\n// Open file picker\nconst handles = await window.showOpenFilePicker({multiple: true});\n// Get the files\nconst files = await fromEvent(handles);\nconsole.log(files);\n```\n\n**NOTE** The above is experimental and subject to change.\n\n### CommonJS\n\nConvert a `DragEvent` to File objects:\n\n```ts\nconst {fromEvent} = require(\"file-selector\");\ndocument.addEventListener(\"drop\", async evt => {\n  const files = await fromEvent(evt);\n  console.log(files);\n});\n```\n\n### MIME types\n\nWhen the browser doesn't set a File's `type`, `fromEvent` infers one from the file extension. By default it uses a small built-in table of the most common types, keeping the bundle lean.\n\nIf you need broader coverage, import the full extension-to-MIME table from the `file-selector/mime` subpath and pass it via the `mimeTypes` option. Because it's a separate entry point, the full table (~1,200 entries) is only included in your bundle when you import it:\n\n```ts\nimport {fromEvent} from \"file-selector\";\nimport {COMMON_MIME_TYPES} from \"file-selector/mime\";\n\nconst files = await fromEvent(evt, {mimeTypes: COMMON_MIME_TYPES});\n```\n\nYou can also pass your own `Map<extension, mimeType>` to restrict or extend the lookup:\n\n```ts\nconst files = await fromEvent(evt, {mimeTypes: new Map([[\"dwg\", \"image/vnd.dwg\"]])});\n```\n\n## Browser Support\n\nMost browser support basic File selection with drag 'n' drop or file input:\n\n- [File API](https://developer.mozilla.org/en-US/docs/Web/API/File#Browser_compatibility)\n- [Drag Event](https://developer.mozilla.org/en-US/docs/Web/API/DragEvent#Browser_compatibility)\n- [DataTransfer](https://developer.mozilla.org/en-US/docs/Web/API/DataTransfer#Browser_compatibility)\n- [`<input type=\"file\">`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/file#Browser_compatibility)\n\nFor folder drop we use the [FileSystem API](https://developer.mozilla.org/en-US/docs/Web/API/FileSystem) which has very limited support:\n\n- [DataTransferItem.getAsFile()](https://developer.mozilla.org/en-US/docs/Web/API/DataTransferItem/getAsFile#Browser_compatibility)\n- [DataTransferItem.webkitGetAsEntry()](https://developer.mozilla.org/en-US/docs/Web/API/DataTransferItem/webkitGetAsEntry#Browser_compatibility)\n- [FileSystemEntry](https://developer.mozilla.org/en-US/docs/Web/API/FileSystemEntry#Browser_compatibility)\n- [FileSystemFileEntry.file()](https://developer.mozilla.org/en-US/docs/Web/API/FileSystemFileEntry/file#Browser_compatibility)\n- [FileSystemDirectoryEntry.createReader()](https://developer.mozilla.org/en-US/docs/Web/API/FileSystemDirectoryEntry/createReader#Browser_compatibility)\n- [FileSystemDirectoryReader.readEntries()](https://developer.mozilla.org/en-US/docs/Web/API/FileSystemDirectoryReader/readEntries#Browser_compatibility)\n\n## Contribute\n\nCheckout the organization [CONTRIBUTING.md](https://github.com/react-dropzone/.github/blob/main/CONTRIBUTING.md).\n\n### Development\n\nDevelopment requires [Node.js](https://nodejs.org) >= 20. Install the dependencies with:\n\n```bash\nnpm install\n```\n\nThe project is built with [tsdown](https://tsdown.dev) (Rolldown), type-checked with [TypeScript](https://www.typescriptlang.org), tested with [Vitest](https://vitest.dev) and linted/formatted with [oxlint](https://oxc.rs) and [oxfmt](https://oxc.rs).\n\n| Command                   | Description                                                                      |\n| ------------------------- | -------------------------------------------------------------------------------- |\n| `npm test`                | Run the test suite in watch mode.                                                |\n| `npm run test:cov`        | Run the tests once with coverage (runs type-check, lint and format check first). |\n| `npm run type-check`      | Type-check the sources without emitting.                                         |\n| `npm run lint`            | Lint the sources (oxlint).                                                       |\n| `npm run lint:fix`        | Apply safe lint fixes.                                                           |\n| `npm run lint:type-aware` | Type-aware lint via tsgolint (alpha).                                            |\n| `npm run format`          | Format the sources (oxfmt).                                                      |\n| `npm run format:check`    | Check formatting without writing.                                                |\n| `npm run build`           | Build the outputs into `dist/`.                                                  |\n| `npm run dev`             | Build in watch mode.                                                             |\n| `npm run docs:dev`        | Run the [Vocs](https://vocs.dev) docs site locally.                              |\n| `npm run docs:build`      | Build the docs site into `site/`.                                                |\n| `npm run docs:preview`    | Preview the built docs site.                                                     |\n| `npm run hooks:install`   | Install the git hooks (`prek install`).                                          |\n| `npm run hooks:run`       | Run every git hook over the whole repo.                                          |\n\nThe build emits into `dist/`:\n\n- `dist/index.js` — ES module\n- `dist/index.cjs` — CommonJS module\n- `dist/index.d.ts` — TypeScript declarations\n\n### Git hooks\n\nGit hooks are managed with [prek](https://github.com/j178/prek), a fast Rust drop-in for the [pre-commit](https://pre-commit.com) framework (configured in [`.pre-commit-config.yaml`](.pre-commit-config.yaml)). On commit they format and lint the staged files with oxfmt/oxlint, and check the message against [Conventional Commits](https://www.conventionalcommits.org) — the same convention [semantic-release](https://semantic-release.gitbook.io) uses to cut releases.\n\nprek is a standalone binary, so install it once (e.g. `uv tool install prek`, `brew install prek`, or see the [install docs](https://github.com/j178/prek#installation)). `npm install` then wires up the hooks automatically; run `npm run hooks:install` to (re)install them by hand. The hooks are optional — CI enforces the same lint, format and commit checks — but they catch issues before you push.\n\n## Credits\n\n- [html5-file-selector](https://github.com/quarklemotion/html5-file-selector)\n\n## Support\n\n### Backers\n\nSupport us with a monthly donation and help us continue our activities. [[Become a backer](https://opencollective.com/react-dropzone#backer)]\n\n<a href=\"https://opencollective.com/react-dropzone#backers\" target=\"_blank\"><img src=\"https://opencollective.com/react-dropzone/backers.svg?width=890\"></a>\n\n### Sponsors\n\nBecome a sponsor and get your logo on our README on Github with a link to your site. [[Become a sponsor](https://opencollective.com/react-dropzone#sponsor)]\n\n<a href=\"https://opencollective.com/react-dropzone#sponsors\" target=\"_blank\"><img src=\"https://opencollective.com/react-dropzone/sponsors.svg?width=890\"></a>\n\n## License\n\nMIT\n","publish_time":1732705744240,"maintainers":[{"name":"rolandjitsu","email":"rolandjitsu@gmail.com"}],"_cnpm_publish_time":1732705744240,"dist-tags":{"beta":"3.0.0-beta.6","latest":"5.0.3","release-0.1.x":"0.1.19","release-1.2.x":"1.2.0","release-2.1.x":"2.1.2"}}