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

Commit

Permalink
samples: new cast sample
Browse files Browse the repository at this point in the history
  • Loading branch information
wdavidw committed Sep 28, 2018
1 parent c8339fe commit 1bfa7d2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -3,6 +3,7 @@

## Trunk

* samples: new cast sample
* package: upgrade to babel 7
* samples: new mixed api samples
* travis: support Node.js 10
Expand Down
24 changes: 24 additions & 0 deletions samples/options.cast.js
@@ -0,0 +1,24 @@

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

const data = `
2000-01-01,date1
2050-11-27,date2
`.trim()
const records = parse(data, {
cast: function(value, context){
if(context.index === 0){
return `${value}T05:00:00.000Z`
}else{
return context
}
},
trim: true
})
assert.deepEqual(records, [
[ '2000-01-01T05:00:00.000Z', {
quoting: false, lines: 1, count: 0, index: 1, header: false, column: 1 } ],
[ '2050-11-27T05:00:00.000Z', {
quoting: false, lines: 2, count: 1, index: 1, header: false, column: 1 } ]
])

0 comments on commit 1bfa7d2

Please sign in to comment.