npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

easy-csv-parser

v1.0.8

Published

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.

Downloads

18

Readme

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 applications.

Installation

You can install easy-csv-parser using npm or yarn.

npm install easy-csv-parser

OR

yarn add easy-csv-parser

Usage

CSV to Javascript

Import the library

const { csvToObject } = require("easy-csv-parser`");

Exact code

async function processCSV() {
  const csvLink = "https://example.com/your-csv-file.csv";
  const result = await csvToObject(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();

CSV to JSON

Import the library

const { csvToJSON } = require("easy-csv-parser`");

Exact code

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

  • link (string): The URL of the CSV file you want to parse.

Return Value

The csvToObject function returns an object with the following properties:

  1. status (number): The HTTP status code indicating the result of the operation.
  2. data (array of objects): An array of JavaScript objects representing the parsed CSV data. Each object corresponds to a row in the CSV file, with keys derived from the CSV header and values from the data rows.

Key Features

easy-csv-parser offers the following key features to simplify your CSV data processing tasks:

  • Effortless CSV Retrieval: Fetch and parse CSV data from a specified URL with a single function call. Say goodbye to manual data retrieval and parsing.

  • Automatic Header Extraction: The library automatically handles CSV header extraction, ensuring that your data is organized and structured from the start.

  • Data Conversion: Seamlessly convert CSV data into JavaScript objects, making it easy to work with and manipulate in your Node.js applications.

  • Error Handling Made Easy: Receive clear and informative error messages and status codes, simplifying the process of identifying and resolving issues.

  • Versatile Application: Suitable for a wide range of applications, including data analysis, automation, data integration, and more. Streamline your workflow with ease.

easy-csv-parser is designed to be your go-to tool for handling CSV data efficiently and effectively, reducing complexity and improving your development experience.

Example Output

  1. If the CSV is successfully parsed, status will be 200, and the parsed data will be available in the data property.
  2. If the CSV file is empty or there is an issue with the request, status will be 400, and an error message will be provided.
  3. If there is an error during the fetching or processing of the CSV, status will be 500, and an error message will be provided.

License

This project is licensed under the MIT License. Feel free to use it in your own projects and contribute to its development on GitHub.

Issues and Contributions

If you encounter any issues, have questions, or want to contribute to the project, we welcome your involvement! Here's how you can get involved:

  • Report Issues: If you come across any bugs, unexpected behavior, or have suggestions for improvements, please visit the GitHub Issues page to create a new issue. Be sure to provide detailed information about the problem you encountered.

  • 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. 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!

If you have any questions or need assistance with using the library or contributing, feel free to reach out to us on GitHub.