forked from bigeasy/udt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers.js
65 lines (55 loc) · 1.78 KB
/
helpers.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
64
65
var __slice = [].slice;
module.exports = class Helpers {
static _check(ee, forward) {
return function (error) {
if (error) {
process.nextTick(function () {
ee.emit('error', error);
ee._destroy();
});
} else {
try {
forward.apply(null, __slice.call(arguments, 1));
} catch (error) {
ee.emit('error', error);
}
}
};
}
static validator(ee) {
return function (forward) {
return Helpers._check(ee, forward);
};
}
static die() {
console.log.apply(console, __slice.call(arguments, 0));
return process.exit(1);
}
static say() {
return console.log.apply(console, __slice.call(arguments, 0));
}
static extend(to, from) {
for (var key in from) to[key] = from[key];
return to;
}
static parseDotDecimal(quad) {
quad = quad.split('.');
for (var i = 3, address = 0; i >= 0; i--) {
address = address + quad[i] * Math.pow(256, i);
}
return address;
}
// Comparison operator generator for high-resolution time for use with heap.
static sooner(property) {
return function (a, b) {
if (a[property][0] < b[property][0]) return true;
if (a[property][0] > b[property][0]) return false;
return a[property][1] < b[property][1];
};
}
// better used on hrtime differences which will be much smaller numbers
// returns: decimal double representing the high resolution time in microseconds
static hrtimeToMicro(hrtime) {
return hrtime[0] * 1000000 + hrtime[1] / 1000;
}
};