Skip to content

Commit

Permalink
➕ jsonToCSV
Browse files Browse the repository at this point in the history
  • Loading branch information
Bunlong committed Apr 16, 2021
1 parent 8cfc76f commit 0827548
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 10 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,17 @@ See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the
## License

MIT

<!--
Run the example app on iOS:
$ yarn example ios
Run the example app on Android:
$ yarn example android
$ react-native run-android
$ react-native start
-->
37 changes: 32 additions & 5 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,45 @@
import * as React from 'react';

import { StyleSheet, View, Text } from 'react-native';
import Csv from 'react-native-csv';
import { jsonToCSV } from 'react-native-csv';

export default function App() {
const [result, setResult] = React.useState<number | undefined>();

React.useEffect(() => {
Csv.multiply(3, 7).then(setResult);
const jsonData = `[
{
"Column 1": "1-1",
"Column 2": "1-2",
"Column 3": "1-3",
"Column 4": "1-4"
},
{
"Column 1": "2-1",
"Column 2": "2-2",
"Column 3": "2-3",
"Column 4": "2-4"
},
{
"Column 1": "3-1",
"Column 2": "3-2",
"Column 3": "3-3",
"Column 4": "3-4"
},
{
"Column 1": 4,
"Column 2": 5,
"Column 3": 6,
"Column 4": 7
}
]`;
const results = jsonToCSV(jsonData);
console.log('======================');
console.log(results);
console.log('======================');
}, []);

return (
<View style={styles.container}>
<Text>Result: {result}</Text>
<Text>Result</Text>
</View>
);
}
Expand Down
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -149,5 +149,9 @@
}
]
]
},
"dependencies": {
"@types/papaparse": "^5.2.5",
"papaparse": "^5.3.0"
}
}
6 changes: 1 addition & 5 deletions src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
export default {
multiply(a: number, b: number) {
return Promise.resolve(a * b);
},
};
export { jsonToCSV } from './jsonToCSV';
5 changes: 5 additions & 0 deletions src/jsonToCSV.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import PapaParse from 'papaparse';

export function jsonToCSV(json: any, options = {}) {
return PapaParse.unparse(json, options);
}
12 changes: 12 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1898,6 +1898,13 @@
resolved "https://registry.yarnpkg.com/@types/normalize-package-data/-/normalize-package-data-2.4.0.tgz#e486d0d97396d79beedd0a6e33f4534ff6b4973e"
integrity sha512-f5j5b/Gf71L+dbqxIpQ4Z2WlmI/mPJ0fOkGGmFgtb6sAu97EPczzbS3/tJKxmcYDj55OX6ssqwDAWOHIYDRDGA==

"@types/papaparse@^5.2.5":
version "5.2.5"
resolved "https://registry.yarnpkg.com/@types/papaparse/-/papaparse-5.2.5.tgz#9d3cd9d932eb0dccda9e3f73f39996c4da3fa628"
integrity sha512-TlqGskBad6skAgx2ifQmkO/FwiwObuWltBvX2bDceQhXh9IyZ7jYCK7qwhjB67kxw+0LJDXXM4jN3lcGqm1g5w==
dependencies:
"@types/node" "*"

"@types/parse-json@^4.0.0":
version "4.0.0"
resolved "https://registry.yarnpkg.com/@types/parse-json/-/parse-json-4.0.0.tgz#2f8bb441434d163b35fb8ffdccd7138927ffb8c0"
Expand Down Expand Up @@ -7361,6 +7368,11 @@ package-json@^6.3.0:
registry-url "^5.0.0"
semver "^6.2.0"

papaparse@^5.3.0:
version "5.3.0"
resolved "https://registry.yarnpkg.com/papaparse/-/papaparse-5.3.0.tgz#ab1702feb96e79ab4309652f36db9536563ad05a"
integrity sha512-Lb7jN/4bTpiuGPrYy4tkKoUS8sTki8zacB5ke1p5zolhcSE4TlWgrlsxjrDTbG/dFVh07ck7X36hUf/b5V68pg==

parent-module@^1.0.0:
version "1.0.1"
resolved "https://registry.yarnpkg.com/parent-module/-/parent-module-1.0.1.tgz#691d2709e78c79fae3a156622452d00762caaaa2"
Expand Down

0 comments on commit 0827548

Please sign in to comment.