Skip to content

Commit 83ebeb0

Browse files
committed
toggle on/off to remove whitespaces from header fields: closes #67
1 parent a973f8d commit 83ebeb0

File tree

9 files changed

+168
-385
lines changed

9 files changed

+168
-385
lines changed

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ show your :heart: and support.
3232
+ [Generate Array of Object in JSON format](#generate-array-of-object-in-json-format)
3333
+ [Generate Object with sub array](#generate-object-with-sub-array)
3434
+ [Define field delimiter](#define-field-delimiter)
35+
+ [Trim header field](#trim-header-field)
36+
+ [Trim header field with whitespaces](#trim-header-field-with-whitespaces)
3537
+ [Support Quoted Fields](#support-quoted-fields)
3638
+ [Index header](#index-header)
3739
+ [Empty rows](#empty-rows)
@@ -168,6 +170,19 @@ E.g. if your field delimiter is the comma **,** then:
168170
.getJsonFromCsv(fileInputName);
169171
```
170172

173+
#### Trim header field
174+
175+
The content of the field header is cut off at the beginning and end of the string. E.g. " Last Name " -> "Last Name".
176+
177+
#### Trim header field with whitespaces
178+
179+
Use the method *trimHeaderFieldWhiteSpace(true)* to remove the whitespaces in an header field (E.g. " Last Name " -> "LastName"):
180+
181+
```js
182+
csvToJson.rimHeaderFieldWhiteSpace(true)
183+
.getJsonFromCsv(fileInputName);
184+
```
185+
171186
#### Support Quoted Fields
172187
To be able to parse correctly fields wrapped in quote, like the **last_name** in the first row in the following example:
173188

index.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ exports.fieldDelimiter = function (delimiter) {
3535
return this;
3636
};
3737

38+
/**
39+
* If active the content of the Header Fields is trimmed including the white spaces, e.g. "My Name" -> "MyName"
40+
*/
41+
exports.trimHeaderFieldWhiteSpace = function (active = false) {
42+
csvToJson.trimHeaderFieldWhiteSpace(active);
43+
return this;
44+
};
45+
3846
/**
3947
* Defines the index where the header is defined
4048
*/

0 commit comments

Comments
 (0)