Skip to content

Commit

Permalink
feat: build iana data
Browse files Browse the repository at this point in the history
  • Loading branch information
JadsonLucena committed Mar 23, 2023
1 parent 3833294 commit aadb663
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions src/MimeTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,52 @@ class MimeTypes {

}

#loadIANA = async res => {

try {

return {
version: res.headers.get('last-modified'),
content: (await res.text()).split(/\n+/).slice(1).filter(line => !/^#.*/.test(line) && line.trim() != '').reduce((curr, line) => {

line = line.split(',');

if (line.length > 1) {

let extension = line[0].trim().toLowerCase();
let mimeType = line[1].trim().toLowerCase();

if (mimeType != '' && extension != '' && !/^.*(obsoleted?|deprecated?).*$/i.test(extension)) {

if (!(mimeType in curr)) {

curr[mimeType] = [ extension ];

} else if (!curr[mimeType].includes(extension)) {

curr[mimeType].push(extension);

}

}

}

return curr;

}, {})
};

} catch (err) {

console.error(err);

return null;

}

}

get list() {

return this.#mimeTypes;
Expand Down

0 comments on commit aadb663

Please sign in to comment.