2.0.1 • Published 6 years ago
http-timing v2.0.1
http-timing
Generate the http timing(Server-Timing)

API
Constructor
The HTTPTiming constructor
optionsThe constructor optionsoptions.maxThe max time(ms), use for the time line bar, default is 10 * 1000options.sizeThe cache size, default is 10
const HTTPTiming = require('http-timing');
const httpTiming = new HTTPTiming({
max: 5 * 1000,
size: 5,
});add
Add the data to timing view, return function to change the value of data
dataThe setting of http timingdata.urlThe http request urldata.methodThe http request methoddata.statusThe http response statusdata.useThe http response timedata.serverTimingThe http server timing
const HTTPTiming = require('http-timing');
const httpTiming = new HTTPTiming();
const set = httpTiming.add({
method: 'GET',
url: '/users/me',
status: 200,
use: 3000,
serverTiming: 'A;dur=2521.46147;desc="/users/me",B;dur=102.022688;desc="getUser",C;dur=33.468153;desc="mongodb:get",D;dur=54.064163;desc="validate:user"',
});
set('use', 5000);
set({
use: 5000,
});get
Get the timing by index
indexthe timing index
const HTTPTiming = require('http-timing');
const httpTiming = new HTTPTiming();
httpTiming.add({
method: 'GET',
url: '/users/me',
status: 200,
use: 3000,
serverTiming: 'A;dur=2521.46147;desc="/users/me",B;dur=102.022688;desc"getUser",C;dur=33.468153;desc"mongodb:get",D;dur=54.064163;desc="validate:user"',
});
console.info(httpTiming.get(0));length
Get the cache length
const HTTPTiming = require('http-timing');
const httpTiming = new HTTPTiming();
// 0
console.info(httpTiming.length);empty
Remove all cache
const HTTPTiming = require('http-timing');
const httpTiming = new HTTPTiming();
httpTiming.add({
method: 'GET',
url: '/users/me',
status: 200,
use: 3000,
serverTiming: 'A;dur=2521.46147;desc="/users/me",B;dur=102.022688;desc="getUser",C;dur=33.468153;desc="mongodb:get",D;dur=54.064163;desc="validate:user"',
});
// 1
console.info(httpTiming.length)
httpTiming.empty();
// 0
console.info(httpTiming.length)toHTML
Get the html of http timing
const HTTPTiming = require('http-timing');
const httpTiming = new HTTPTiming();
httpTiming.add({
method: 'GET',
url: '/users/me',
status: 200,
use: 3000,
serverTiming: 'A;dur=2521.46147;desc="/users/me",B;dur=102.022688;desc="getUser",C;dur=33.468153;desc="mongodb:get",D;dur=54.064163;desc="validate:user"',
});
const html = httpTiming.toHTML();
console.info(html);License
MIT