chess-moments 0.8.4 → 0.10.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.
@@ -1,5 +1,9 @@
1
+ const decodeMoves = require('./decode-moves');
2
+
1
3
  module.exports = (moves, fen) => {
2
- const decodedMoves = decodeURIComponent(moves);
4
+ // Remove opposing brackets and whitespace
5
+ const decodedMoves = decodeMoves(moves).replace(/}\s*{/g, '');
6
+
3
7
  const pgn = [
4
8
  `[FEN "${fen}"]`, // mandatory header info
5
9
  '[SetUp "1"]', // mandatory header info
@@ -0,0 +1,7 @@
1
+ module.exports = (moves) => {
2
+ try {
3
+ return decodeURIComponent(moves);
4
+ } catch {
5
+ return moves;
6
+ }
7
+ };
@@ -1,13 +1,20 @@
1
1
  const castle = require('./replace-castling');
2
2
 
3
3
  module.exports = (pgn) => {
4
+ let processedPgn = null;
5
+
4
6
  if (typeof pgn === 'string') {
5
- return castle(pgn.trim());
7
+ processedPgn = castle(pgn.trim());
8
+ } else if (Array.isArray(pgn)) {
9
+ processedPgn = castle(pgn.join('\n').trim());
10
+ } else {
11
+ throw new Error('Unsupported PGN type');
6
12
  }
7
13
 
8
- if (Array.isArray(pgn)) {
9
- return castle(pgn.join('\n').trim());
10
- }
14
+ // Remove newlines from comments delimited by curly braces
15
+ processedPgn = processedPgn.replace(/\{[^}]*\}/g, (match) => {
16
+ return match.replace(/\n/g, '\\n');
17
+ });
11
18
 
12
- throw new Error('Unsupported PGN type');
19
+ return processedPgn;
13
20
  };
@@ -3,10 +3,8 @@ const brush = require('./brush');
3
3
  module.exports = (comment) => {
4
4
  try {
5
5
  const draw = [];
6
- const shapeComments = comment
7
- .split(']')
8
- .map((it) => it.trim())
9
- .filter((it) => it.indexOf('[') === 0);
6
+ // Find all shape comments
7
+ const shapeComments = comment.match(/\[.*?\]/g);
10
8
 
11
9
  for (const shapeComment of shapeComments) {
12
10
  // transform "[%csl Ya7" into "Ya7"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chess-moments",
3
- "version": "0.8.4",
3
+ "version": "0.10.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": [