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

fix(bom): BOM should be included when requested in sync #115

Merged
merged 1 commit into from Aug 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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'