README
wydfa-json2csv
Installation
## using npm
npm i wydfa-json2csv
## using yarn
yarn add wydfa-json2csv
Usage
import package in your project
import wdf from 'wydfa-json2csv';
const data =[
// write your object here, see full code to example
]
const filename = "document"
// generate object to csv format
wdf.generate(data)
// you can get it using var
var getdata = wdf.generate(data)
// print get data from csv format
console.log(getdata)
//download document with csv format
wdf.download(filename)
}
full code in react app
import './App.css';
import wdf from 'wydfa-json2csv';
import React from 'react';
function App() {
React.useEffect(()=>{
const data = [
{ "id": 1, "name": "Aceh", "capital":"Banda Aceh" },
{ "id": 2, "name": "Bali", "capital":"Denpasar" },
{ "id": 3, "name": "DI Yogyakarta", "capital":"Yogjakarta" },
{ "id": 4, "name": "Kalimantan Barat" , "capital":"Pontianak"},
{ "id": 5, "name": "Sumatera Utara", "capital":"Medan" },
{ "id": 6, "name": "Banten", "capital":"Serang" },
]
wdf.generate(data)
wdf.download("document csv")
},[])
return (
<div className="App">
<header className="App-header">
<h1>Welcome, it's will automatically download</h1>
</header>
</div>
);
}
export default App;
output:
Contributing
you can open issues or open request to modify and improvment this package