Skip to content

michaelstoner/csv-parser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Just a little module to try a couple of ideas out, it just extends https://github.com/adaltas/node-csv-parse

An example using this module:

'use strict'
const CsvParser = require('csv-parser')
const assert = require('assert')
const output = []

const parser = new CsvParser({
  delimiter: ':'
})
// Use the readable stream api
parser.on('readable', function () {
  let record
  while ((record = parser.read())) {
    output.push(record)
  }
})
// Catch any error
parser.on('error', function (err) {
  console.error(err.message)
})
parser.on('end', function () {
  assert.deepStrictEqual(
    output,
    [
      ['root', 'x', '0', '0', 'root', '/root', '/bin/bash'],
      ['someone', 'x', '1022', '1022', '', '/home/someone', '/bin/bash']
    ]
  )
})
parser.write('root:x:0:0:root:/root:/bin/bash\n')
parser.write('someone:x:1022:1022::/home/someone:/bin/bash\n')
// Close the readable stream
parser.end()

About

trying out a couple of things

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published