Skip to content

Commit d636bff

Browse files
authored
Merge pull request #242 from mrodrig/v5-prep
V5 documentation prep
2 parents 1f2e6f9 + 7e71ee7 commit d636bff

File tree

4 files changed

+49
-17
lines changed

4 files changed

+49
-17
lines changed

README.md

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ $ npm install @mrodrig/json-2-csv-cli
2929

3030
## Upgrading?
3131

32-
Upgrading to v4 from v3? Check out the [upgrade guide](https://github.com/mrodrig/json-2-csv/blob/master/upgrade_guides/UPGRADE_3_to_4.md).
32+
Upgrading to v5 from v4? Check out the [upgrade guide](https://github.com/mrodrig/json-2-csv/blob/master/upgrade_guides/UPGRADE_4_to_5.md).
3333

3434
## Usage
3535

@@ -41,13 +41,12 @@ or
4141
```javascript
4242
import { json2csv } from 'json-2-csv';
4343
```
44-
Looking for examples? Check out the Wiki: [json-2-csv Wiki](https://github.com/mrodrig/json-2-csv/wiki)
4544

4645
### API
4746

48-
#### `json2csv(array, options)` => `Promise<string>`
47+
#### `json2csv(array, options)` => `string`
4948

50-
Returns a `Promise` that resolves with the CSV `string` or rejects with an `Error` if there was an issue.
49+
Returns the CSV `string` or rejects with an `Error` if there was an issue.
5150

5251
* `array` - An array of JSON documents to be converted to CSV.
5352
* `options` - (Optional) A JSON document specifying any of the following key value pairs:
@@ -165,11 +164,9 @@ Returns a `Promise` that resolves with the CSV `string` or rejects with an `Erro
165164
* Default: `false`
166165

167166

168-
For examples, please refer to the [json2csv API Documentation (Link)](https://github.com/mrodrig/json-2-csv/wiki/json2csv-Documentation)
167+
#### `csv2json(csv, options)` => object[]
169168

170-
#### `csv2json(csv, options)` => Promise<object[]>
171-
172-
Returns a `Promise` that resolves with the JSON object array (`object[]`) or rejects with an `Error` if there was an issue.
169+
Returns the JSON object array (`object[]`) or rejects with an `Error` if there was an issue.
173170

174171
* `csv` - A string of CSV
175172
* `options` - (Optional) A JSON document specifying any of the following key value pairs:
@@ -197,8 +194,6 @@ Returns a `Promise` that resolves with the JSON object array (`object[]`) or rej
197194
* `trimFieldValues` - Boolean - Should the field values be trimmed?
198195
* Default: `false`
199196

200-
For examples, please refer to the [csv2json API Documentation (Link)](https://github.com/mrodrig/json-2-csv/wiki/csv2json-Documentation)
201-
202197
### CLI
203198
Note: As of `3.5.8`, the command line interface functionality has been pulled out to a separate package. Please be sure to
204199
install the `@mrodrig/json-2-csv-cli` NPM package if you wish to use the CLI functionality shown below:
@@ -258,9 +253,6 @@ To see test coverage, please run:
258253
$ npm run coverage
259254
```
260255

261-
## Frequently Asked Questions (FAQ)
262-
Please find the updated list (relocated to the Wiki) here: [Frequently Asked Questions (Link)](https://github.com/mrodrig/json-2-csv/wiki/FAQ)
263-
264256
## Features
265257
* Header Generation (per document keys)
266258
* Allows for conversion of specific keys in both json2csv and csv2json via the options.keys parameter (as of 1.1.2)
@@ -272,11 +264,11 @@ Please find the updated list (relocated to the Wiki) here: [Frequently Asked Que
272264
* Allows for custom field delimiters, end of line delimiters, etc.
273265
* Wrapped value support for json2csv and csv2json (as of 1.3.0)
274266
* Support for multiple different schemas (as of 1.4.0)
275-
* Promisified versions of the functions are now available by default: json2csvAsync, csv2jsonAsync (as of 2.2.0)
276267
* RFC 4180 Compliance (as of 3.0.0)
277268
* CLI functionality (as of 3.0.0)
278269
* `csv2json test.csv -o output.json`
279270
* *and*
280271
* `json2csv test.json -o output.csv -W -k arrayOfStrings -o output.csv`
281272
* Empty field value option (as of 3.1.0)
282273
* TypeScript typings included (as of 3.4.0) - thanks to [@GabrielCastro](https://github.com/GabrielCastro)!
274+
* Synchronous use case support (as of 5.0.0) - thanks to [@Nokel81](https://github.com/Nokel81)

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
},
66
"name": "json-2-csv",
77
"description": "A JSON to CSV and CSV to JSON converter that natively supports sub-documents and auto-generates the CSV heading.",
8-
"version": "4.1.1",
8+
"version": "5.0.0",
99
"homepage": "https://mrodrig.github.io/json-2-csv",
1010
"repository": {
1111
"type": "git",

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)