Skip to content

Commit bc7e317

Browse files
committed
Release 3.0.0
* Improving logic flow of the module. * RFC 4180 compliance. * Refactored tests to remove replication and improve coverage. * Release 3.0.0
1 parent 5b595ff commit bc7e317

File tree

106 files changed

+2097
-3689
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

106 files changed

+2097
-3689
lines changed

.github/ISSUE_TEMPLATE.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
## Background Information
2+
- Module Version:
3+
4+
Issue is with:
5+
- [ ] json2csv
6+
- [ ] csv2json
7+
8+
## Expected Behavior
9+
10+
11+
## Actual Behavior
12+
13+
14+
## Code Example
15+
```javascript
16+
// Please include a simple example to replicate the issue
17+
let converter = require('json-2-csv');
18+
19+
20+
```

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
## Background Information
2+
3+
- Fixes issue(s): #
4+
- Proposed release version: ` `
5+
6+
## Proposed Changes
7+
8+
-
9+
-

.gitignore

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,11 @@
1-
# Created by .gitignore support plugin (hsz.mobi)
2-
### Node template
3-
# Logs
4-
logs
5-
*.log
6-
7-
# Runtime data
8-
pids
9-
*.pid
10-
*.seed
11-
12-
# Directory for instrumented libs generated by jscoverage/JSCover
13-
lib-cov
14-
151
# Coverage directory used by tools like istanbul
162
coverage
173

18-
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
19-
.grunt
20-
21-
# Compiled binary addons (http://nodejs.org/api/addons.html)
22-
build/Release
23-
244
# Dependency directory
25-
# Commenting this out is preferred by some people, see
26-
# https://npmjs.org/doc/faq.html#Should-I-check-my-node_modules-folder-into-git
275
node_modules
286

29-
# Users Environment Variables
30-
.lock-wscript
31-
7+
# Users Environment Configurations
328
.idea
339

