index.js
function (mime) {

        var info = {
                type: UNKNOWN,
                format: RAW,
                guessed: true
            },
            match,
            base;

        // extract the mime base
        base = (base = mime.split(SEP)) && base[0] || E;

        // bail out on the mime types that are sure-shot ones with no ambiguity
        match = base.match(AUDIO_VIDEO_IMAGE_TEXT);
        if (match && match[1]) {
            info.type = info.format = match[1];

            // we do special kane matching to extract the format in case the match was text
            // this ensures that we get same formats like we will do in kane match later down the line
            if (info.type === TEXT) {
                match = mime.match(JSON_XML_SCRIPT_SIBLINGS);
                info.format = match && match[1] || PLAIN;
            }
            return info;
        }

        // we do a kane match on entire mime (not just base) to find texts
        match = mime.match(JSON_XML_SCRIPT_SIBLINGS);
        if (match && match[1]) {
            info.type = TEXT;
            info.format = match[1];
            return info;
        }

        // now we match the subtype having names from the sure shot bases
        match = mime.match(AUDIO_VIDEO_IMAGE_TEXT_SUBTYPE);
        if (match && match[1]) {
            info.type = info.format = match[1];
            return info;
        }

        // now that most text and sure-shot types and sub-types are out of our way, we detect standard bases
        // and rest are unknown
        match = base.match(APPLICATION_MESSAGE_MULTIPART);
        if (match && match[1]) {
            info.type = match[1];
            info.format = RAW;
            return info;
        }

        // at this point nothing has matched nothing. it is worth keeping a note of it
        info.orphan = true;
        return info;
    }
function (mime) {

        var info = {
                type: UNKNOWN,
                format: RAW,
                guessed: true
            },
            match,
            base;

        // extract the mime base
        base = (base = mime.split(SEP)) && base[0] || E;

        // bail out on the mime types that are sure-shot ones with no ambiguity
        match = base.match(AUDIO_VIDEO_IMAGE_TEXT);
        if (match && match[1]) {
            info.type = info.format = match[1];

            // we do special kane matching to extract the format in case the match was text
            // this ensures that we get same formats like we will do in kane match later down the line
            if (info.type === TEXT) {
                match = mime.match(JSON_XML_SCRIPT_SIBLINGS);
                info.format = match && match[1] || PLAIN;
            }
            return info;
        }

        // we do a kane match on entire mime (not just base) to find texts
        match = mime.match(JSON_XML_SCRIPT_SIBLINGS);
        if (match && match[1]) {
            info.type = TEXT;
            info.format = match[1];
            return info;
        }

        // now we match the subtype having names from the sure shot bases
        match = mime.match(AUDIO_VIDEO_IMAGE_TEXT_SUBTYPE);
        if (match && match[1]) {
            info.type = info.format = match[1];
            return info;
        }

        // now that most text and sure-shot types and sub-types are out of our way, we detect standard bases
        // and rest are unknown
        match = base.match(APPLICATION_MESSAGE_MULTIPART);
        if (match && match[1]) {
            info.type = match[1];
            info.format = RAW;
            return info;
        }

        // at this point nothing has matched nothing. it is worth keeping a note of it
        info.orphan = true;
        return info;
    }
function ( mime ) { var info = { type : UNKNOWN , format : RAW , guessed : true } , match , base ; // extract the mime base base = ( base = mime . split ( SEP ) ) && base [ 0 ] || E ; // bail out on the mime types that are sure-shot ones with no ambiguity match = base . match ( AUDIO_VIDEO_IMAGE_TEXT ) ; if ( match && match [ 1 ] ) { info . type = info . format = match [ 1 ] ; // we do special kane matching to extract the format in case the match was text // this ensures that we get same formats like we will do in kane match later down the line if ( info . type === TEXT ) { match = mime . match ( JSON_XML_SCRIPT_SIBLINGS ) ; info . format = match && match [ 1 ] || PLAIN ; } return info ; } // we do a kane match on entire mime (not just base) to find texts match = mime . match ( JSON_XML_SCRIPT_SIBLINGS ) ; if ( match && match [ 1 ] ) { info . type = TEXT ; info . format = match [ 1 ] ; return info ; } // now we match the subtype having names from the sure shot bases match = mime . match ( AUDIO_VIDEO_IMAGE_TEXT_SUBTYPE ) ; if ( match && match [ 1 ] ) { info . type = info . format = match [ 1 ] ; return info ; } // now that most text and sure-shot types and sub-types are out of our way, we detect standard bases // and rest are unknown match = base . match ( APPLICATION_MESSAGE_MULTIPART ) ; if ( match && match [ 1 ] ) { info . type = match [ 1 ] ; info . format = RAW ; return info ; } // at this point nothing has matched nothing. it is worth keeping a note of it info . orphan = true ; return info ; }
Attempts to guess the format by analysing mime type and not a db lookup
@private
@param {String} mime - contentType header value
@returns {Object}
Attempts to guess the format by analysing mime type and not a db lookup