
Product
Secure Your AI-Generated Code with Socket MCP
Socket MCP brings real-time security checks to AI-generated code, helping developers catch risky dependencies before they enter the codebase.
generic-file-validator
Advanced tools
It checks the file MIME type, and validate it against the extension.
npm i generic-file-validator
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 |
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 |
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 (
<div className="App">
<input type="file" onChange={handleChange} />
</div>
);
}
export default App;
https://codesandbox.io/s/generic-file-validator-example-zjlyrm
FAQs
This package is designed to check file (MIME) type
The npm package generic-file-validator receives a total of 8 weekly downloads. As such, generic-file-validator popularity was classified as not popular.
We found that generic-file-validator demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket MCP brings real-time security checks to AI-generated code, helping developers catch risky dependencies before they enter the codebase.
Security News
As vulnerability data bottlenecks grow, the federal government is formally investigating NIST’s handling of the National Vulnerability Database.
Research
Security News
Socket’s Threat Research Team has uncovered 60 npm packages using post-install scripts to silently exfiltrate hostnames, IP addresses, DNS servers, and user directories to a Discord-controlled endpoint.