Skip to content

Commit 51a76a7

Browse files
authored
Fix: babel runtime (#5) (fixes #3)
* Chore: rm babel-runtime and update to babel 7 * Chore: update dependencies and add husky prepush hook * Style: eslint * Test: test src * Fix: change object.entries to object.keys
1 parent 898dc3a commit 51a76a7

11 files changed

+1628
-1507
lines changed

.babelrc

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
{
22
"presets": [
3-
"env",
4-
"es2017"
5-
],
6-
"plugins": ["transform-runtime"]
3+
"@babel/env"
4+
]
75
}

package.json

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,16 @@
3333
]
3434
},
3535
"devDependencies": {
36-
"babel-cli": "^6.26.0",
37-
"babel-plugin-transform-runtime": "^6.23.0",
38-
"babel-preset-env": "^1.6.1",
39-
"babel-preset-es2017": "^6.24.1",
40-
"eslint": "^4.19.1",
41-
"eslint-config-airbnb-base": "^12.1.0",
42-
"eslint-plugin-import": "^2.9.0",
43-
"jest": "^22.4.3"
36+
"@babel/cli": "^7.0.0",
37+
"@babel/core": "^7.0.0",
38+
"@babel/preset-env": "^7.0.0",
39+
"babel-core": "^7.0.0-0",
40+
"babel-jest": "^23.4.2",
41+
"eslint": "^5.5.0",
42+
"eslint-config-airbnb-base": "^13.1.0",
43+
"eslint-plugin-import": "^2.14.0",
44+
"husky": "^0.14.3",
45+
"jest": "^23.5.0",
46+
"regenerator-runtime": "^0.12.1"
4447
}
4548
}
Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
export const checkSpecialCharsAndEmpty = (value) => {
22
const thisValue = value.toString().toLowerCase();
33

4-
const hasSpecialChars =
5-
thisValue.includes('\n') ||
6-
thisValue.includes('\t') ||
7-
thisValue.includes(',') ||
8-
thisValue.includes(';') ||
9-
thisValue.includes('.') ||
10-
thisValue.includes('"') ||
11-
thisValue.includes('\'') ||
12-
thisValue.includes('`') ||
13-
thisValue.includes('´') ||
14-
thisValue.length === 0;
4+
const hasSpecialChars = thisValue.includes('\n')
5+
|| thisValue.includes('\t')
6+
|| thisValue.includes(',')
7+
|| thisValue.includes(';')
8+
|| thisValue.includes('.')
9+
|| thisValue.includes('"')
10+
|| thisValue.includes('\'')
11+
|| thisValue.includes('`')
12+
|| thisValue.includes('´')
13+
|| thisValue.length === 0;
1514

1615
return hasSpecialChars;
1716
};

src/modules/convert-array-of-arrays-to-csv.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,21 @@ export const convertArrayOfArraysToCSV = (data, { header, separator }) => {
88
header.forEach((headerEl, i) => {
99
const thisHeaderEl = headerEl || '';
1010
const includesSpecials = checkSpecialCharsAndEmpty(thisHeaderEl);
11-
csv +=
12-
(includesSpecials ? `"${thisHeaderEl}"` : thisHeaderEl) +
13-
(Object.entries(header).length - 1 === i ? '' : separator) +
14-
(Object.entries(header).length - 1 === i ? '\n' : '');
11+
csv
12+
+= (includesSpecials ? `"${thisHeaderEl}"` : thisHeaderEl)
13+
+ (Object.keys(header).length - 1 === i ? '' : separator)
14+
+ (Object.keys(header).length - 1 === i ? '\n' : '');
1515
});
1616
}
1717

1818
array.forEach((row) => {
1919
row.forEach((value, i) => {
2020
const thisValue = value || (value === 0 ? 0 : '');
2121
const includesSpecials = checkSpecialCharsAndEmpty(thisValue);
22-
csv +=
23-
(includesSpecials ? `"${thisValue}"` : thisValue) +
24-
(row.length - 1 === i ? '' : separator) +
25-
(row.length - 1 === i ? '\n' : '');
22+
csv
23+
+= (includesSpecials ? `"${thisValue}"` : thisValue)
24+
+ (row.length - 1 === i ? '' : separator)
25+
+ (row.length - 1 === i ? '\n' : '');
2626
});
2727
});
2828

