Skip to content
This repository has been archived by the owner on Jun 28, 2021. It is now read-only.

Commit

Permalink
columns: examples
Browse files Browse the repository at this point in the history
  • Loading branch information
wdavidw committed Nov 19, 2018
1 parent 33dc238 commit ffed6c7
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 7 deletions.
11 changes: 4 additions & 7 deletions samples/options.columns.js → samples/options.columns.array.js
Expand Up @@ -2,13 +2,10 @@
const parse = require('../lib')
const assert = require('assert')

const records = parse(`
"key_1","key_2"
"value 1","value 2"
`, {
columns: true,
trim: true,
skip_empty_lines: true
parse(`
"value 1","value 2"
`.trim(), {
columns: ['key_1', 'key_2']
}, function(err, records){
assert.deepEqual(
records, [{
Expand Down
18 changes: 18 additions & 0 deletions samples/options.columns.function.js
@@ -0,0 +1,18 @@

const parse = require('../lib')
const assert = require('assert')

parse(`
"key_1","key_2"
"value 1","value 2"
`.trim(), {
columns: header =>
header.map( column => column.toUpperCase() )
}, function(err, records){
assert.deepEqual(
records, [{
KEY_1: 'value 1',
KEY_2: 'value 2'
}]
)
})
17 changes: 17 additions & 0 deletions samples/options.columns.true.js
@@ -0,0 +1,17 @@

const parse = require('../lib')
const assert = require('assert')

parse(`
"key_1","key_2"
"value 1","value 2"
`.trim(), {
columns: true
}, function(err, records){
assert.deepEqual(
records, [{
key_1: 'value 1',
key_2: 'value 2'
}]
)
})

0 comments on commit ffed6c7

Please sign in to comment.