Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a new method to get all extensions. #26

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 21 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ exports.charset = charset
exports.charsets = { lookup: charset }
exports.contentType = contentType
exports.extension = extension
exports.allExtensions = allExtensions
exports.extensions = Object.create(null)
exports.lookup = lookup
exports.types = Object.create(null)
Expand Down Expand Up @@ -105,23 +106,38 @@ function contentType (str) {
*/

function extension (type) {
var extensions = allExtensions(type);

return extensions ? extensions[0] : extensions;
}

/**
* Get all the extensions for a MIME type.
*
* @param {string} type
* @return {boolean|Array}
*/

function allExtensions (type) {
if (!type || typeof type !== 'string') {
return false
return false;
}

// TODO: use media-typer
var match = extractTypeRegExp.exec(type)
var match = extractTypeRegExp.exec(type);

// get extensions
var exts = match && exports.extensions[match[1].toLowerCase()]
var exts = match && exports.extensions[match[1].toLowerCase()];

if (!exts || !exts.length) {
return false
return false;
}

return exts[0]
return exts;
}



/**
* Lookup the MIME type for a file path/extension.
*
Expand Down