Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/suryakant2000/generic-file-validator
NPM package, for validating the file MIME type.
https://github.com/suryakant2000/generic-file-validator
filevalidator mime-type npm-package
Last synced: 23 days ago
JSON representation
NPM package, for validating the file MIME type.
- Host: GitHub
- URL: https://github.com/suryakant2000/generic-file-validator
- Owner: suryakant2000
- License: mit
- Created: 2023-07-14T18:04:23.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-07-31T18:50:38.000Z (over 1 year ago)
- Last Synced: 2024-12-08T09:17:17.025Z (about 2 months ago)
- Topics: filevalidator, mime-type, npm-package
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/generic-file-validator?activeTab=readme
- Size: 28.3 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# generic-file-validator
### What it does?
It checks the file MIME type, and validate it against the extension.### Install
```
npm i generic-file-validator
```### Supported media and extension
| Media | Extension |
| ------------- | ------------- |
| image | .jpg, .jpeg, .png, .gif, .webp, .tiff, .bmp |
| audio | .mp3, .oga, .wav, .mid, .midi |
| video | .mp4, .ogv, .avi, .mpeg, .webm, .mkv, .3gp |
| application | .doc, .docx, .xls, .xlsx, .ppt, .pptx, .zip, .apk, .pdf |
## User guide
### Props
| Props name | Description | Defalut value | Required | Example |
| ------------- | ------------- | ------------- | ------------- | ------------- |
| file | The file which you want to validate | null | true | file: file to be validated |
| media | The media type, it will whitelist all the supported extension | [] | required if 'whitelistExtension' is not passed in the function | media: ['image']
| whitelistExtension | The extension you want to whitelist irrespective of media | [] | required if 'media' is not passed in the function | whitelistExtension: ['png', 'gif'] |
| blacklistExtension | The extension you want to blacklist irrespective of media | [] | false | blacklistExtension: ['tiff', 'pdf'] |
| returnBase64 | Return base64 of the file | true | false | returnBase64: false |### Usage
Here is the example usage in react app.
```
import "./App.css";
import fileValidator from "generic-file-validator";function App() {
const handleChange = (e) => {
let file = e.target.files[0];fileValidator(
{
file: file,
media: ["image"],
whitelistExtension: ["jpg", "jpeg"],
blacklistExtension: ["png"],
},
callback
);
};const callback = (res) => {
console.log({ res });
};return (
);
}export default App;
```
### Usefull Link
https://codesandbox.io/s/generic-file-validator-example-zjlyrm