easy-csv-parser
Advanced tools
Comparing version 1.0.4 to 1.0.5
32
index.js
@@ -9,3 +9,3 @@ const axios = require("axios"); | ||
status: 400, | ||
message: "Your file might br empty" | ||
message: "Your file might be empty" | ||
}; | ||
@@ -37,8 +37,30 @@ } | ||
return { | ||
status: 500, | ||
message: `Error fetching or processing CSV: ${error}` | ||
}; | ||
status: 500, | ||
message: `Error fetching or processing CSV: ${error}` | ||
}; | ||
} | ||
} | ||
module.exports = csvToObject; | ||
async function csvToJSON(link) { | ||
const csvToObj = await csvToObject(link); | ||
if (csvToObj.status === 500) { | ||
return { | ||
status: 500, | ||
message: `Error fetching or processing CSV` | ||
}; | ||
} | ||
if (csvToObj.status === 200) { | ||
return { | ||
status: 200, | ||
data: JSON.stringify(csvToObj) | ||
}; | ||
} | ||
if (csvToObj.status === 400) { | ||
return { | ||
status: 400, | ||
message: "Your file might br empty" | ||
}; | ||
} | ||
} | ||
module.exports = { csvToObject, csvToJSON }; |
{ | ||
"name": "easy-csv-parser", | ||
"version": "1.0.4", | ||
"description": "easy-csv-parser simplifies CSV data parsing in Node.js. Fetch, extract headers, and convert CSV files from URLs to JavaScript objects effortlessly. Ideal fordevelopers, data analysis, automation, and more.", | ||
"version": "1.0.5", | ||
"description": "easy-csv-parser simplifies CSV data parsing in Node.js. Fetch, extract headers, and convert CSV files from URLs to JavaScript objects and JSON effortlessly. Ideal fordevelopers, data analysis, automation, and more.", | ||
"main": "index.js", | ||
@@ -16,2 +16,3 @@ "scripts": { | ||
"csv", | ||
"csv-to-json", | ||
"csv-parser", | ||
@@ -18,0 +19,0 @@ "csv-to-object", |
# easy-csv-parser | ||
`easy-csv-parser` is an npm package that allows you to easily parse CSV files from | ||
a provided URL into JavaScript objects. This library simplifies the process of | ||
fetching and processing CSV data, making it useful for a wide range of | ||
`easy-csv-parser` is an npm package that allows you to easily parse CSV files | ||
from a provided URL into JavaScript objects. This library simplifies the process | ||
of fetching and processing CSV data, making it useful for a wide range of | ||
applications. | ||
@@ -22,5 +22,5 @@ | ||
## Usage | ||
# Usage | ||
Here's how you can use `easy-csv-parser` in your JavaScript project: | ||
## CSV to Javascript | ||
@@ -30,3 +30,3 @@ ### Import the library | ||
```javascript | ||
const csvToObject = require("easy-csv-parser`"); | ||
const { csvToObject } = require("easy-csv-parser`"); | ||
``` | ||
@@ -54,2 +54,30 @@ | ||
## CSV to Javascript | ||
### Import the library | ||
```javascript | ||
const { csvToJSON } = require("easy-csv-parser`"); | ||
``` | ||
### Exact code | ||
```javascript | ||
async function processCSV() { | ||
const csvLink = "https://example.com/your-csv-file.csv"; | ||
const result = await csvToJSON(csvLink); | ||
if (result.status === 200) { | ||
console.log("CSV data successfully parsed:"); | ||
console.log(result.data); | ||
} else if (result.status === 400) { | ||
console.error("Bad Request:", result.message); | ||
} else { | ||
console.error("Error:", result.message); | ||
} | ||
} | ||
processCSV(); | ||
``` | ||
## Parameters | ||
@@ -120,11 +148,11 @@ | ||
- **Contribute Code**: If you want to contribute to the development of | ||
`easy-csv-parser`, we appreciate your contributions! You can submit code changes | ||
or enhancements by opening a pull request on our | ||
[GitHub repository](https://github.com/rahulnikam2002/easy-csv-parser). | ||
Please follow our contribution guidelines when submitting your changes. | ||
`easy-csv-parser`, we appreciate your contributions! You can submit code | ||
changes or enhancements by opening a pull request on our | ||
[GitHub repository](https://github.com/rahulnikam2002/easy-csv-parser). Please | ||
follow our contribution guidelines when submitting your changes. | ||
Your feedback and contributions help make `easy-csv-parser` better for | ||
everyone. Thank you for using and supporting this project! | ||
Your feedback and contributions help make `easy-csv-parser` better for everyone. | ||
Thank you for using and supporting this project! | ||
If you have any questions or need assistance with using the library or | ||
contributing, feel free to reach out to us on GitHub. |
7705
55
155