1.0.6 • Published 8 years ago

csv-mapper-lite v1.0.6

Weekly downloads
3
License
MIT
Repository
github
Last release
8 years ago

csv-mapper-lite

build Coverage Status node6.10.1 npm.io npm.io npm

A node.js library for parsing and mapping csv string into pre-defined format.

Installation

With yarn:

$ yarn add csv-mapper-lite

With npm:

$ npm install csv-mapper-lite

Tests

Tests are written using the futuristic JavaScript test runner, ava.

$ yarn test

API Documentation

process(input : String, mapping : Object) : String

const csvStr = 'col1,col2,col3,,\nworld,hello\n'
const Formatter = require('csv-mapper-lite')
const formatter = new Formatter(csvStr, {
  // required
  rules: {
    newCol1: { expr: 'this.B', defaultValue: '0' },
    newCol2: { expr: 'this.A', defaultValue: '0' },
    newCol3: { expr: 'this.B+this.A', defaultValue: '0' }
  },
  // optional. Additional options and their default values
  separator: ',',
  newLine: '\n',
  noHeader: false,
  shiftFirstRow: false,
  trimTrailing: false,
  dropLastRow: false,
  dropRow: '' // accepts an expression string which will be evaluated during formatting, if evaluation result returns true, current row will be dropped.
})

const output = formatter.process()
console.log(output);

Output:

'newCol1,newCol2,newCol3\nhello,world,helloworld'
1.0.6

8 years ago

1.0.5

8 years ago

1.0.4

8 years ago

1.0.3

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago