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 🙏

© 2026 – Pkg Stats / Ryan Hefner

data-flip

v1.0.1

Published

A generic utility library for converting between JSON, CSV, TXT, and XLSX formats with auto-detection

Readme

Data Format Converter

A lightweight, generic Node.js utility library for converting between JSON, CSV, TXT, and XLSX formats with automatic delimiter detection.

Features

  • JSON ↔ CSV conversion
  • JSON ↔ TXT conversion
  • CSV ↔ TXT conversion
  • XLSX → CSV conversion
  • Auto-detect delimiters (comma, tab, etc.)
  • Simple API - Easy to use
  • Zero configuration - Works out of the box
  • Flexible options - Customize as needed

Installation

npm install data-flip

Usage

Import the library

const DataFormatConverter = require('data-flip');

JSON to CSV

const jsonData = [
  { name: 'John', age: 30, city: 'New York' },
  { name: 'Jane', age: 25, city: 'London' }
];

const csv = DataFormatConverter.jsonToCsv(jsonData);
console.log(csv);
// Output:
// name,age,city
// John,30,New York
// Jane,25,London

CSV to JSON

const csvString = `name,age,city
John,30,New York
Jane,25,London`;

const json = DataFormatConverter.csvToJson(csvString);
console.log(json);
// Output:
// [
//   { name: 'John', age: '30', city: 'New York' },
//   { name: 'Jane', age: '25', city: 'London' }
// ]

JSON to TXT (Tab-delimited)

const jsonData = [
  { name: 'John', age: 30, city: 'New York' },
  { name: 'Jane', age: 25, city: 'London' }
];

const txt = DataFormatConverter.jsonToTxt(jsonData);
console.log(txt);
// Output:
// name	age	city
// John	30	New York
// Jane	25	London

TXT to JSON (Auto-detect delimiter)

const txtString = `name\tage\tcity
John\t30\tNew York
Jane\t25\tLondon`;

const json = DataFormatConverter.txtToJson(txtString);
console.log(json);
// Output:
// [
//   { name: 'John', age: '30', city: 'New York' },
//   { name: 'Jane', age: '25', city: 'London' }
// ]

TXT to CSV

const txtString = `name\tage\tcity
John\t30\tNew York
Jane\t25\tLondon`;

const csv = DataFormatConverter.txtToCsv(txtString);
console.log(csv);
// Output:
// name,age,city
// John,30,New York
// Jane,25,London

CSV to TXT

const csvString = `name,age,city
John,30,New York
Jane,25,London`;

const txt = DataFormatConverter.csvToTxt(csvString);
console.log(txt);
// Output:
// name	age	city
// John	30	New York
// Jane	25	London

XLSX to CSV

// Convert from file path
const csv = DataFormatConverter.xlsxToCsv('./data.xlsx');
console.log(csv);
// Output:
// name,age,city
// John,30,New York
// Jane,25,London

// Convert specific sheet by name
const csv2 = DataFormatConverter.xlsxToCsv('./data.xlsx', { 
  sheetName: 'Sheet2' 
});

// Convert specific sheet by index
const csv3 = DataFormatConverter.xlsxToCsv('./data.xlsx', { 
  sheetIndex: 1 
});

// Convert from Buffer (useful for uploaded files)
const fs = require('fs');
const buffer = fs.readFileSync('./data.xlsx');
const csv4 = DataFormatConverter.xlsxToCsv(buffer);

Auto-detect and Convert to JSON

// Works with CSV
const csvString = `name,age,city
John,30,New York`;

const json1 = DataFormatConverter.autoToJson(csvString);

// Works with tab-delimited
const txtString = `name	age	city
John	30	New York`;

const json2 = DataFormatConverter.autoToJson(txtString);

// Works with JSON string
const jsonString = '[{"name":"John","age":30}]';
const json3 = DataFormatConverter.autoToJson(jsonString);

API Reference

jsonToCsv(data, options)

Convert JSON to CSV format.

Parameters:

  • data (Array|Object): JSON data to convert
  • options (Object): Optional configuration
    • fields (Array): Field names to include (auto-detected if not provided)

Returns: CSV string


csvToJson(csvString, options)

Convert CSV to JSON format.

Parameters:

  • csvString (String): CSV string to convert
  • options (Object): Optional configuration
    • delimiter (String): Delimiter character (auto-detected if not provided)

Returns: Array of objects


jsonToTxt(data, options)

Convert JSON to delimited text format.

Parameters:

  • data (Array|Object): JSON data to convert
  • options (Object): Optional configuration
    • delimiter (String): Delimiter character (default: tab \t)
    • includeHeaders (Boolean): Include headers (default: true)

Returns: Delimited text string


txtToJson(txtString, options)

Convert delimited text to JSON format.

Parameters:

  • txtString (String): Delimited text string to convert
  • options (Object): Optional configuration
    • delimiter (String): Delimiter character (auto-detected if not provided)

Returns: Array of objects


txtToCsv(txtString, options)

Convert delimited text to CSV format.

Parameters:

  • txtString (String): Delimited text string to convert
  • options (Object): Optional configuration
    • inputDelimiter (String): Input delimiter (auto-detected if not provided)
    • outputDelimiter (String): Output delimiter (default: comma ,)

Returns: CSV string


csvToTxt(csvString, options)

Convert CSV to delimited text format.

Parameters:

  • csvString (String): CSV string to convert
  • options (Object): Optional configuration
    • inputDelimiter (String): Input delimiter (auto-detected if not provided)
    • outputDelimiter (String): Output delimiter (default: tab \t)

Returns: Delimited text string


autoToJson(data, options)

Auto-detect format and convert to JSON.

Parameters:

  • data (String): Input data string
  • options (Object): Optional configuration
    • delimiter (String): Delimiter character (auto-detected if not provided)

Returns: Array of objects


xlsxToCsv(xlsxData, options)

Convert XLSX file to CSV format.

Parameters:

  • xlsxData (String|Buffer): Path to XLSX file or Buffer containing XLSX data
  • options (Object): Optional configuration
    • sheetName (String): Sheet name to convert (default: first sheet)
    • sheetIndex (Number): Sheet index to convert (default: 0)

Returns: CSV string

Advanced Options

Custom Delimiters

// Use semicolon as delimiter
const csv = DataFormatConverter.jsonToCsv(data, { delimiter: ';' });

// Convert pipe-delimited to JSON
const json = DataFormatConverter.txtToJson(txtString, { delimiter: '|' });

Specify Fields

// Only include specific fields
const csv = DataFormatConverter.jsonToCsv(data, { 
  fields: ['name', 'age'] 
});

Without Headers

// Generate text without headers
const txt = DataFormatConverter.jsonToTxt(data, { 
  includeHeaders: false 
});

Error Handling

try {
  const json = DataFormatConverter.csvToJson(csvString);
} catch (error) {
  console.error('Conversion failed:', error.message);
}

License

MIT

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Support

For issues and questions, please open an issue on GitHub.