Skip to content

bwz3rbot/csv-util

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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');
    }

})();

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published