Skip to content

Commit c237523

Browse files
authored
Fix: space as special char (closes #7) (#10)
* Fix: add space as special char * Test: update tests for new fix
1 parent bf60b3a commit c237523

File tree

5 files changed

+29
-15
lines changed

5 files changed

+29
-15
lines changed

src/helpers/check-special-chars-and-empty.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export const checkSpecialCharsAndEmpty = (value) => {
1010
|| thisValue.includes('\'')
1111
|| thisValue.includes('`')
1212
|| thisValue.includes('´')
13+
|| thisValue.includes(' ')
1314
|| thisValue.length === 0;
1415

1516
return hasSpecialChars;

test/fixtures/data.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ const dataArrayWithNullAndUndefined = [
1515
];
1616

1717
const dataArrayWithZero = [
18-
[0, 'Mark', 'Otto', '@mdo'],
19-
[1, 'Jacob', 'Thornton', '@fat'],
20-
[2, 'Larry', 'the Bird', '@twitter'],
21-
]
18+
[0, 'Mark', 'Otto', '@mdo'],
19+
[1, 'Jacob', 'Thornton', '@fat'],
20+
[2, 'Larry', 'the Bird', '@twitter'],
21+
];
2222

2323
const data = [
2424
{

test/fixtures/expected-results.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
1-
export const expectedResultArrayNoHeaderNoOptions = '1,Mark,Otto,@mdo\n2,Jacob,Thornton,@fat\n3,Larry,the Bird,@twitter\n';
1+
export const expectedResultArrayNoHeaderNoOptions = '1,Mark,Otto,@mdo\n2,Jacob,Thornton,@fat\n3,Larry,"the Bird",@twitter\n';
22

3-
export const expectedResultObjectNoOptions = 'number,first,last,handle\n1,Mark,Otto,@mdo\n2,Jacob,Thornton,@fat\n3,Larry,the Bird,@twitter\n';
3+
export const expectedResultObjectNoOptions = 'number,first,last,handle\n1,Mark,Otto,@mdo\n2,Jacob,Thornton,@fat\n3,Larry,"the Bird",@twitter\n';
44

5-
export const expectedResultObjectOnlyHeader = 'Number,First,Last,Handle\n1,Mark,Otto,@mdo\n2,Jacob,Thornton,@fat\n3,Larry,the Bird,@twitter\n';
5+
export const expectedResultObjectOnlyHeader = 'Number,First,Last,Handle\n1,Mark,Otto,@mdo\n2,Jacob,Thornton,@fat\n3,Larry,"the Bird",@twitter\n';
66

7-
export const expectedResultObjectNullAndUndefined = 'Number,First,Last,Handle\n1,Mark,"",@mdo\n2,Jacob,Thornton,""\n3,Larry,the Bird,@twitter\n';
7+
export const expectedResultObjectNullAndUndefined = 'Number,First,Last,Handle\n1,Mark,"",@mdo\n2,Jacob,Thornton,""\n3,Larry,"the Bird",@twitter\n';
88

9-
export const expectedResultArrayNullAndUndefined = 'number,first,last,handle\n1,Mark,"",@mdo\n2,Jacob,Thornton,""\n3,Larry,the Bird,@twitter\n';
9+
export const expectedResultArrayNullAndUndefined = 'number,first,last,handle\n1,Mark,"",@mdo\n2,Jacob,Thornton,""\n3,Larry,"the Bird",@twitter\n';
1010

11-
export const expectedResultArrayZero = 'number,first,last,handle\n0,Mark,Otto,@mdo\n1,Jacob,Thornton,@fat\n2,Larry,the Bird,@twitter\n';
11+
export const expectedResultArrayZero = 'number,first,last,handle\n0,Mark,Otto,@mdo\n1,Jacob,Thornton,@fat\n2,Larry,"the Bird",@twitter\n';
1212

13-
export const expectedResultObjectHeaderSeparatorSemicolon = 'Number;First;Last;Handle\n1;Mark;Otto;@mdo\n2;Jacob;Thornton;@fat\n3;Larry;the Bird;@twitter\n';
13+
export const expectedResultObjectHeaderSeparatorSemicolon = 'Number;First;Last;Handle\n1;Mark;Otto;@mdo\n2;Jacob;Thornton;@fat\n3;Larry;"the Bird";@twitter\n';
1414

15-
export const expectedResultObjecOnlySeparatorTab = 'number\tfirst\tlast\thandle\n1\tMark\tOtto\t@mdo\n2\tJacob\tThornton\t@fat\n3\tLarry\tthe Bird\t@twitter\n';
15+
export const expectedResultObjecOnlySeparatorTab = 'number\tfirst\tlast\thandle\n1\tMark\tOtto\t@mdo\n2\tJacob\tThornton\t@fat\n3\tLarry\t"the Bird"\t@twitter\n';
16+
17+
export const expectedResultArrayHeaderWithSpaces = '"number number",first,last,handle\n1,Mark,Otto,@mdo\n2,Jacob,Thornton,@fat\n3,Larry,"the Bird",@twitter\n';
1618

1719
export const expectedResultArrayWithHeaderNoOptions = expectedResultObjectNoOptions;
1820

1921
export const expectedResultArrayOnlyHeader = expectedResultObjectOnlyHeader;
2022

21-
export const expectedResultArrayHeaderSeparatorSemicolon =
22-
expectedResultObjectHeaderSeparatorSemicolon;
23+
export const expectedResultArrayHeaderSeparatorSemicolon = expectedResultObjectHeaderSeparatorSemicolon; // eslint-disable-line
2324

2425
export const expectedResultArrayOnlySeparatorTab = expectedResultObjecOnlySeparatorTab;
25-

test/fixtures/options.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ export const optionsHeaderSeparatorDefault = {
33
separator: ',',
44
};
55

6+
export const optionsHeaderWithSpacesSeparatorDefault = {
7+
header: ['number number', 'first', 'last', 'handle'],
8+
separator: ',',
9+
};
10+
611
export const optionsHeaderSeperatorSemicolon = {
712
header: ['Number', 'First', 'Last', 'Handle'],
813
separator: ';',

test/index.spec.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,22 @@ import {
88
import {
99
expectedResultArrayNoHeaderNoOptions,
1010
expectedResultObjectNoOptions,
11+
expectedResultArrayHeaderWithSpaces,gco
1112
} from './fixtures/expected-results';
13+
import { optionsHeaderWithSpacesSeparatorDefault } from './fixtures/options';
1214

1315
test('convertArrayToCsv | array of arrays | with no header and no options', () => {
1416
const result = convertArrayToCSV(dataArrayWithoutHeader);
1517

1618
expect(result).toBe(expectedResultArrayNoHeaderNoOptions);
1719
});
1820

21+
test('convertArrayToCsv | array of arrays | with header with spaces and no options', () => {
22+
const result = convertArrayToCSV(dataArrayWithoutHeader, optionsHeaderWithSpacesSeparatorDefault);
23+
24+
expect(result).toBe(expectedResultArrayHeaderWithSpaces);
25+
});
26+
1927
test('convertArrayToCsv | array of objects | with no options', () => {
2028
const result = convertArrayToCSV(dataObject);
2129

0 commit comments

Comments
 (0)