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

Commit

Permalink
fix(bom): BOM should be included when requested in sync
Browse files Browse the repository at this point in the history
Fixes #114
  • Loading branch information
tomyam1 committed Jul 9, 2020
1 parent ece5cc4 commit c873bf1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/sync.js
Expand Up @@ -18,5 +18,8 @@ module.exports = function(records, options={}){
stringifier.write(record)
}
stringifier.end()
return data.join('')
const res = data.join('');
return options.bom
? '\ufeff' + res
: res;
}
21 changes: 21 additions & 0 deletions test/option.bom.coffee
@@ -1,5 +1,6 @@

stringify = require '../lib'
stringifySync = require '../lib/sync'

describe 'Option `bom`', ->

Expand All @@ -23,3 +24,23 @@ describe 'Option `bom`', ->
], bom: false, (err, data) ->
data.should.eql 'ok\n'
next()

describe 'sync ', ->
it 'validate', ->
(->
stringifySync [], bom: 'invalid'
).should.throw
code: 'CSV_OPTION_BOOLEAN_INVALID_TYPE'
message: 'option `bom` is optional and must be a boolean value, got "invalid"'

it 'value is `true`', ->
res = stringifySync [
value: 'ok'
], bom: true
res.should.eql '\ufeffok\n'

it 'value is `false`', ->
res = stringifySync [
value: 'ok'
], bom: false
res.should.eql 'ok\n'

0 comments on commit c873bf1

Please sign in to comment.