@mahdi.golzar/dynamicconvertdata

1.0.0 • Public • Published

DynamicDataConverter

DynamicDataConverter is a versatile tool for converting data between various formats. It supports dynamic format handling and allows for easy extension to new formats and conversions.

Features

  • Dynamic Format Handling: Supports conversion between various data formats dynamically.
  • Custom Format Registration: Register and use custom formats and converters.
  • File Conversion: Convert data files between formats.
  • Easy to Use: Simple methods to handle data and files.

Installation

No installation is required for this code as it is self-contained and can be added directly to your project. Ensure you have the following packages:

npm install json2csv csv-parse

Usage

  1. Create a DynamicDataConverter Instance
    const converter = new DynamicDataConverter();
  2. Convert Data Between Formats
   const jsonArray = [
   { id: 1, name: 'John Doe', email: 'john.doe@example.com' },
   { id: 2, name: 'Jane Doe', email: 'jane.doe@example.com' }
   ];

// Convert JSON to CSV

const csvData = converter.convert(jsonArray, 'json', 'csv');
console.log('CSV Data:\n', csvData);

// Convert CSV to JSON
const csvString = `id,name,email\n1,John Doe,john.doe@example.com\n2,Jane Doe,jane.doe@example.com`;
const jsonData = converter.convert(csvString, 'csv', 'json');
console.log('JSON Data:\n', jsonData);
  1. Save to and Read from Files Save Data to a File
    converter.saveToFile(csvData, './data.csv');
    Read Data from a File
    const fileContent = converter.readFromFile('./data.csv');
    console.log('File Content:\n', fileContent);
  2. Convert File Formats
    converter.convertFromFile('./data.csv', 'csv', 'json');

Readme

Keywords

Package Sidebar

Install

npm i @mahdi.golzar/dynamicconvertdata

Weekly Downloads

1

Version

1.0.0

License

ISC

Unpacked Size

4.26 kB

Total Files

3

Last publish

Collaborators

  • mahdi.golzar