Skip to content

Commit f053c8b

Browse files
juanjoDiazknownasilya
authored andcommitted
fix: Rename hasCSVColumnTitle to noHeader (#216)
BREAKING CHANGE: Rename hasCSVColumnTitle to noHeader to keep in line with the CLI
1 parent 3359e8d commit f053c8b

File tree

5 files changed

+11
-11
lines changed

5 files changed

+11
-11
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ try {
4646
- Supports optional custom delimiters
4747
- Supports optional custom eol value
4848
- Supports optional custom quotation marks
49-
- Not create CSV column title by passing hasCSVColumnTitle: false, into params.
49+
- Not create CSV column title by passing noHeader: false, into params.
5050
- If field is not exist in object then the field value in CSV will be empty.
5151
- Preserve new lines in values. Should be used with \r\n line endings for full compatibility with Excel.
5252
- Add a BOM character at the beginning of the csv to make Excel displaying special characters correctly.
@@ -64,7 +64,7 @@ try {
6464
- `defaultValue` - String, default value to use when missing data. Defaults to `<empty>` if not specified. (Overridden by `fields[].default`)
6565
- `quotes` - String, quotes around cell values and column names. Defaults to `"` if not specified.
6666
- `doubleQuotes` - String, the value to replace double quotes in strings. Defaults to 2x`quotes` (for example `""`) if not specified.
67-
- `hasCSVColumnTitle` - Boolean, determines whether or not CSV file will contain a title column. Defaults to `true` if not specified.
67+
- `noHeader` - Boolean, determines whether or not CSV file will contain a title column. Defaults to `true` if not specified.
6868
- `eol` - String, it gets added to each row of data. Defaults to `` if not specified.
6969
- `newLine` - String, overrides the default OS line ending (i.e. `\n` on Unix and `\r\n` on Windows).
7070
- `flatten` - Boolean, flattens nested JSON using [flat]. Defaults to `false`.

bin/json2csv.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ getFields(function (err, fields) {
109109
var opts = {
110110
data: input,
111111
fields: fields,
112-
hasCSVColumnTitle: program.header,
112+
noHeader: program.header,
113113
quotes: program.quote,
114114
defaultValue: program.defaultValue,
115115
flatten: program.flatten,

index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ declare namespace json2csv {
2424
defaultValue?: string;
2525
quotes?: string;
2626
doubleQuotes?: string;
27-
hasCSVColumnTitle?: boolean;
27+
noHeader?: boolean;
2828
eol?: string;
2929
newLine?: string;
3030
flatten?: boolean;

lib/json2csv.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ var flatten = require('flat');
2020
* @property {String} [defaultValue="<empty>"] - default value to use when missing data
2121
* @property {String} [quotes='"'] - quotes around cell values and column names
2222
* @property {String} [doubleQuotes='""'] - the value to replace double quotes in strings
23-
* @property {Boolean} [hasCSVColumnTitle=true] - determines whether or not CSV file will contain a title column
23+
* @property {Boolean} [noHeader=true] - determines whether or not CSV file will contain a title column
2424
* @property {String} [eol=''] - it gets added to each row of data
2525
* @property {String} [newLine] - overrides the default OS line ending (\n on Unix \r\n on Windows)
2626
* @property {Boolean} [flatten=false] - flattens nested JSON using flat (https://www.npmjs.com/package/flat)
@@ -34,7 +34,7 @@ var flatten = require('flat');
3434
* Main function that converts json to csv.
3535
*
3636
* @param {Json2CsvParams} params Function parameters containing data, fields,
37-
* delimiter (default is ','), hasCSVColumnTitle (default is true)
37+
* delimiter (default is ','), noHeader (default is true)
3838
* and default value (default is '')
3939
* @param {Function} [callback] Callback function
4040
* if error, returning error in call back.
@@ -75,7 +75,7 @@ module.exports = function (params, callback) {
7575
* Note that this modifies params.
7676
*
7777
* @param {Json2CsvParams} params Function parameters containing data, fields,
78-
* delimiter, default value, mark quotes and hasCSVColumnTitle
78+
* delimiter, default value, mark quotes and noHeader
7979
*/
8080
function checkParams(params) {
8181
params.data = params.data || [];
@@ -133,8 +133,8 @@ function checkParams(params) {
133133
//#check default value
134134
params.defaultValue = params.defaultValue;
135135

136-
//#check hasCSVColumnTitle, if it is not explicitly set to false then true.
137-
params.hasCSVColumnTitle = params.hasCSVColumnTitle !== false;
136+
//#check noHeader, if it is not explicitly set to false then true.
137+
params.noHeader = params.noHeader !== false;
138138

139139
//#check include empty rows, defaults to false
140140
params.includeEmptyRows = params.includeEmptyRows || false;
@@ -161,7 +161,7 @@ function createColumnTitles(params) {
161161
var str = '';
162162

163163
//if CSV has column title, then create it
164-
if (params.hasCSVColumnTitle) {
164+
if (params.noHeader) {
165165
params.fieldNames.forEach(function (element) {
166166
if (str !== '') {
167167
str += params.del;

test/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ async.parallel(loadFixtures(csvFixtures), function (err) {
115115
json2csv({
116116
data: jsonDefault,
117117
fields: ['carModel', 'price', 'color'],
118-
hasCSVColumnTitle: false
118+
noHeader: false
119119
}, function (error, csv) {
120120
t.error(error);
121121
t.equal(csv, csvFixtures.withoutTitle);

0 commit comments

Comments
 (0)