34-
test/CSV/*
10+
# Debug logs
11+
npm-debug.log

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,7 @@ language: node_js
33
node_js:
44
- "11"
55
- "10"
6+
- "9"
67
- "8"
8+
- "7"
79
- "6"

README.md

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
[![Build Status](https://travis-ci.org/mrodrig/json-2-csv.svg?branch=master)](https://travis-ci.org/mrodrig/json-2-csv)
66
[![Downloads](http://img.shields.io/npm/dm/json-2-csv.svg)](https://www.npmjs.org/package/json-2-csv)
77
[![NPM version](https://img.shields.io/npm/v/json-2-csv.svg)](https://www.npmjs.org/package/json-2-csv)
8+
[![Maintainability](https://api.codeclimate.com/v1/badges/8c0cc3699d054fb77abe/maintainability)](https://codeclimate.com/github/mrodrig/json-2-csv/maintainability)
89
[![Known Vulnerabilities](https://snyk.io/test/npm/json-2-csv/badge.svg)](https://snyk.io/test/npm/json-2-csv)
910

1011
This node module will convert an array of JSON documents to a CSV string.
@@ -30,6 +31,10 @@ $ npm install json-2-csv
3031
let converter = require('json-2-csv');
3132
```
3233

34+
## Upgrading?
35+
36+
Upgrading to v3 from v2? Check out the [upgrade guide](https://github.com/mrodrig/json-2-csv/blob/master/upgrade_guides/UPGRADE_2_to_3.md).
37+
3338
### API
3439

3540
#### `converter.json2csv(array, callback, options)`
@@ -40,25 +45,22 @@ let converter = require('json-2-csv');
4045
* `options` - (Optional) A JSON document specifying any of the following key value pairs:
4146
* `delimiter` - Document - Specifies the different types of delimiters
4247
* `field` - String - Field Delimiter.
43-
* Default: `','`
44-
* `array` - String - Array Value Delimiter.
45-
* Default: `';'`
48+
* Default: `,`
4649
* `wrap` - String - Wrap values in the delimiter of choice (e.g. wrap values in quotes).
47-
* Default: `''`
50+
* Default: `"`
4851
* `eol` - String - End of Line Delimiter.
49-
* Default: `'\n'`
52+
* Default: `\n`
53+
* `excelBOM` - Boolean - Should a unicode character be prepended to allow Excel to open a UTF-8 encoded file with non-ASCII characters present.
5054
* `prependHeader` - Boolean - Should the auto-generated header be prepended as the first line in the CSV?
5155
* Default: `true`
5256
* `sortHeader` - Boolean - Should the header keys be sorted in alphabetical order?
5357
* Default: `false`
54-
* `emptyFieldValue` - String - Value for fields without data _when not checking schemas_.
55-
* Default: `'null'`
5658
* `trimHeaderFields` - Boolean - Should the header fields be trimmed?
5759
* Default: `false`
5860
* `trimFieldValues` - Boolean - Should the field values be trimmed? (*in development*)
5961
* Default: `false`
6062
* `checkSchemaDifferences` - Boolean - Should all documents have the same schema?
61-
* Default: `true`
63+
* Default: `false`
6264
* Note: Change this to `false` if some documents are missing certain fields and you still want to convert the data.
6365
* `keys` - Array - Specify the keys (as strings) that should be converted.
6466
* Default: `null`
@@ -69,7 +71,7 @@ let converter = require('json-2-csv');
6971

7072
For examples, please refer to the [json2csv API Documentation (Link)](https://github.com/mrodrig/json-2-csv/wiki/json2csv-Documentation)
7173

72-
#### Promisified Version: `converter.json2csvPromisified(array, options)`
74+
#### Promisified Version: `converter.json2csvAsync(array, options)`
7375

7476
Available in version `2.2.0`, this functionality makes use of promises from the `bluebird` module.
7577

@@ -80,13 +82,13 @@ Available in version `2.2.0`, this functionality makes use of promises from the
8082
* `options` - (Optional) A JSON document specifying any of the following key value pairs:
8183
* `delimiter` - Document - Specifies the different types of delimiters
8284
* `field` - String - Field Delimiter.
83-
* Default: `','`
84-
* `array` - String - Array Value Delimiter.
85-
* Default: `';'`
85+
* Default: `,`
8686
* `wrap` - String - The character that field values are wrapped in.
87-
* Default: `''`
87+
* Default: `"`
8888
* `eol` - String - End of Line Delimiter.
89-
* Default: `'\n'`
89+
* Default: `\n`
90+
* `excelBOM` - Boolean - Does the CSV contain a unicode character prepended in order to allow Excel to open a UTF-8 encoded file with non-ASCII characters present?
91+
* Default: `false`
9092
* `trimHeaderFields` - Boolean - Should the header fields be trimmed?
9193
* Default: `false`
9294
* `trimFieldValues` - Boolean - Should the field values be trimmed?
@@ -98,7 +100,7 @@ Available in version `2.2.0`, this functionality makes use of promises from the
98100

99101
For examples, please refer to the [csv2json API Documentation (Link)](https://github.com/mrodrig/json-2-csv/wiki/csv2json-Documentation)
100102

101-
#### Promisified Version: `csv2jsonPromisified(csv, options)`
103+
#### Promisified Version: `csv2jsonAsync(csv, options)`
102104

103105
Available in version `2.2.0`, this functionality makes use of promises from the `bluebird` module.
104106

@@ -108,7 +110,7 @@ Available in version `2.2.0`, this functionality makes use of promises from the
108110
$ npm test
109111
```
110112

111-
_Note_: This requires `mocha`, `should`, `async`, and `underscore`.
113+
_Note_: This requires `mocha`, `should`, and `underscore`.
112114

113115
To see test coverage, please run:
114116
```bash
@@ -117,18 +119,18 @@ $ npm run coverage
117119

118120
Current Coverage is:
119121
```
120-
Statements : 94.69% ( 196/207 )
121-
Branches : 93.55% ( 145/155 )
122-
Functions : 100% ( 34/34 )
123-
Lines : 95.38% ( 186/195 )
122+
Statements : 100% ( 245/245 )
123+
Branches : 100% ( 122/122 )
124+
Functions : 100% ( 48/48 )
125+
Lines : 100% ( 243/243 )
124126
```
125127

126128
## Frequently Asked Questions (FAQ)
127129
Please find the updated list (relocated to the Wiki) here: [Frequently Asked Questions (Link)](https://github.com/mrodrig/json-2-csv/wiki/FAQ)
128130

129131
## Features
130132
* Header Generation (per document keys)
131-
* Allows for conversion of specific keys in both json2csv and csv2json via the options.KEYS parameter (as of 1.1.2)
133+
* Allows for conversion of specific keys in both json2csv and csv2json via the options.keys parameter (as of 1.1.2)
132134
* Verifies all documents have same schema (schema field order does not matter as of 1.1.0)
133135
* Supports sub-documents natively
134136
* Supports arrays as document values for both json2csv and csv2json
@@ -138,5 +140,6 @@ Please find the updated list (relocated to the Wiki) here: [Frequently Asked Que
138140
* Promisifiable via bluebird's .promisify(<function>) and .promisifyAll(<object>) (as of 1.1.1)
139141
* Wrapped value support for json2csv and csv2json (as of 1.3.0)
140142
* Support for multiple different schemas (as of 1.4.0)
141-
* Promisified versions of the functions are now available by default: json2csvPromisified, csv2jsonPromisified (as of 2.2.0)
143+
* Promisified versions of the functions are now available by default: json2csvAsync, csv2jsonAsync (as of 2.2.0)
142144
* Nested quotes are escaped with an additional quote (per [RFC 4180](https://tools.ietf.org/html/rfc4180)) thanks to @eric-thelin (as of 2.3.0)
145+
* RFC 4180 Compliance (as of 3.0.0)

package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"author": "mrodrig",
33
"name": "json-2-csv",
44
"description": "A JSON to CSV and CSV to JSON converter that natively supports sub-documents and auto-generates the CSV heading.",
5-
"version": "2.4.0",
5+
"version": "3.0.0",
66
"repository": {
77
"type": "git",
88
"url": "http://github.com/mrodrig/json-2-csv.git"
@@ -32,8 +32,7 @@
3232
"devDependencies": {
3333
"mocha": "5.2.0",
3434
"istanbul": "0.4.5",
35-
"should": "13.2.3",
36-
"async": "2.6.1"
35+
"should": "13.2.3"
3736
},
3837
"engines": {
3938
"node": ">= 6"

src/constants.json

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,39 @@
11
{
2-
"Errors" : {
2+
"errors" : {
33

4-
"delimitersMustDiffer": "The field and array delimiters must differ.",
54
"callbackRequired": "A callback is required!",
65
"optionsRequired": "Options were not passed and are required.",
76

87
"json2csv": {
9-
"cannotCallJson2CsvOn": "Cannot call json2csv on ",
10-
"dataNotArrayOfDocuments": "Data provided was not an array of documents.",
8+
"cannotCallOn": "Cannot call json2csv on ",
9+
"dataCheckFailure": "Data provided was not an array of documents.",
1110
"notSameSchema": "Not all documents have the same schema."
1211
},
1312

1413
"csv2json": {
15-
"cannotCallCsv2JsonOn": "Cannot call csv2json on ",
16-
"csvNotString": "CSV is not a string.",
17-
"noDataRetrieveHeading": "No data provided to retrieve heading."
14+
"cannotCallOn": "Cannot call csv2json on ",
15+
"dataCheckFailure": "CSV is not a string."
1816
}
1917

2018
},
2119

22-
"DefaultOptions" : {
23-
"DELIMITER" : {
24-
"FIELD" : ",",
25-
"ARRAY" : ";",
26-
"WRAP" : "",
27-
"EOL" : "\n"
20+
"defaultOptions" : {
21+
"delimiter" : {
22+
"field" : ",",
23+
"wrap" : "\"",
24+
"eol" : "\n"
2825
},
29-
"PREPEND_HEADER" : true,
30-
"TRIM_HEADER_FIELDS": false,
31-
"TRIM_FIELD_VALUES" : false,
32-
"SORT_HEADER" : false,
33-
"PARSE_CSV_NUMBERS" : false,
34-
"KEYS" : null,
35-
"CHECK_SCHEMA_DIFFERENCES": true,
36-
"EMPTY_FIELD_VALUE": "null"
26+
"excelBOM": false,
27+
"prependHeader" : true,
28+
"trimHeaderFields": false,
29+
"trimFieldValues" : false,
30+
"sortHeader" : false,
31+
"parseCsvNumbers" : false,
32+
"keys" : null,
33+
"checkSchemaDifferences": false
34+
},
35+
36+
"values" : {
37+
"excelBOM": "\ufeff"
3738
}
3839
}

0 commit comments

Comments
 (0)