forked from mattiasw/ExifReader
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
43 lines (35 loc) · 805 Bytes
/
index.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
42
43
/**
* Module dependencies.
*/
var ExifReader = require('./js/ExifReader').ExifReader;
/**
* Parse EXIF tags in `buf`.
*
* @param {ArrayBuffer} buf
* @return {Object}
* @api public
*/
module.exports = function(buf){
var exif = new ExifReader;
exif.load(buf);
var tags = exif.getAllTags();
var out = {};
for(var tag in tags) {
out[spaces(tag)] = tags[tag].description;
}
return out;
};
/**
* Convert camel-case to lowercase words
*
* @param {String} str
* @return {String}
* @api private
*/
function spaces(str) {
return str.replace(/([A-Z][a-z])|([a-z][A-Z])|([A-Z])/g, function(m) {
return (1 == m.length)
? m.toLowerCase()
: (m[0] == m[0].toUpperCase()) ? ' ' + m.toLowerCase() : m[0] + ' ' + m[1].toLowerCase()
}).replace(/^\s+|\s+$/g, '');
}