forked from jexamd/rest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmime.js
41 lines (36 loc) · 869 Bytes
/
mime.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/*
* Copyright 2014-2016 the original author or authors
* @license MIT, see LICENSE.txt for details
*
* @author Scott Andrews
*/
'use strict';
/**
* Parse a MIME type into it's constituent parts
*
* @param {string} mime MIME type to parse
* @return {{
* {string} raw the original MIME type
* {string} type the type and subtype
* {string} [suffix] mime suffix, including the plus, if any
* {Object} params key/value pair of attributes
* }}
*/
function parse(mime) {
var params, type;
params = mime.split(';');
type = params[0].trim().split('+');
return {
raw: mime,
type: type[0],
suffix: type[1] ? '+' + type[1] : '',
params: params.slice(1).reduce(function (params, pair) {
pair = pair.split('=');
params[pair[0].trim()] = pair[1] ? pair[1].trim() : void 0;
return params;
}, {})
};
}
module.exports = {
parse: parse
};