chess-moments 0.10.0 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -9,6 +9,7 @@ const prepare = require('./prepare');
9
9
  const prettify = require('./prettify');
10
10
  const shape = require('./shape');
11
11
  const split = require('./split');
12
+ const train = require('./train');
12
13
  const tree = require('./tree');
13
14
 
14
15
  module.exports = {
@@ -23,5 +24,6 @@ module.exports = {
23
24
  prettify,
24
25
  shape,
25
26
  split,
27
+ train,
26
28
  tree,
27
29
  };
@@ -1,9 +1,7 @@
1
1
  module.exports = (comment) => {
2
2
  try {
3
- return comment
4
- .split(']')
5
- .map((it) => it.trim())
6
- .filter((it) => it.indexOf('[') !== 0)[0];
3
+ // Remove any shape comments like [%cal Ya7,Ya6] or [%csl Ya7,Ya6]
4
+ return comment.replace(/\s*\[%c(?:al|sl) [^\]]+\]/g, '').trim();
7
5
  } catch (err) {
8
6
  return undefined;
9
7
  }
@@ -0,0 +1,21 @@
1
+ const flat = require('./flat');
2
+
3
+ const train = (sloppyPgn, moveIndex) => {
4
+ const moments = flat(sloppyPgn);
5
+
6
+ // Remove sidelines (depth > 1) when no move index is specified
7
+ if (!moveIndex) {
8
+ return moments.filter((moment) => moment.depth === 1);
9
+ }
10
+
11
+ // Split the moments into two groups
12
+ const before = moments.slice(0, moveIndex);
13
+ const after = moments.slice(moveIndex);
14
+
15
+ // Remove sidelines after the specified move index with the move index depth
16
+ const filtered = after.filter((moment) => moment.depth <= moments[moveIndex].depth);
17
+
18
+ return before.concat(filtered);
19
+ };
20
+
21
+ module.exports = train;
package/index.js CHANGED
@@ -1,8 +1,9 @@
1
- const { fen, pgn, flat, tree } = require('./functions');
1
+ const { fen, pgn, flat, train, tree } = require('./functions');
2
2
 
3
3
  module.exports = {
4
4
  fen,
5
5
  pgn,
6
6
  flat,
7
+ train,
7
8
  tree,
8
9
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chess-moments",
3
- "version": "0.10.0",
3
+ "version": "0.11.0",
4
4
  "description": "PGN reader is a javascript chess library that transforms PGN files into chess moments",
5
5
  "main": "dist/index.js",
6
6
  "files": [