Skip to content

Commit

Permalink
Merge f7b05ae into aa78164
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaukov committed Apr 23, 2019
2 parents aa78164 + f7b05ae commit 3543fbd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
12 changes: 7 additions & 5 deletions lib/pbn-stream.js
Expand Up @@ -54,7 +54,7 @@ function parseDeal(s) {

PbnStream.prototype._transform = function(line, encoding, done) {
if (this.comment) {
if (line[0] === '}') {
if (line.endsWith('}')) {
this.produce(this.comment);
this.comment = undefined;
}
Expand Down Expand Up @@ -117,13 +117,14 @@ PbnStream.prototype._transform = function(line, encoding, done) {
this.produce(null);
this.ingame = false;
}
else if (line[0] === '{') {
else if (line.includes('{')) {
let braceIndex = line.indexOf('{');
this.comment = {
type: 'comment',
text: ''
};
let rest = line.slice(1).trim();
if (rest[rest.length - 1] === '}') {
let rest = line.slice(braceIndex + 1).trim();
if (rest.endsWith('}')) {
this.comment.text = rest.slice(0, -1).trim();
this.produce(this.comment);
this.comment = undefined;
Expand Down Expand Up @@ -162,8 +163,9 @@ PbnStream.prototype.produce = function(data) {
this.produce(tag);
}

if (data !== null)
if (data !== null) {
this.push(data);
}
};

let pbn = opts => pipe(lines(), new PbnStream(opts));
Expand Down
6 changes: 6 additions & 0 deletions package.json
Expand Up @@ -21,6 +21,12 @@
"name": "Richard Schneider",
"email": "makaretu@gmail.com"
},
"contributors": [
{
"name": "Peter Kaukov",
"email": "peter.kaukov@gmail.com"
}
],
"repository": {
"type": "git",
"url": "https://github.com/richardschneider/pbn"
Expand Down

0 comments on commit 3543fbd

Please sign in to comment.