attr-accept is a lightweight JavaScript utility that implements the logic of the HTML5 `<input type="file">` `accept` attribute. It provides a function to programmatically check if a given `File` object matches the criteria specified by an `accept` string, which can include MIME types (e.g., `image/*`, `application/pdf`), file extensions (e.g., `.jpg`, `.png`), and wildcards. The current stable version is 2.2.5. The library maintains a steady, though not rapid, release cadence, primarily focusing on bug fixes and minor improvements. Its key differentiator is providing a robust, standalone, and browser-compatible implementation of a browser's native file acceptance logic, making it suitable for custom file upload components, especially in libraries like react-dropzone.
npm install attr-acceptVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to use the `attrAccept` function to validate different file types against various 'accept' attribute strings, including MIME types, extensions, and wildcards.
If your application relies on polyfills for older JavaScript features, ensure `core-js` or an alternative polyfill library is included as a direct dependency in your project.
Upgrade to `attr-accept@2.2.1` or newer to ensure proper ES module compatibility.
Update to `attr-accept@2.2.3` or later to correctly handle empty accept arrays (i.e., accept all files).
Upgrade to `attr-accept@2.2.2` or later for case-insensitive MIME type matching, which aligns with standard browser behavior.
For ES Modules: `import attrAccept from 'attr-accept';`. For CommonJS: `const attrAccept = require('attr-accept');`.Ensure you are on `attr-accept@2.2.3` or newer to benefit from fixes for case-insensitive MIME type checking and correct handling of empty `accept` parameters.
Upgrade to `attr-accept@2.2.1` or newer. If the problem persists, ensure your build tool (e.g., webpack, Rollup) is configured to transpile `node_modules` if targeting older environments that don't natively support ESM.
No dependency data recorded yet.