Skip to content

Commit

Permalink
enabled import pipe
Browse files Browse the repository at this point in the history
  • Loading branch information
ishubham21 committed Oct 13, 2021
1 parent f4ded91 commit 95be9b4
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
/.pnp
.pnp.js

.json

# testing
/coverage

Expand Down
File renamed without changes.
18 changes: 18 additions & 0 deletions csv2json.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const csv = require('csv-parser')
const fs = require('fs')
const results = [];

fs.createReadStream('csv/data.csv')
.pipe(csv())
.on('data', (data) => results.push(data))
.on('end', () => {
fs.writeFileSync(
"src/data.json",
JSON.stringify(results),
(err) => {
if (err) throw err;
console.log("Data file has been saved!");
}
);
});

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
"eject": "react-scripts eject",
"make": "node csv2json && npm run start"
},
"eslintConfig": {
"extends": [
Expand Down
5 changes: 5 additions & 0 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import './App.css';

function App() {

const data = require('./../src/data.json')
console.log(data);

return (
<div className="App">

</div>
);
}
Expand Down
1 change: 1 addition & 0 deletions src/data.json

Large diffs are not rendered by default.

0 comments on commit 95be9b4

Please sign in to comment.