diff --git a/README.md b/README.md index 07f1461..779aeea 100644 --- a/README.md +++ b/README.md @@ -25,3 +25,17 @@ See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the ## License MIT + + diff --git a/example/src/App.tsx b/example/src/App.tsx index 59af5a7..fc878b4 100644 --- a/example/src/App.tsx +++ b/example/src/App.tsx @@ -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(); - 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 ( - Result: {result} + Result ); } diff --git a/package.json b/package.json index e598068..ffd17a8 100644 --- a/package.json +++ b/package.json @@ -149,5 +149,9 @@ } ] ] + }, + "dependencies": { + "@types/papaparse": "^5.2.5", + "papaparse": "^5.3.0" } } diff --git a/src/index.tsx b/src/index.tsx index 328eb2d..f342bd6 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -1,5 +1 @@ -export default { - multiply(a: number, b: number) { - return Promise.resolve(a * b); - }, -}; +export { jsonToCSV } from './jsonToCSV'; diff --git a/src/jsonToCSV.ts b/src/jsonToCSV.ts new file mode 100644 index 0000000..88edde0 --- /dev/null +++ b/src/jsonToCSV.ts @@ -0,0 +1,5 @@ +import PapaParse from 'papaparse'; + +export function jsonToCSV(json: any, options = {}) { + return PapaParse.unparse(json, options); +} diff --git a/yarn.lock b/yarn.lock index c46e354..e5d2b60 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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" @@ -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"