Skip to content

Commit

Permalink
feat: get mime types from a filename
Browse files Browse the repository at this point in the history
  • Loading branch information
JadsonLucena committed Mar 23, 2023
1 parent daa0883 commit e6a423b
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/MimeTypes.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const fs = require('fs');
const { parse } = require('path');

class MimeTypes {

Expand All @@ -24,6 +25,26 @@ class MimeTypes {

}

get(path) {

let pathinfo = parse(path);
let extension = pathinfo.ext.replace('.', '').trim().toLowerCase();
let mimeTypes = [];

for (let mimeType in this.#mimeTypes) {

if (!mimeTypes.includes(mimeType) && this.#mimeTypes[mimeType].includes(extension)) {

mimeTypes.push(mimeType);

}

}

return mimeTypes;

}

}


Expand Down

0 comments on commit e6a423b

Please sign in to comment.