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-pipe

v1.3.1

Published

CSV-Pipe is a versatile TypeScript/JavaScript library that effortlessly converts data into the CSV file format for both front-end and back-end applications. It is lightweight and designed for simplicity, enabling the seamless transformation of arrays of o

Downloads

106

Readme

CSV-Pipe: Easy Data-to-CSV Conversion

CSV-Pipe is a versatile TypeScript/JavaScript library that effortlessly converts data into the CSV file format for both front-end and back-end applications. It is lightweight and designed for simplicity, enabling the seamless transformation of arrays of objects into CSV format.

Installation

npm install --save csv-pipe

Usage Guide

This section is dedicated to helping you integrate CSV-Pipe into your project with ease. Below, you'll find step-by-step instructions and code snippets that demonstrate how to convert your data into CSV format using our library.

Front-end

import { CsvPipe, CpDataset, cpDownload } from 'csv-pipe';

// Instantiate CsvPipe with configuration options
const csvPipe = new CsvPipe({
  filename: 'active_users_october', // Optional: Specify file name
  headers: ['Name', 'Email', 'Age'] // Optional: Specify CSV column headers
});

const data: CpDataset = [
  {
    name: 'Alex Johnson',
    email: '[email protected]',
    age: 29
  },
  {
    name: 'Carlos Herrera',
    email: '[email protected]',
    age: 24
  }
];

// Convert your Array to CSV format
const result = csvPipe.generate(data);

// Download the resulting data as a CSV or TXT file. If you require the output in TXT format, specify 'txt' as the second parameter
cpDownload(result);

Back-end

import { CsvPipe } from 'csv-pipe';
import { writeFile } from 'fs';

// Instantiate CsvPipe with configuration options
const csvPipe = new CsvPipe({
  filename: 'active_users_october', // Optional: Specify file name
  headers: ['Name', 'Email', 'Age'] // Optional: Specify CSV column headers
});

const data = [
  {
    name: 'Alex Johnson',
    email: '[email protected]',
    age: 29
  },
  {
    name: 'Carlos Herrera',
    email: '[email protected]',
    age: 24
  }
];

// Convert your Array to CSV format
const result = csvPipe.generate(data);

// Write the csv file
writeFile(`${result.filename}.csv`, result.data, (error) => {
  if (error) throw new Error(error);

  console.log(`${result.filename} successfully saved!`);
});

Config Table

| Option | Description | Default Value | Accepted Value | | -------------- | -------------------------------------------------------- | ---------------------------------- | --------------------------------- | | separator | Character for field separation, typically a comma | , | string | | filename | The name assigned to the CSV file | Generated Randomly | string | | headers | List of strings for CSV column headers | [] | Array<string> | | quote | Character to wrap around values | " | string | | autoHeaders | Whether to generate headers from data keys automatically | false | boolean | | showHeaders | Whether to include headers in the CSV output | true | boolean | | infinityText | Representation for Infinity values in CSV | "Infinity" | string | | nullDisplay | Text representation for null values | "null" | string | | undefDisplay | Text for undefined values | "undefined" | string | | boolStyle | Text mappings for true and false values | { true: "TRUE", false: "FALSE" } | { true: string, false: string } | | charset | Encoding for the CSV file | "utf8" | string | | newLine | Characters used for line breaks in CSV | "\r\n" | string | | NaNText | Text to represent NaN values | "" | string |

Getting Help

If you have questions or encounter any issues, please open an issue on our GitHub repository so we can help you out.

Thank you for choosing CSV-Pipe

We trust it will enhance your data handling capabilities and simplify your CSV conversion tasks.