4.2.1 • Published 4 months ago

generic-file-validator v4.2.1

Weekly downloads
-
License
ISC
Repository
github
Last release
4 months ago

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

MediaExtension
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 nameDescriptionDefalut valueRequiredExample
fileThe file which you want to validatenulltruefile: file to be validated
mediaThe media type, it will whitelist all the supported extension[]required if 'whitelistExtension' is not passed in the functionmedia: 'image'
whitelistExtensionThe extension you want to whitelist irrespective of media[]required if 'media' is not passed in the functionwhitelistExtension: 'png', 'gif'
blacklistExtensionThe extension you want to blacklist irrespective of media[]falseblacklistExtension: 'tiff', 'pdf'
returnBase64Return base64 of the filetruefalsereturnBase64: 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 (
    <div className="App">
      <input type="file" onChange={handleChange} />
    </div>
  );
}

export default App;

Usefull Link

https://codesandbox.io/s/generic-file-validator-example-zjlyrm

4.2.1

4 months ago

4.2.0

10 months ago

4.1.0

10 months ago

4.0.0

10 months ago

3.1.1

10 months ago

3.1.0

10 months ago

3.0.0

10 months ago

2.0.0

10 months ago

1.1.2

10 months ago

1.1.1

10 months ago

1.1.0

10 months ago

1.0.1

10 months ago

1.0.0

10 months ago