Skip to content

Commit 1500c26

Browse files
committed
Update code style: arrow-parens
1 parent bda8388 commit 1500c26

11 files changed

+52
-52
lines changed

JavaScript/2-promise.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
// Pending
44

5-
const promise1 = new Promise(resolve => {
5+
const promise1 = new Promise((resolve) => {
66
setTimeout(() => {
77
resolve('value1');
88
}, 0);
@@ -12,7 +12,7 @@ promise1.then(console.log); // 'value1' (delayed)
1212

1313
// Immediate resolve
1414

15-
const promise2 = new Promise(resolve => resolve('value2'));
15+
const promise2 = new Promise((resolve) => resolve('value2'));
1616
console.dir({ promise2 }); // Promise { 'value2' }
1717
promise2.then(console.log); // 'value2'
1818

@@ -48,14 +48,14 @@ const readFile = (filename, encoding) =>
4848
}));
4949

5050
readFile('file1.txt', 'utf8')
51-
.then(data => {
51+
.then((data) => {
5252
console.log(data);
5353
return readFile('file2.txt', 'utf8');
5454
})
55-
.then(data => {
55+
.then((data) => {
5656
console.log(data);
5757
return readFile('file3.txt', 'utf8');
5858
})
59-
.then(data => {
59+
.then((data) => {
6060
console.log(data);
6161
});

JavaScript/3-promisify.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
const promisify = fn => (...args) => new Promise((resolve, reject) => {
3+
const promisify = (fn) => (...args) => new Promise((resolve, reject) => {
44
args.push((err, result) => {
55
if (err) reject(err);
66
else resolve(result);
@@ -13,18 +13,18 @@ const fs = require('fs');
1313
const readFile1 = promisify(fs.readFile);
1414

1515
readFile1('file1.txt', 'utf8')
16-
.then(data => {
16+
.then((data) => {
1717
console.log(data.toString());
1818
return readFile1('file2.txt', 'utf8');
1919
})
20-
.then(data => {
20+
.then((data) => {
2121
console.log(data.toString());
2222
return readFile1('file3.txt', 'utf8');
2323
})
24-
.then(data => {
24+
.then((data) => {
2525
console.log(data.toString());
2626
})
27-
.catch(err => {
27+
.catch((err) => {
2828
console.log(err);
2929
});
3030

@@ -33,17 +33,17 @@ const util = require('util');
3333
const readFile2 = util.promisify(fs.readFile);
3434

3535
readFile2('file1.txt', 'utf8')
36-
.then(data => {
36+
.then((data) => {
3737
console.log(data.toString());
3838
return readFile2('file2.txt', 'utf8');
3939
})
40-
.then(data => {
40+
.then((data) => {
4141
console.log(data.toString());
4242
return readFile2('file3.txt', 'utf8');
4343
})
44-
.then(data => {
44+
.then((data) => {
4545
console.log(data.toString());
4646
})
47-
.catch(err => {
47+
.catch((err) => {
4848
console.log(err);
4949
});

JavaScript/4-catch.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,37 @@
22

33
const fs = require('fs');
44

5-
const readTextFile = filename => fs.promises.readFile(filename, 'utf8');
5+
const readTextFile = (filename) => fs.promises.readFile(filename, 'utf8');
66

77
readTextFile('file1-.txt')
88
.then(
9-
data => {
9+
(data) => {
1010
console.dir({ file1: data });
1111
return readTextFile('file2.txt');
1212
},
13-
reason => {
13+
(reason) => {
1414
console.log('Cannot read file1.txt --- A');
1515
console.log(reason);
1616
}
1717
)
1818
.catch(
19-
reason => {
19+
(reason) => {
2020
console.log('Cannot read file1.txt --- B');
2121
console.log(reason);
2222
}
2323
)
24-
.then(data => {
24+
.then((data) => {
2525
console.dir({ file2: data });
2626
return readTextFile('file3.txt');
2727
})
28-
.catch(reason => {
28+
.catch((reason) => {
2929
console.log('Cannot read file2.txt');
3030
console.log(reason);
3131
})
32-
.then(data => {
32+
.then((data) => {
3333
console.dir({ file3: data });
3434
})
35-
.catch(reason => {
35+
.catch((reason) => {
3636
console.log('Cannot read file');
3737
console.log(reason);
3838
});

JavaScript/5-finally.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
const fs = require('fs');
44

5-
const readTextFile = filename => fs.promises.readFile(filename, 'utf8');
5+
const readTextFile = (filename) => fs.promises.readFile(filename, 'utf8');
66

77
readTextFile('file1-.txt')
8-
.then(data => {
8+
.then((data) => {
99
console.dir({ file1: data });
1010
})
11-
.catch(reason => {
11+
.catch((reason) => {
1212
console.log('Cannot read file1.txt');
1313
console.log(reason);
1414
})

JavaScript/6-fetch.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
const http = require('http');
44

5-
const fetch = url => new Promise((resolve, reject) => {
6-
http.get(url, res => {
5+
const fetch = (url) => new Promise((resolve, reject) => {
6+
http.get(url, (res) => {
77
const code = res.statusCode;
88
if (code !== 200) {
99
return reject(new Error(`HTTP status code ${code}`));
@@ -12,7 +12,7 @@ const fetch = url => new Promise((resolve, reject) => {
1212
res.on('error', reject);
1313

1414
const chunks = [];
15-
res.on('data', chunk => {
15+
res.on('data', (chunk) => {
1616
chunks.push(chunk);
1717
});
1818

JavaScript/7-http.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
const fetch = require('./6-fetch.js');
44

55
fetch('http://localhost:3000/person')
6-
.then(data => {
6+
.then((data) => {
77
console.log(data);
88
})
9-
.catch(err => {
9+
.catch((err) => {
1010
console.error(err);
1111
});

JavaScript/8-all.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ const promises = [
1111
];
1212

1313
Promise.all(promises)
14-
.then(values => {
14+
.then((values) => {
1515
console.log(values);
1616
})
17-
.catch(err => {
17+
.catch((err) => {
1818
console.log(err);
1919
});

JavaScript/9-race.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ const promises = [
1111
];
1212

1313
Promise.race(promises)
14-
.then(res => {
14+
.then((res) => {
1515
console.log(res);
1616
})
17-
.catch(err => {
17+
.catch((err) => {
1818
console.log(err);
1919
});

JavaScript/a-thenable.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class Thenable {
1919
if (fn) {
2020
const next = fn(value);
2121
if (next) {
22-
next.then(value => {
22+
next.then((value) => {
2323
this.next.resolve(value);
2424
});
2525
}
@@ -29,7 +29,7 @@ class Thenable {
2929

3030
// Usage
3131

32-
const readFile = filename => {
32+
const readFile = (filename) => {
3333
const thenable = new Thenable();
3434
fs.readFile(filename, 'utf8', (err, data) => {
3535
if (err) throw err;
@@ -39,14 +39,14 @@ const readFile = filename => {
3939
};
4040

4141
readFile('file1.txt')
42-
.then(data => {
42+
.then((data) => {
4343
console.dir({ file1: data });
4444
return readFile('file2.txt');
4545
})
46-
.then(data => {
46+
.then((data) => {
4747
console.dir({ file2: data });
4848
return readFile('file3.txt');
4949
})
50-
.then(data => {
50+
.then((data) => {
5151
console.dir({ file3: data });
5252
});

JavaScript/b-expirable.js

+12-12
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ const PROMISE_TIMEOUT = 1000;
55
class Expirable {
66
constructor(executor) {
77
const promise = new Promise((resolve, reject) => {
8-
executor(val => {
8+
executor((val) => {
99
if (this.expired) return;
1010
clearTimeout(this.timer);
1111
resolve(val);
12-
}, err => {
12+
}, (err) => {
1313
if (this.expired) return;
1414
clearTimeout(this.timer);
1515
reject(err);
@@ -28,42 +28,42 @@ class Expirable {
2828

2929
// Usage
3030

31-
new Expirable(resolve => {
31+
new Expirable((resolve) => {
3232
setTimeout(() => {
3333
resolve('Resolved before timeout');
3434
}, 100);
35-
}).then(data => {
35+
}).then((data) => {
3636
console.dir({ data });
37-
}).catch(error => {
37+
}).catch((error) => {
3838
console.dir({ error: error.message });
3939
});
4040

4141
new Expirable((resolve, reject) => {
4242
setTimeout(() => {
4343
reject(new Error('Something went wrong'));
4444
}, 100);
45-
}).then(data => {
45+
}).then((data) => {
4646
console.dir({ data });
47-
}).catch(error => {
47+
}).catch((error) => {
4848
console.dir({ error: error.message });
4949
});
5050

51-
new Expirable(resolve => {
51+
new Expirable((resolve) => {
5252
setTimeout(() => {
5353
resolve('Never resolved before timeout');
5454
}, 2000);
55-
}).then(data => {
55+
}).then((data) => {
5656
console.dir({ data });
57-
}).catch(error => {
57+
}).catch((error) => {
5858
console.dir({ error: error.message });
5959
});
6060

6161
new Expirable((resolve, reject) => {
6262
setTimeout(() => {
6363
reject(new Error('Never rejected before timeout'));
6464
}, 2000);
65-
}).then(data => {
65+
}).then((data) => {
6666
console.dir({ data });
67-
}).catch(error => {
67+
}).catch((error) => {
6868
console.dir({ error: error.message });
6969
});

JavaScript/server.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ const server = http.createServer((req, res) => {
4040
return;
4141
}
4242

43-
handler(req, result => {
43+
handler(req, (result) => {
4444
const json = JSON.stringify(result);
4545
res.writeHead(200, { 'Content-Type': 'application/json' });
4646
res.end(json);

0 commit comments

Comments
 (0)