Skip to content

Commit 2c85230

Browse files
committed
Prettier update
1 parent ce673e3 commit 2c85230

File tree

10 files changed

+38
-41
lines changed

10 files changed

+38
-41
lines changed

examples/express-example/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ const { statsMiddleware, getStats } = initStats({
55
endpointStats: true,
66
complexEndpoints: ['/user/:id'],
77
customStats: true,
8-
addHeader: true
8+
addHeader: true,
99
});
1010

1111
app.use(statsMiddleware);
1212
app.get('/', (req, res) => res.end('Hello'));
1313
app.get('/user/:id', (req, res) => res.end(`Hello ${req.params.id}`));
1414
app.get('/long', async (req, res) => {
1515
const measurement = req.startMeasurement('long');
16-
await new Promise(resolve => {
16+
await new Promise((resolve) => {
1717
setTimeout(resolve, 2000);
1818
});
1919
req.finishMeasurement(measurement);

examples/fastify-example/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const { statsMiddleware, getStats } = initStats({
55
endpointStats: true,
66
complexEndpoints: ['/user/:id'],
77
customStats: true,
8-
addHeader: true
8+
addHeader: true,
99
});
1010

1111
/*
@@ -20,7 +20,7 @@ fastify.get('/', (req, res) => res.send('Hello'));
2020
fastify.get('/user/:id', (req, res) => res.send(`Hello ${req.params.id}`));
2121
fastify.get('/long', async (req, res) => {
2222
const measurement = req.startMeasurement('long');
23-
await new Promise(resolve => {
23+
await new Promise((resolve) => {
2424
setTimeout(resolve, 2000);
2525
});
2626
req.finishMeasurement(measurement);

examples/koa-example/index.js

+7-10
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,27 @@ const { statsMiddleware, getStats } = initStats({
99
endpointStats: true,
1010
complexEndpoints: ['/user/:id'],
1111
customStats: true,
12-
addHeader: true
12+
addHeader: true,
1313
});
1414

1515
// Small modification is required to work with koa
1616
const koaStatsMiddleware = (ctx, next) =>
1717
statsMiddleware(ctx.req, ctx.res, next);
1818
koaStatsMiddleware._name = 'statsMiddleware';
1919

20-
router.get('/', ctx => (ctx.body = 'Hello'));
21-
router.get('/user/:id', ctx => (ctx.body = `Hello ${ctx.params.id}`));
22-
router.get('/long', async ctx => {
20+
router.get('/', (ctx) => (ctx.body = 'Hello'));
21+
router.get('/user/:id', (ctx) => (ctx.body = `Hello ${ctx.params.id}`));
22+
router.get('/long', async (ctx) => {
2323
const measurement = ctx.req.startMeasurement('long');
24-
await new Promise(resolve => {
24+
await new Promise((resolve) => {
2525
setTimeout(resolve, 2000);
2626
});
2727
ctx.req.finishMeasurement(measurement);
2828
ctx.body = 'Long job finished'; // eslint-disable-line require-atomic-updates
2929
});
30-
router.get('/stats', ctx => (ctx.body = getStats()));
30+
router.get('/stats', (ctx) => (ctx.body = getStats()));
3131

32-
app
33-
.use(koaStatsMiddleware)
34-
.use(router.routes())
35-
.use(router.allowedMethods());
32+
app.use(koaStatsMiddleware).use(router.routes()).use(router.allowedMethods());
3633

3734
app.listen(8080);
3835
console.log('Server listens at http://localhost:8080'); // eslint-disable-line no-console

examples/node-example/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const { statsMiddleware, getStats } = initStats({
55
endpointStats: true,
66
complexEndpoints: ['/user/:id'],
77
customStats: true,
8-
addHeader: true
8+
addHeader: true,
99
});
1010

1111
http
@@ -20,7 +20,7 @@ http
2020
return res.end(`Hello ${req.url.split('/user/')[1]}`);
2121
}
2222
const measurement = req.startMeasurement('long');
23-
await new Promise(resolve => {
23+
await new Promise((resolve) => {
2424
setTimeout(resolve, 2000);
2525
});
2626
req.finishMeasurement(measurement);

examples/polka-example/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const { statsMiddleware, getStats } = initStats({
66
endpointStats: true,
77
complexEndpoints: ['/user/:id'],
88
customStats: true,
9-
addHeader: true
9+
addHeader: true,
1010
});
1111

1212
polka()
@@ -15,7 +15,7 @@ polka()
1515
.get('/user/:id', (req, res) => send(res, 200, `Hello ${req.params.id}`))
1616
.get('/long', async (req, res) => {
1717
const measurement = req.startMeasurement('long');
18-
await new Promise(resolve => {
18+
await new Promise((resolve) => {
1919
setTimeout(resolve, 2000);
2020
});
2121
req.finishMeasurement(measurement);

examples/rayo-example/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const { statsMiddleware, getStats } = initStats({
55
endpointStats: true,
66
complexEndpoints: ['/user/:id'],
77
customStats: true,
8-
addHeader: true
8+
addHeader: true,
99
});
1010

1111
rayo({ port: 8080 })
@@ -14,7 +14,7 @@ rayo({ port: 8080 })
1414
.get('/user/:id', (req, res) => res.end(`Hello ${req.params.id}`))
1515
.get('/long', async (req, res) => {
1616
const measurement = req.startMeasurement('long');
17-
await new Promise(resolve => {
17+
await new Promise((resolve) => {
1818
setTimeout(resolve, 2000);
1919
});
2020
req.finishMeasurement(measurement);

index.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ function initMiddleware(opts = {}) {
1212
pid: process.pid,
1313
totalTime: 0,
1414
averageTime: 0,
15-
count: 0
15+
count: 0,
1616
};
1717

1818
const statusCodes = {};
1919
const endpointStats = {};
2020
const complexEndpoints =
2121
(opts.complexEndpoints &&
22-
opts.complexEndpoints.map(path => ({ ...regexparam(path), path }))) ||
22+
opts.complexEndpoints.map((path) => ({ ...regexparam(path), path }))) ||
2323
[];
2424
const customStats = {};
2525

@@ -28,7 +28,7 @@ function initMiddleware(opts = {}) {
2828
uptime: process.uptime() * 1e3, // convert to ms
2929
uptimeHumanReadable: prettyTime(Math.floor(process.uptime() * 1e9)),
3030
statusCodes,
31-
...stats
31+
...stats,
3232
};
3333
if (opts.endpointStats) {
3434
result.endpointStats = endpointStats;
@@ -45,7 +45,7 @@ function initMiddleware(opts = {}) {
4545
totalTime: 0,
4646
averageTime: 0,
4747
started: 0,
48-
count: 0
48+
count: 0,
4949
};
5050
}
5151
customStats[name].started++;
@@ -88,7 +88,7 @@ function initMiddleware(opts = {}) {
8888
// prefer using `req.originalUrl` as some frameworks replace `req.url`
8989
const url = req.originalUrl || req.url;
9090
let path = urlParse(url).pathname;
91-
const complexPath = complexEndpoints.find(endpoint =>
91+
const complexPath = complexEndpoints.find((endpoint) =>
9292
endpoint.pattern.test(path)
9393
);
9494
path = complexPath ? complexPath.path : path;
@@ -99,7 +99,7 @@ function initMiddleware(opts = {}) {
9999
totalTime: 0,
100100
averageTime: 0,
101101
count: 0,
102-
statusCodes: {}
102+
statusCodes: {},
103103
};
104104
}
105105

package-lock.json

+5-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
"eslint-plugin-prettier": "^3.1.2",
5353
"husky": "^4.2.3",
5454
"nyc": "^15.0.0",
55-
"prettier": "^1.19.1",
55+
"prettier": "^2.0.4",
5656
"pretty-quick": "^2.0.1",
5757
"supertest": "^4.0.2"
5858
}

test.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ const http = require('http');
66
const initStats = require('.');
77
const { hrTimeToMs } = require('./utils');
88

9-
test('initMiddleware returns getStats and statsMiddleware', t => {
9+
test('initMiddleware returns getStats and statsMiddleware', (t) => {
1010
const { getStats, statsMiddleware } = initStats();
1111
t.is(typeof getStats, 'function');
1212
t.is(typeof statsMiddleware, 'function');
1313
});
1414

15-
test('getStats returns a correct object', t => {
15+
test('getStats returns a correct object', (t) => {
1616
const { getStats } = initStats();
1717
const stats = getStats();
1818
t.is(typeof stats.uptime, 'number');
@@ -29,7 +29,7 @@ test('getStats returns a correct object', t => {
2929
t.is(typeof stats.customStats, 'undefined');
3030
});
3131

32-
test('statsMiddleware works', async t => {
32+
test('statsMiddleware works', async (t) => {
3333
const { getStats, statsMiddleware } = initStats();
3434
const server = createServer(statsMiddleware);
3535

@@ -52,7 +52,7 @@ test('statsMiddleware works', async t => {
5252
t.deepEqual(stats.statusCodes, { 200: 2 });
5353
});
5454

55-
test('endpointStats option works', async t => {
55+
test('endpointStats option works', async (t) => {
5656
const { getStats, statsMiddleware } = initStats({ endpointStats: true });
5757
const server = createServer(statsMiddleware);
5858

@@ -78,10 +78,10 @@ test('endpointStats option works', async t => {
7878
t.deepEqual(endpointStat.statusCodes, { 200: 1 });
7979
});
8080

81-
test('complexEndpoints option works', async t => {
81+
test('complexEndpoints option works', async (t) => {
8282
const { getStats, statsMiddleware } = initStats({
8383
endpointStats: true,
84-
complexEndpoints: ['/user/:id']
84+
complexEndpoints: ['/user/:id'],
8585
});
8686
const server = createServer(statsMiddleware);
8787

@@ -99,7 +99,7 @@ test('complexEndpoints option works', async t => {
9999
t.deepEqual(endpointStat.statusCodes, { 200: 2 });
100100
});
101101

102-
test('customStats option works', t => {
102+
test('customStats option works', (t) => {
103103
const { getStats, statsMiddleware } = initStats({ customStats: true });
104104
const req = {};
105105
statsMiddleware(req, {}, () => {});
@@ -130,7 +130,7 @@ test('customStats option works', t => {
130130
t.is(customStat.count, 2);
131131
});
132132

133-
test('addHeader option works', async t => {
133+
test('addHeader option works', async (t) => {
134134
const { statsMiddleware } = initStats({ addHeader: true });
135135
const server = createServer(statsMiddleware);
136136

@@ -139,7 +139,7 @@ test('addHeader option works', async t => {
139139
t.assert(res.headers['x-response-time'].includes('ms'));
140140
});
141141

142-
test('utils.hrTimeToMs works correctly', t => {
142+
test('utils.hrTimeToMs works correctly', (t) => {
143143
t.is(hrTimeToMs([0, 0]), 0);
144144
t.is(hrTimeToMs([1, 0]), 1000); // 1st argument is a second 1s = 1000ms
145145
t.is(hrTimeToMs([0, 1]), 1e-6); // 2nd argument is a nanosecond 1ns = 1e-6ms

0 commit comments

Comments
 (0)