ext-name
Advanced tools
Comparing version 4.0.0 to 4.1.0
23
index.js
'use strict'; | ||
const endsWith = require('ends-with'); | ||
const extList = require('ext-list'); | ||
@@ -8,5 +7,5 @@ const sortKeysLength = require('sort-keys-length'); | ||
const obj = sortKeysLength.desc(extList()); | ||
const ext = Object.keys(obj).filter(x => endsWith(str, x)); | ||
const ext = Object.keys(obj).find(x => str.endsWith(x)); | ||
if (!ext.length) { | ||
if (!ext) { | ||
return null; | ||
@@ -16,5 +15,19 @@ } | ||
return { | ||
ext: ext[0], | ||
mime: obj[ext[0]] | ||
ext, | ||
mime: obj[ext] | ||
}; | ||
}; | ||
module.exports.mime = str => { | ||
const obj = sortKeysLength.desc(extList()); | ||
const ext = Object.keys(obj).find(x => obj[x] === str); | ||
if (!ext) { | ||
return null; | ||
} | ||
return { | ||
ext, | ||
mime: obj[ext] | ||
}; | ||
}; |
{ | ||
"name": "ext-name", | ||
"version": "4.0.0", | ||
"version": "4.1.0", | ||
"description": "Get the file extension and MIME type from a file", | ||
@@ -27,3 +27,2 @@ "license": "MIT", | ||
"dependencies": { | ||
"ends-with": "^0.2.0", | ||
"ext-list": "^2.0.0", | ||
@@ -35,6 +34,3 @@ "sort-keys-length": "^1.0.0" | ||
"xo": "*" | ||
}, | ||
"xo": { | ||
"esnext": true | ||
} | ||
} |
@@ -20,5 +20,27 @@ # ext-name [![Build Status](https://travis-ci.org/kevva/ext-name.svg?branch=master)](https://travis-ci.org/kevva/ext-name) | ||
//=> {ext: 'tar', mime: 'application/x-tar'} | ||
console.log(extName.mime('application/x-tar')); | ||
//=> {ext: 'tar', mime: 'application/x-tar'} | ||
``` | ||
## API | ||
### extName(filename) | ||
#### filename | ||
Type: `string` | ||
Get the extension and MIME type from a filename. | ||
### extName.mime(mimetype) | ||
#### mimetype | ||
Type: `string` | ||
Get the extension and MIME type from a MIME type. | ||
## Related | ||
@@ -25,0 +47,0 @@ |
3186
2
25
54
- Removedends-with@^0.2.0
- Removedends-with@0.2.0(transitive)