src/modules/convert-array-of-objects-to-csv.js

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,33 +7,33 @@ export const convertArrayOfObjectsToCSV = (data, { header, separator }) => {
77
if (header) {
88
header.forEach((headerEl, i) => {
99
const includesSpecials = checkSpecialCharsAndEmpty(headerEl);
10-
csv +=
11-
(includesSpecials ? `"${headerEl}"` : headerEl) +
12-
(Object.entries(header).length - 1 === i ? '' : separator) +
13-
(Object.entries(header).length - 1 === i ? '\n' : '');
10+
csv
11+
+= (includesSpecials ? `"${headerEl}"` : headerEl)
12+
+ (Object.keys(header).length - 1 === i ? '' : separator)
13+
+ (Object.keys(header).length - 1 === i ? '\n' : '');
1414
});
1515
}
1616

1717
array.forEach((row, idx) => {
1818
if (!header && idx === 0) {
19-
Object.entries(row).forEach((entry, i) => {
20-
const key = entry[0] ? entry[0] : '';
21-
const includesSpecials = checkSpecialCharsAndEmpty(key);
19+
Object.keys(row).forEach((key, i) => {
20+
const value = key || '';
21+
const includesSpecials = checkSpecialCharsAndEmpty(value);
2222

23-
csv +=
24-
(includesSpecials ? `"${key}"` : key) +
25-
(Object.entries(row).length - 1 === i ? '' : separator) +
26-
(Object.entries(row).length - 1 === i ? '\n' : '');
23+
csv
24+
+= (includesSpecials ? `"${value}"` : value)
25+
+ (Object.keys(row).length - 1 === i ? '' : separator)
26+
+ (Object.keys(row).length - 1 === i ? '\n' : '');
2727
});
2828
}
29-
Object.entries(row).forEach((entry, i) => {
30-
const value = entry[1] ? entry[1] : '';
29+
Object.keys(row).forEach((key, i) => {
30+
const value = row[key] || '';
3131
const includesSpecials = checkSpecialCharsAndEmpty(value);
3232

33-
csv +=
34-
(includesSpecials ? `"${value}"` : value) +
35-
(Object.entries(row).length - 1 === i ? '' : separator) +
36-
(Object.entries(row).length - 1 === i ? '\n' : '');
33+
csv
34+
+= (includesSpecials ? `"${value}"` : value)
35+
+ (Object.keys(row).length - 1 === i ? '' : separator)
36+
+ (Object.keys(row).length - 1 === i ? '\n' : '');
3737
});
3838
});
3939

test/helpers/check-if-valid.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { checkIfValid } from '../../lib/helpers/check-if-valid';
1+
import { checkIfValid } from '../../src/helpers/check-if-valid';
22

33
test('checkIfValid | wrong data', () => {
44
const result = () => checkIfValid({});

test/helpers/check-special-chars-and-empty.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { checkSpecialCharsAndEmpty } from '../../lib/helpers/check-special-chars-and-empty';
1+
import { checkSpecialCharsAndEmpty } from '../../src/helpers/check-special-chars-and-empty';
22

33
test('checkIfValid | newline', () => {
44
const result = checkSpecialCharsAndEmpty('\n');

test/index.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import converter, { convertArrayToCSV } from '../lib';
1+
import converter, { convertArrayToCSV } from '../src';
22

33
import {
44
dataArrayWithoutHeader,

test/modules/convert-array-of-arrays-to-csv.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { convertArrayOfArraysToCSV } from '../../lib/modules/convert-array-of-arrays-to-csv';
1+
import { convertArrayOfArraysToCSV } from '../../src/modules/convert-array-of-arrays-to-csv';
22

33
import {
44
dataArrayWithHeader,

test/modules/convert-array-of-objects-to-csv.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { convertArrayOfObjectsToCSV } from '../../lib/modules/convert-array-of-objects-to-csv';
1+
import { convertArrayOfObjectsToCSV } from '../../src/modules/convert-array-of-objects-to-csv';
22

33
import {
44
dataObject,

0 commit comments

Comments
 (0)