Skip to content

File Handling Toolkit is a Node.js package that provides utility functions for handling files, including reading and writing text files, as well as reading CSV files and converting them to arrays of objects.

License

Notifications You must be signed in to change notification settings

iamvirul/file-handling-toolkit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

File Handling Toolkit

File Handling Toolkit is a Node.js package that provides utility functions for handling files, including reading and writing text files, as well as reading CSV files and converting them to arrays of objects.

Installation

You can install the File Handling Toolkit package via npm:

npm install file-handling-toolkit

Usage

Read a File

const { readFile } = require('file-handling-toolkit');

readFile('example.txt')
  .then(data => {
    console.log('File content:', data);
  })
  .catch(error => {
    console.error('Error reading file:', error);
  });

Write to a File

const { writeFile } = require('file-handling-toolkit');

const data = 'Hello, world!';
writeFile('output.txt', data)
  .then(() => {
    console.log('Data written to file successfully!');
  })
  .catch(error => {
    console.error('Error writing to file:', error);
  });

Append to a File

const { writeFile } = require('file-handling-toolkit');

const data = 'Appending this text.';
writeFile('output.txt', data, true)
  .then(() => {
    console.log('Data appended to file successfully!');
  })
  .catch(error => {
    console.error('Error appending to file:', error);
  });

Read a CSV File

const { readCsvToArray } = require('file-handling-toolkit');

readCsvToArray('example.csv')
  .then(data => {
    console.log('CSV Data:', data);
  })
  .catch(error => {
    console.error('Error reading CSV file:', error);
  });

API Reference

readFile(filePath: string): Promise<string>

Reads the contents of a file and returns a Promise that resolves with the file content as a string.

  • filePath: Path to the file to be read.

writeFile(filePath: string, data: string, append?: boolean): Promise<void>

Writes data to a file and returns a Promise that resolves when the operation completes successfully.

  • filePath: Path to the file to write.
  • data: Data to be written to the file.
  • append (optional): If true, appends data to the file instead of overwriting it. Defaults to false.

readCsvToArray(filePath: string): Promise<object[]>

Reads a CSV file and returns a Promise that resolves with the content of the CSV file as an array of objects.

  • filePath: Path to the CSV file to be read.

License

This project is licensed under the MIT License - see the LICENSE file for details.


Explanation:

  1. Append to a File Feature: Added an example usage for appending data to an existing file.
  2. API Reference Update: Updated the writeFile function in the API reference to include the new optional append parameter.

This updated README.md provides clear instructions and examples for users on how to use the new appending feature along with the existing file read, write, and CSV read features.

About

File Handling Toolkit is a Node.js package that provides utility functions for handling files, including reading and writing text files, as well as reading CSV files and converting them to arrays of objects.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published