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.
package/functions/build-pgn.js
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
|
+
const decodeMoves = require('./decode-moves');
|
|
2
|
+
|
|
1
3
|
module.exports = (moves, fen) => {
|
|
2
|
-
|
|
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
|
|
@@ -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
|
-
|
|
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
|
-
|
|
9
|
-
|
|
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
|
-
|
|
19
|
+
return processedPgn;
|
|
13
20
|
};
|
package/functions/shape.js
CHANGED
|
@@ -3,10 +3,8 @@ const brush = require('./brush');
|
|
|
3
3
|
module.exports = (comment) => {
|
|
4
4
|
try {
|
|
5
5
|
const draw = [];
|
|
6
|
-
|
|
7
|
-
|
|
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"
|