Skip to content

Commit 5cbc628

Browse files
committed
use arrow function where possible
1 parent 5eaf6e2 commit 5cbc628

File tree

11 files changed

+71
-92
lines changed

11 files changed

+71
-92
lines changed

biome.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@
3838
"noUnusedVariables": "error"
3939
},
4040
"complexity": {
41-
"noForEach": "off",
42-
"useArrowFunction": "off"
41+
"noForEach": "off"
4342
},
4443
"style": {
4544
"noParameterAssign": "off",

lib/service/osrm/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,14 @@ function init(options) {
102102
if (query.turnbyturn || query.path === pathType.smooth || query.path === pathType.coarse) {
103103
directions.segments = [];
104104
// copy segments from route to its own table
105-
directions.routes.forEach(function (route) {
105+
directions.routes.forEach(route => {
106106
route.segmentIndex = directions.segments.length;
107107
directions.segments = directions.segments.concat(route.segments);
108108
delete route.segments;
109109
});
110110
} else {
111111
// delete segments
112-
directions.routes.forEach(function (route) {
112+
directions.routes.forEach(route => {
113113
delete route.segments;
114114
});
115115
}

lib/service/util.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,7 @@ function isFuture(time) {
6464

6565
// like normal join but with optional filter fn
6666
function join(arr, conn, fn) {
67-
fn =
68-
fn ||
69-
function (it) {
70-
return it;
71-
};
67+
fn = fn || (it => it);
7268
return arr.filter(fn).join(conn);
7369
}
7470

@@ -77,7 +73,7 @@ function last(arr) {
7773
}
7874

7975
function split2object(str, conn, obj) {
80-
return str.split(conn || '-').reduce(function (result, word) {
76+
return str.split(conn || '-').reduce((result, word) => {
8177
result[word] = word;
8278
return result;
8379
}, obj || {});

test/directions.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,25 +23,25 @@ function timeService(millis, success = true) {
2323
}
2424
}
2525

26-
describe('furkot-directions node module', async function () {
27-
await it('no input', async function () {
26+
describe('furkot-directions node module', async () => {
27+
await it('no input', async () => {
2828
const result = await furkotDirections()();
2929
should.not.exist(result);
3030
});
3131

32-
await it('empty input', async function () {
32+
await it('empty input', async () => {
3333
const result = await furkotDirections()({});
3434
should.not.exist(result);
3535
});
3636

37-
await it('one point', async function () {
37+
await it('one point', async () => {
3838
const result = await furkotDirections()({
3939
points: [[0, 0]]
4040
});
4141
should.not.exist(result);
4242
});
4343

44-
await it('no service', async function () {
44+
await it('no service', async () => {
4545
const result = await furkotDirections({
4646
services: []
4747
})({
@@ -54,7 +54,7 @@ describe('furkot-directions node module', async function () {
5454
result.should.have.property('routes').with.length(1);
5555
});
5656

57-
await it('service', async function () {
57+
await it('service', async () => {
5858
const query = {
5959
points: [
6060
[0, 0],
@@ -77,15 +77,15 @@ describe('furkot-directions node module', async function () {
7777
result.should.have.property('query', query);
7878
});
7979

80-
await it('only enabled services', function () {
80+
await it('only enabled services', () => {
8181
const options = {
8282
valhalla_enable() {}
8383
};
8484
const directions = furkotDirections(options);
8585
directions.options.should.have.property('services').with.length(1);
8686
});
8787

88-
await it('override provider name', function () {
88+
await it('override provider name', () => {
8989
const options = {
9090
order: ['stadiamaps'],
9191
stadiamaps: 'valhalla',
@@ -95,7 +95,7 @@ describe('furkot-directions node module', async function () {
9595
directions.options.should.have.property('services').with.length(1);
9696
});
9797

98-
await it('timeout', async function () {
98+
await it('timeout', async () => {
9999
const promise = furkotDirections({
100100
services: [
101101
{
@@ -122,7 +122,7 @@ describe('furkot-directions node module', async function () {
122122
});
123123
});
124124

125-
await it('abort', async function () {
125+
await it('abort', async () => {
126126
const ac = new AbortController();
127127
const promise = furkotDirections({
128128
services: [

test/service/graphhopper/index.js

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const should = require('should');
33
const { directionsQuery, pathType } = require('../../../lib/model');
44
const graphhopper = require('../../../lib/service/graphhopper');
55

6-
describe('graphhopper directions', async function () {
6+
describe('graphhopper directions', async () => {
77
let response;
88

99
const directions = graphhopper({
@@ -15,7 +15,7 @@ describe('graphhopper directions', async function () {
1515
}
1616
}).operation;
1717

18-
await it('test', async function () {
18+
await it('test', async () => {
1919
response = require('./fixtures/response');
2020

2121
const query = {
@@ -42,7 +42,7 @@ describe('graphhopper directions', async function () {
4242
result.should.have.property('provider', 'graphhopper');
4343
});
4444

45-
await it('turn-by-turn', async function () {
45+
await it('turn-by-turn', async () => {
4646
response = require('./fixtures/turnbyturn');
4747

4848
const query = {
@@ -72,15 +72,11 @@ describe('graphhopper directions', async function () {
7272
result.segments[0].should.have.property('distance', 508);
7373
result.segments[0].should.have.property('path').with.length(13);
7474
result.segments[0].should.have.property('instructions', 'Continue');
75-
result.segments
76-
.reduce(function (len, seg) {
77-
return len + seg.path.length - 1;
78-
}, 0)
79-
.should.equal(5749);
75+
result.segments.reduce((len, seg) => len + seg.path.length - 1, 0).should.equal(5749);
8076
result.should.have.property('provider', 'graphhopper');
8177
});
8278

83-
await it('ferry', async function () {
79+
await it('ferry', async () => {
8480
response = require('./fixtures/ferry');
8581

8682
const query = {
@@ -108,7 +104,7 @@ describe('graphhopper directions', async function () {
108104
result.should.have.property('provider', 'graphhopper');
109105
});
110106

111-
await it('other ferry', async function () {
107+
await it('other ferry', async () => {
112108
response = require('./fixtures/ferry-2');
113109

114110
const query = {
@@ -132,7 +128,7 @@ describe('graphhopper directions', async function () {
132128
result.should.have.property('provider', 'graphhopper');
133129
});
134130

135-
await it('rough surface', async function () {
131+
await it('rough surface', async () => {
136132
response = require('./fixtures/rough');
137133

138134
const query = {
@@ -180,7 +176,7 @@ describe('graphhopper directions', async function () {
180176
result.should.have.property('provider', 'graphhopper');
181177
});
182178

183-
await it('toll roads', async function () {
179+
await it('toll roads', async () => {
184180
response = require('./fixtures/tolls');
185181

186182
const query = {

test/service/index.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ const service = require('../../lib/service');
44
const status = require('../../lib/service/status');
55
const util = require('../../lib/service/util');
66

7-
describe('service', function () {
7+
describe('service', () => {
88
let s;
99
let st;
1010
let reqTimeout;
1111
let reqResponse;
1212
const timeout = 200;
1313

14-
beforeEach(function () {
14+
beforeEach(() => {
1515
st = [];
1616
reqResponse = 'response';
1717
reqTimeout = 1;
@@ -38,7 +38,7 @@ describe('service', function () {
3838
}).operation;
3939
});
4040

41-
it('success', async function () {
41+
it('success', async () => {
4242
const result = await s({
4343
points: [
4444
[0, 0],
@@ -48,7 +48,7 @@ describe('service', function () {
4848
result.should.equal('response');
4949
});
5050

51-
it('request later', async function () {
51+
it('request later', async () => {
5252
st = [status.error];
5353
const result = await s({
5454
points: [
@@ -59,7 +59,7 @@ describe('service', function () {
5959
result.should.equal('response');
6060
});
6161

62-
it('cascade to next service', async function () {
62+
it('cascade to next service', async () => {
6363
reqResponse = undefined;
6464
const result = await s({
6565
points: [

test/service/mapquest/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ const directions = mapquest({
1313
}
1414
}).operation;
1515

16-
describe('mapquest directions', async function () {
17-
await it('test', async function () {
16+
describe('mapquest directions', async () => {
17+
await it('test', async () => {
1818
response = require('./fixtures/turnbyturn');
1919

2020
const query = {
@@ -51,8 +51,8 @@ describe('mapquest directions', async function () {
5151
});
5252
});
5353

54-
describe('open mapquest directions', async function () {
55-
await it('test', async function () {
54+
describe('open mapquest directions', async () => {
55+
await it('test', async () => {
5656
response = require('./fixtures/response');
5757

5858
const query = {

test/service/openroute/index.js

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ const directions = openroute({
1313
}
1414
}).operation;
1515

16-
describe('openroute directions', async function () {
17-
await it('turn-by-turn', async function () {
16+
describe('openroute directions', async () => {
17+
await it('turn-by-turn', async () => {
1818
response = require('./fixtures/turnbyturn');
1919

2020
const query = {
@@ -42,15 +42,11 @@ describe('openroute directions', async function () {
4242
result.segments[0].should.have.property('distance', 2226);
4343
result.segments[0].should.have.property('path').with.length(42);
4444
result.segments[0].should.have.property('instructions', 'Head south on K 7931');
45-
result.segments
46-
.reduce(function (len, seg) {
47-
return len + seg.path.length - 1;
48-
}, 0)
49-
.should.equal(7964);
45+
result.segments.reduce((len, seg) => len + seg.path.length - 1, 0).should.equal(7964);
5046
result.should.have.property('provider', 'openroute');
5147
});
5248

53-
await it('empty', async function () {
49+
await it('empty', async () => {
5450
response = require('./fixtures/empty');
5551

5652
const query = {
@@ -78,15 +74,11 @@ describe('openroute directions', async function () {
7874
result.segments[0].should.have.property('distance', 0);
7975
result.segments[0].should.have.property('path').with.length(0);
8076
result.segments[0].should.have.property('instructions', 'Head east');
81-
result.segments
82-
.reduce(function (len, seg) {
83-
return len + seg.path.length;
84-
}, 0)
85-
.should.equal(0);
77+
result.segments.reduce((len, seg) => len + seg.path.length, 0).should.equal(0);
8678
result.should.have.property('provider', 'openroute');
8779
});
8880

89-
await it('ferry', async function () {
81+
await it('ferry', async () => {
9082
response = require('./fixtures/ferry');
9183

9284
const query = {
@@ -122,7 +114,7 @@ describe('openroute directions', async function () {
122114
result.should.have.property('provider', 'openroute');
123115
});
124116

125-
await it('too long roundabout route', async function () {
117+
await it('too long roundabout route', async () => {
126118
response = require('./fixtures/roundabout-too-long');
127119

128120
const query = {
@@ -135,7 +127,7 @@ describe('openroute directions', async function () {
135127
should.not.exist(result);
136128
});
137129

138-
await it('rough surface', async function () {
130+
await it('rough surface', async () => {
139131
response = require('./fixtures/rough');
140132

141133
const query = {
@@ -166,7 +158,7 @@ describe('openroute directions', async function () {
166158
result.should.have.property('provider', 'openroute');
167159
});
168160

169-
await it('toll roads', async function () {
161+
await it('toll roads', async () => {
170162
response = require('./fixtures/tolls');
171163

172164
const query = {

test/service/osrm/index.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ const should = require('should');
44
const osrm = require('../../../lib/service/osrm');
55
const model = require('../../../lib/model');
66

7-
describe('osrm', async function () {
8-
await it('should return turnbyturn directions', async function (t) {
9-
const request = t.mock.fn(undefined, async () => {
10-
return { response: require('./fixtures/turnbyturn.json') };
11-
});
7+
describe('osrm', async () => {
8+
await it('should return turnbyturn directions', async t => {
9+
const request = t.mock.fn(undefined, async () => ({
10+
response: require('./fixtures/turnbyturn.json')
11+
}));
1212

1313
const directions = osrm({
1414
name: 'osrm',
@@ -34,7 +34,7 @@ describe('osrm', async function () {
3434

3535
result.should.have.property('routes').with.length(2);
3636

37-
result.routes.forEach(function (route) {
37+
result.routes.forEach(route => {
3838
route.should.have.property('distance').which.is.Number();
3939
route.should.have.property('duration').which.is.Number();
4040
route.should.have.property('path').which.is.Array();
@@ -44,7 +44,7 @@ describe('osrm', async function () {
4444

4545
result.should.have.property('segments').which.is.Array();
4646

47-
result.segments.forEach(function (segment) {
47+
result.segments.forEach(segment => {
4848
segment.should.have.property('distance').which.is.Number();
4949
segment.should.have.property('duration').which.is.Number();
5050
segment.should.have.property('path').which.is.Array();
@@ -63,10 +63,10 @@ describe('osrm', async function () {
6363
]);
6464
});
6565

66-
await it('should return zero results', async function (t) {
67-
const request = t.mock.fn(undefined, async () => {
68-
return { response: require('./fixtures/zeroresults.json') };
69-
});
66+
await it('should return zero results', async t => {
67+
const request = t.mock.fn(undefined, async () => ({
68+
response: require('./fixtures/zeroresults.json')
69+
}));
7070

7171
const directions = osrm({
7272
name: 'osrm',

0 commit comments

Comments
 (0)