@abhijith_213-/js-file-magic-number-checker
v1.1.0
Published
<h1 align="center">js-file-magic-number-checker</h1>
Downloads
15
Readme
Table of Contents
Functions
Functions getFileType(fileSignature: string): string
Returns the corresponding file type for a given magic number (file signature). getFileTypeFromEvent(event: Event): Promise
Returns a promise that resolves to the detected file type from a file input change event.
Installation
npm install @abhijith_213-/js-file-magic-number-checker
Usage
Import the necessary functions:
javascript
import { getFileTypeFromEvent } from '@abhijith_213-/js-file-magic-number-checker';
Use the getFileTypeFromEvent function to determine the file type from a file input change event:
javascript
import React, { useState } from 'react';
import { getFileTypeFromEvent } from '@abhijith_213-/js-file-magic-number-checker';
function App() {
const [fileType, setFileType] = useState('');
const handleFileChange = async (event) => {
const fileType = await getFileTypeFromEvent(event);
setFileType(fileType);
};
return (
<div>
<h1>File Magic Number Checker</h1>
<input type="file" onChange={handleFileChange} />
{fileType && <p>Detected File Type: {fileType}</p>}
</div>
);
}
export default App;