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

csv-exporter-utility

v1.1.0

Published

Downloads a CSV file from given JSON data

Downloads

181

Readme

CSV Exporter Utility

Description

CSV Exporter Utility is a simple, yet powerful package that allows you to easily convert a JSON array of data into a CSV file and download it in a user-friendly way. This utility is highly useful when you need to export data from a web application or API to a CSV file format, which can then be imported into other tools or processed further.

"Buy Me A Coffee"

Why use CSV Exporter Utility

  • Easy to integrate into your existing projects
  • Lightweight with no external dependencies
  • Handles complex JSON data structures and nested objects
  • Automatically generates CSV headers from JSON keys
  • Allows omission of specific properties from the CSV export
  • Supports nested properties omission with dot notation
  • Cross-browser compatibility
  • User-friendly file download experience

How to use CSV Exporter Utility

  1. Install the package using npm or yarn:
npm install csv-exporter-utility
  1. Import the downloadCSVFile function from the package:
import { downloadCSVFile } from "csv-exporter-utility";
  1. Use the downloadCSVFile function in your application to convert and download JSON data as a CSV file. You can also pass an array of property names to omit certain fields from the CSV:
const jsonData = [
  { id: 1, name: "John Doe", email: "[email protected]" },
  { id: 2, name: "Jane Doe", email: "[email protected]" },
];

// Omit the "email" field from the CSV
downloadCSVFile(jsonData, "users", ["email"]);

In the above example, the email field is omitted from the downloaded users.csv file.

Additional support: Dot notation for nested properties

You can also omit nested properties using dot notation:

// Omit the "user.age" field from the CSV
downloadCSVFile(jsonData, "users", ["user.age"]);

This will omit the age field inside the user object, allowing more control over complex JSON data structures.

When to use CSV Exporter Utility

Use CSV Exporter Utility when you need to:

  • Export data from your web application to a CSV file
  • Provide users with a simple way to download data in a structured format
  • Convert JSON data to CSV for further processing or analysis
  • Omit specific properties (including nested ones) from the CSV output
  • Integrate a lightweight CSV export solution without external dependencies

Requirements and dependencies

CSV Exporter Utility is written in TypeScript and has no external dependencies. However, you need to ensure that your project uses TypeScript and has the necessary TypeScript configuration in place.

To use this package, your project should have the following:

  • TypeScript version 4.x or higher
  • A properly configured tsconfig.json file
  • Node.js version 12.x or higher (if using the package in a Node.js environment)

For more information on setting up TypeScript in your project, please refer to the official TypeScript documentation.

License

This project is licensed under the MIT License. You are free to use, modify, and distribute this package, provided that you include the copyright notice and the license text. For more information, please see the LICENSE file.

Author

CSV Exporter Utility is developed and maintained by Arslan Ameer. If you have any questions or need help, feel free to open an issue on the GitHub repository.

Contributing

Contributions to CSV Exporter Utility are welcome and greatly appreciated! If you would like to contribute, please follow these steps:

  1. Fork the repository on GitHub.
  2. Clone your fork and create a new branch for your changes.
  3. Commit and push your changes to your fork.
  4. Create a Pull Request on the original repository, describing your changes and referencing any related issues.

Please make sure to follow the existing coding style and add tests for any new features or bug fixes. Your contributions will be reviewed and, if approved, merged into the main repository.

Thank you for your interest in contributing to CSV Exporter Utility!

"Buy Me A Coffee"

Changelog

v1.1.0 - [September 7, 2024]

  • New Features:

    • Added support to omit specific properties from CSV output using the omitProperties parameter.
    • Enhanced functionality to omit nested properties using dot notation (e.g., "user.age" will omit the age field from the user object).
  • Improvements:

    • Refined CSV formatting logic to handle omitted properties more efficiently.
    • Improved error handling for scenarios with missing or invalid property paths in dot notation.
  • Bug Fixes:

    • Resolved an issue where certain fields with nested structures were not properly converted to CSV.