module twilio-labs import { fromBuffer } from 'file-type' ; import mime from 'mime-types' ; import path from 'path' ; function hasExtension ( name ) { if ( typeof name === 'undefined' ) { return false ; } return path . extname ( name ) . length !== 0 ; } export param { ( string | Buffer ) } content returns { Promise < ( string | undefined ) > } export async function getContentType ( content , name ? ) { let contentType ; if ( content instanceof Buffer && ! hasExtension ( name ) ) { const type = await fromBuffer ( content ) ; if ( type ) { contentType = type . mime ; } } if ( name && ! contentType ) { contentType = mime . lookup ( name ) || undefined ; } return contentType ; }