UNPKG

882 BJavaScriptView Raw
1'use strict';
2
3var extend = require('xtend');
4var humanize = require('humanize-duration');
5
6module.exports = function humanize(stats) {
7 return _humanize(extend({}, stats), false);
8};
9
10function _humanize(o, isNs, key) {
11 switch (typeof o) {
12
13 case 'object':
14 Object.keys(o).forEach(function(key) {
15 if (key == 'latencyNs') {
16 o['latency'] = _humanize(o[key], true, key);
17 delete o[key];
18 } else {
19 o[key] = _humanize(o[key], isNs, key);
20 }
21 });
22 break;
23
24 case 'number':
25 if (isNs) {
26 if (key == 'variance') {
27 o = Math.round(o / 1e6);
28 } else {
29 o = humanize(Math.round(o / 1e6));
30 }
31 } else if (key == 'percentage') {
32 o = Math.round(o * 100).toString() + '%';
33 } else {
34 o = Math.round(o * 10) / 10;
35 }
36
37 break;
38 }
39
40 return o;
41}