UNPKG

776 BJavaScriptView Raw
1export default function LOGStats(data, feed) {
2 if (this.isFirst()) {
3 this.stats = {
4 counter: 0,
5 maxLength: 0,
6 minLength: 1000000,
7 sumLength: 0,
8 avgLength: 0,
9 };
10 }
11 if (this.isLast()) {
12 this.stats.avgLength = this.stats.sumLength / this.stats.counter;
13 console.log('Statistics', this.stats);
14 } else {
15 const len = typeof data === 'object' ? Object.keys(data).length : data.length;
16 this.stats.counter += 1;
17 this.stats.sumLength += len;
18 if (len < this.stats.minLength) {
19 this.stats.minLength = len;
20 }
21 if (len > this.stats.maxLength) {
22 this.stats.maxLength = len;
23 }
24 }
25 feed.send(data);
26}