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

Commit

Permalink
bom: work with sync module, fix #115
Browse files Browse the repository at this point in the history
  • Loading branch information
wdavidw committed Aug 7, 2020
1 parent 3332a5f commit c1237c3
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 11 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
@@ -1,6 +1,11 @@

# Changelog

## Trunk

Fix
* bom: work with sync module, fix #115

## Version 5.5.0

Feature:
Expand Down
15 changes: 11 additions & 4 deletions lib/es5/index.js
Expand Up @@ -112,10 +112,6 @@ function (_Transform) {
records: 0
};

if (options.bom === true) {
_this.push(bom_utf8);
}

_assertThisInitialized(_this);

return _this;
Expand Down Expand Up @@ -332,6 +328,7 @@ function (_Transform) {


if (this.info.records === 0) {
this.bom();
this.headers();
} // Emit and stringify the record if an object or an array

Expand Down Expand Up @@ -374,6 +371,7 @@ function (_Transform) {
key: "_flush",
value: function _flush(callback) {
if (this.info.records === 0) {
this.bom();
this.headers();
}

Expand Down Expand Up @@ -603,6 +601,15 @@ function (_Transform) {

return csvrecord;
}
}, {
key: "bom",
value: function bom() {
if (this.options.bom !== true) {
return;
}

this.push(bom_utf8);
}
}, {
key: "headers",
value: function headers() {
Expand Down
11 changes: 8 additions & 3 deletions lib/index.js
Expand Up @@ -49,9 +49,6 @@ class Stringifier extends Transform {
this.info = {
records: 0
}
if(options.bom === true){
this.push(bom_utf8)
}
this
}
normalize(options){
Expand Down Expand Up @@ -221,6 +218,7 @@ class Stringifier extends Transform {
}
// Emit the header
if(this.info.records === 0){
this.bom()
this.headers()
}
// Emit and stringify the record if an object or an array
Expand Down Expand Up @@ -256,6 +254,7 @@ class Stringifier extends Transform {
}
_flush(callback){
if(this.info.records === 0){
this.bom()
this.headers()
}
callback()
Expand Down Expand Up @@ -383,6 +382,12 @@ class Stringifier extends Transform {
}
return csvrecord
}
bom(){
if(this.options.bom !== true){
return
}
this.push(bom_utf8)
}
headers(){
if(this.options.header === false){
return
Expand Down
5 changes: 1 addition & 4 deletions lib/sync.js
Expand Up @@ -18,8 +18,5 @@ module.exports = function(records, options={}){
stringifier.write(record)
}
stringifier.end()
const res = data.join('');
return options.bom
? '\ufeff' + res
: res;
return data.join('')
}

0 comments on commit c1237c3

Please sign in to comment.