{"name":"file-selector","version":"3.1.0","keywords":["drag-and-drop","html5","file-api","DataTransfer","File"],"author":{"name":"Roland Groza","email":"rolandjitsu@gmail.com"},"license":"MIT","_id":"file-selector@3.1.0","maintainers":[{"name":"rolandjitsu","email":"rolandjitsu@gmail.com"}],"homepage":"https://github.com/react-dropzone/file-selector","bugs":{"url":"https://github.com/react-dropzone/file-selector/issues"},"dist":{"shasum":"06a47f564b719fb37294770aac64fa46d2324675","tarball":"http://registry-npm.ywwl.com/file-selector/download/file-selector-3.1.0.tgz","fileCount":13,"integrity":"sha512-xPvt2Zk42VgcM9Klmq0gGhBvg1tpLfey6oWtX/gXCMp4d9LluaLaXM6RkXON5Au7T7hjBLqOgpHBcOT05r6rGw==","signatures":[{"sig":"MEYCIQCDKabsP0v9uJhHD3xZiT3go2TNZTVUcUGP3I8JxTS1VAIhAPuypnPZ26mbGTyVIX1rRTv9dtjh7TSIkEuzUNCixdEO","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/file-selector@3.1.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":350935,"size":76875,"noattachment":false,"key":"/file-selector/-/file-selector-3.1.0.tgz"},"main":"./dist/index.cjs","type":"module","types":"./dist/index.d.ts","module":"./dist/index.js","engines":{"node":">= 20"},"exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js","require":"./dist/index.cjs"},"./package.json":"./package.json"},"gitHead":"8b2c704fbfec62cf68b8678af6173f3490fe51a5","scripts":{"dev":"tsdown --watch","lint":"oxlint","test":"vitest","build":"tsdown","clean":"rm -rf dist","format":"oxfmt \"src/**/*.ts\" \"*.ts\"","lint:fix":"oxlint --fix","prebuild":"npm run clean","test:cov":"vitest run --coverage","type-check":"tsc --noEmit","pretest:cov":"npm run type-check && npm run lint && npm run format:check","format:check":"oxfmt --check \"src/**/*.ts\" \"*.ts\"","lint:type-aware":"oxlint --type-aware"},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:b6c9da15-f786-46b2-ba3b-b9c1b12e3b32"}},"repository":{"url":"git+https://github.com/react-dropzone/file-selector.git","type":"git"},"_npmVersion":"11.18.0","description":"Convert DataTransfer object to a list of File objects","directories":{},"sideEffects":false,"_nodeVersion":"22.23.1","publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"jsdom":"^29.1.1","oxfmt":"^0.58.0","oxlint":"^1.73.0","tsdown":"^0.22.4","vitest":"^4.1.10","typescript":"^7.0.2","@types/node":"^26.1.1","oxlint-tsgolint":"^0.24.0","@vitest/coverage-v8":"^4.1.10"},"_npmOperationalInternal":{"tmp":"tmp/file-selector_3.1.0_1783838312241_0.7478400866739192","host":"s3://npm-registry-packages-npm-production"},"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":1783838312435,"_cnpm_publish_time":1783838312435,"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"}}