Skip to content

Commit

Permalink
Merge bf3feaa into cc2928f
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaukov committed Jun 12, 2019
2 parents cc2928f + bf3feaa commit 974106a
Show file tree
Hide file tree
Showing 2 changed files with 14 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
7 changes: 7 additions & 0 deletions package.json
@@ -1,5 +1,6 @@
{
"name": "pbn",
"version": "1.0.0",
"description": "Parse and transform a PBN stream",
"homepage": "https://github.com/richardschneider/pbn",
"bugs": "https://github.com/richardschneider/pbn/issues",
Expand All @@ -21,6 +22,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 974106a

Please sign in to comment.