-
Notifications
You must be signed in to change notification settings - Fork 10
/
index.js
63 lines (53 loc) · 1.33 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
61
62
63
/**
* GEXF Library Node Bindings
* ===========================
*
* Author: PLIQUE Guillaume (Yomguithereal)
* URL: https://github.com/Yomguithereal/gexf
* Version: 0.2.3
*/
var DOMParser = require('xmldom').DOMParser,
DOMImplementation = require('xmldom').DOMImplementation,
XMLSerializer = require('xmldom').XMLSerializer,
parser = require('./src/parser.js'),
writer = require('./src/writer.js');
// Helpers
function isPlainObject(v) {
return v instanceof Object &&
!(v instanceof Array) &&
!(v instanceof Function);
}
function extend() {
var i,
k,
res = {},
l = arguments.length;
for (i = l - 1; i >= 0; i--)
for (k in arguments[i])
if (res[k] && isPlainObject(arguments[i][k]))
res[k] = extend(arguments[i][k], res[k]);
else
res[k] = arguments[i][k];
return res;
}
// Namespace
var gexf = {};
Object.defineProperty(gexf, 'version', {
value: '0.2.5'
});
gexf.parse = function(string) {
var p = new DOMParser();
var xml = p.parseFromString(string, 'application/xml');
return parser.parse(xml);
}
gexf.create = function(params) {
// Forcing implementation
return writer.create.call(writer, extend(
{
implementation: DOMImplementation.prototype,
serializer: XMLSerializer
},
params
));
}
module.exports = gexf;