forked from forwardemail/superagent
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.js
More file actions
47 lines (40 loc) · 838 Bytes
/
utils.js
File metadata and controls
47 lines (40 loc) · 838 Bytes
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
42
43
44
45
46
47
/**
* Generate a UID with the given `len`.
*
* @param {Number} len
* @return {String}
* @api private
*/
exports.uid = function(len){
var buf = ''
, chars = 'abcdefghijklmnopqrstuvwxyz123456789'
, nchars = chars.length;
while (len--) buf += chars[Math.random() * nchars | 0];
return buf;
};
/**
* Return the mime type for `str`.
*
* @param {String} str
* @return {String}
* @api private
*/
exports.type = function(str){
return str.split(/ *;/).shift();
};
/**
* Return header field parameters.
*
* @param {String} str
* @return {Object}
* @api private
*/
exports.params = function(str){
return str.split(/ *; */).reduce(function(obj, str){
var parts = str.split(/ *= */)
, key = parts.shift()
, val = parts.shift();
if (key && val) obj[key] = val;
return obj;
}, {});
};