1.1.1 • Published 2 years ago

@teddy1565/csv-pattern v1.1.1

Weekly downloads
-
License
ISC
Repository
-
Last release
2 years ago

csv-pattern

How to Use

Create Model

const path = require('path');

const BASIC_MODEL = {
    fileName: '$pid/$name/output.csv',
    fields: [
        { colName: 'date', type: 'number' },
        { colName: 'sys', type: 'string' }
    ]
};

const options = {
    standdir: path.join(__dirname, 'output');
}

const model = new csv(BASIC_MODEL, options);

async function progress () {
    await csv.create({
        pid: 'test',
        name: 'james'
    });
    // new csv file in __dirname/output/test/james/output.csv
    
    await csv.insert({
        pid: 'test',
        name: 'james'
    }, [
        {
            date: Date.now(),
            sys: 'hello world'
        },
        {
            date: 123456,
            sys: 'good bye'
        }
    ]);
    /*
        __dirname/output/test/james/output.csv

        pid;name
        1654430957237;"hello world"
        123456;"good bye"
    */
    
    let payload = await csv.read({
        pid: 'test',    //must
        name: 'james'   //optional
    }, [
        {
            callback:(x) => {
                console.log(x);
                /*
                    first round:
                    {
                        pid: "1654430957237", 
                        name: "hello world"
                    }

                    second round:
                    {
                        pid: "123456"
                        name: "good bye"
                    }
                    
                */
                if (x.pid === "123456") {
                    return x;
                }
            }
        }
    ]);

    console.log(payload);
    /*
        [
            {
                pid: "123456",
                name: "good bye"
            }
        ]
    */
}
1.1.1

2 years ago

1.1.0

2 years ago

1.0.10

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago