forked from jonbrennecke/edflib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
60 lines (46 loc) · 1.08 KB
/
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/**
*
* Node JS extension to EDFLIB
*
* by @jonbrennecke
*
*/
(function ( mod ) {
if ( typeof module === "object" && typeof module.exports === "object" ) { // CommonJS, Node
module.exports = mod();
}
else
throw "This module is only supported on Node.js.";
})(function(){
// load the Native C++ V8 library
var Native = require( __dirname + '/src/node/build/Release/edflib' );
// TODO use harmony proxies here, because they're cooler
// but older versions of NW may not support Harmony
function EdfProxy ( path ) {
this.path = path;
this.edf = new Native.Edf(path);
}
EdfProxy.prototype = {
getHeader : function () {
var header = this.edf.getHeader();
// trim whitespace
Object.keys(header).forEach(function ( key ) {
if ( typeof header[key] === "string" ) {
header[key] = header[key].trim();
}
else {
header[key] = header[key].map(function ( val ) {
return val.trim();
});
}
});
return header;
},
getData : function ( index ) {
return this.edf.getData(index);
}
}
return {
"Edf" : EdfProxy
}
});