1.3.1 • Published 2 months ago

csv-pipe v1.3.1

Weekly downloads
-
License
ISC
Repository
github
Last release
2 months ago

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: 'alex.johnson@example.com',
    age: 29
  },
  {
    name: 'Carlos Herrera',
    email: 'carlos.h24@example.com',
    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: 'alex.johnson@example.com',
    age: 29
  },
  {
    name: 'Carlos Herrera',
    email: 'carlos.h24@example.com',
    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

OptionDescriptionDefault ValueAccepted Value
separatorCharacter for field separation, typically a comma,string
filenameThe name assigned to the CSV fileGenerated Randomlystring
headersList of strings for CSV column headers[]Array<string>
quoteCharacter to wrap around values"string
autoHeadersWhether to generate headers from data keys automaticallyfalseboolean
showHeadersWhether to include headers in the CSV outputtrueboolean
infinityTextRepresentation for Infinity values in CSV"Infinity"string
nullDisplayText representation for null values"null"string
undefDisplayText for undefined values"undefined"string
boolStyleText mappings for true and false values{ true: "TRUE", false: "FALSE" }{ true: string, false: string }
charsetEncoding for the CSV file"utf8"string
newLineCharacters used for line breaks in CSV"\r\n"string
NaNTextText 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.

1.3.1

2 months ago

1.2.2

2 months ago

1.3.0

2 months ago

1.2.1

6 months ago

1.2.0

6 months ago

0.0.1

6 months ago

0.0.0

6 months ago

2.0.0

6 months ago

1.1.0

6 months ago

1.0.5

6 months ago

1.0.3

6 months ago

1.0.2

6 months ago

1.0.1

6 months ago

1.0.0

6 months ago