1.1.0 • Published 1 year ago

oro-mimetype v1.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

Oro Mimetype

Class OroMimetype is a wrapper of mmmagic to simplify their use.

mmmagic is a module for node.js that check the file mimetype by their content (not the extension).

npm install oro-mimetype

Examples:

const OMimetype = require( 'oro-mimetype' );

const response = await OMimeType.GetFromFilepath( 'image.png' );
// { status: true, filepath: 'image.png', mimetype: 'image/png' }

const response2 = await OMimeType.GetFromFilepath( 'file.pdf' );
// { status: true, filepath: 'file.pdf', mimetype: 'application/pdf' }

const response3 = await OMimeType.GetFromFilepath( 'file-not-exist.pdf' );
// { 
//   status: false, 
//   filepath: 'file-not-exist.pdf', 
//   msg: "Error: File not exists: 'file-not-exist.pdf'"
// }

const isImage = await OMimeType.IsImage( 'image.png' );
// { status: true, filepath: 'image.png', mimetype: 'image/png' }

const isImage2 = await OMimeType.IsImage( 'file.pdf' );
// { 
//   status: false, 
//   filepath: 'file.pdf', 
//   mimetype: 'application/pdf', 
//   failed: 'image', 
//   msg: "Error: File is not image: 'file.pdf'" 
// }

Methods

// TODO pending to be written