Socket
Socket
Sign inDemoInstall

csv-append-write-read

Package Overview
Dependencies
37
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    csv-append-write-read

csv utility package


Version published
Weekly downloads
2
Maintainers
1
Created
Weekly downloads
 

Readme

Source

CSV Util

Using is simple.

To read a csv, simply require the module and await read.

(async () => {
    const csvUtil = require('../util/csv');

    const rows = await csvUtil.read('test.csv');

    console.log(rows);
})();

To write rows, create an array of objects with keys named after the columns and call csv.write

(async () => {

    const rows = [];
    for (let i = 0; i < 10; i++) {
        rows.push({
            columnNumber: i,
            ref: 'test'
        });
    }

    await require('./util/csv').write(rows, 'test.csv');
})();

To append rows on an already made csv, call csv.append.

(async () => {
    await require('fs/promises').writeFile('appendrows.csv', 'col1,col2,col3\n', 'utf-8');
    const csv = require('../util/csv');

    for (let i = 0; i < 5; i++) {
        await csv.append({
            col1: `data1-${i}`,
            col2: `data2-${i}`,
            col3: `data3-${i}`
        }, 'appendrows.csv');
    }

})();

FAQs

Last updated on 25 Nov 2021

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc