Skip to content

Commit a406678

Browse files
committed
docs: 5.0.0 upgrade guide
1 parent 1f2e6f9 commit a406678

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

upgrade_guides/UPGRADE_4_to_5.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Upgrade Guide - v4 to v5
2+
3+
## Breaking Changes
4+
5+
* Asynchronous methods are now synchronous
6+
7+
Thanks to [@Nokel81](https://github.com/Nokel81) for the pull request to convert the module to convert the asynchronous internal flow to be entirely synchronous. This helps enable certain use cases where a conversion is needed in a synchronous manner, or where asynchronous code might not be feasible. While these changes shift the module towards a more synchronous focused use case, it's still entirely possible to perform JSON to CSV or CSV to JSON conversions for an asynchronous use case too.
8+
9+
```javascript
10+
const converter = require('json-2-csv');
11+
12+
// Synchronous:
13+
14+
const csv = converter.json2csv([ { level: 'info', message: 'Our first test' }]);
15+
console.log('First output is', csv);
16+
17+
// Asynchronous:
18+
19+
async function runConversion() {
20+
return converter.json2csv([ { level: 'info', message: 'Another test...' }]);
21+
}
22+
23+
async function runAsync() {
24+
const csv = await runConversion();
25+
console.log('Second output is', csv);
26+
}
27+
28+
runAsync();
29+
console.log('This can run before the second output appears...');
30+
```
31+
32+
Example output:
33+
34+
```
35+
First output is level,message
36+
info,Our first test
37+
This can run before the second output appears...
38+
Second output is level,message
39+
info,Another test...
40+
```

0 commit comments

Comments
 (0)