chess-moments 1.5.0 → 1.6.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.
@@ -0,0 +1,22 @@
1
+ const glyphs = {
2
+ $7: '□', // Only move
3
+ $22: '⨀', // Zugzwang
4
+ $10: '=', // Equal position
5
+ $13: '∞', // Unclear position
6
+ $14: '⩲', // White is slightly better
7
+ $15: '⩱', // Black is slightly better
8
+ $16: '±', // White is better
9
+ $17: '∓', // Black is better
10
+ $18: '+−', // White is winning
11
+ $19: '-+', // Black is winning
12
+ $146: 'N', // Novelty
13
+ $32: '↑↑', // Development
14
+ $36: '↑', // Initiative
15
+ $40: '→', // Attack
16
+ $132: '⇆', // Counterplay
17
+ $138: '⊕', // Time trouble
18
+ $44: '=∞', // With compensation
19
+ $140: '∆', // With the idea
20
+ };
21
+
22
+ module.exports = glyphs;
@@ -1,7 +1,17 @@
1
1
  const prettify = require('./prettify');
2
2
  const shape = require('./shape');
3
3
 
4
- module.exports = ({ depth, move, fen, comment, suffix, from, to, headers }) => {
4
+ module.exports = ({
5
+ depth,
6
+ move,
7
+ fen,
8
+ comment,
9
+ suffix,
10
+ glyph,
11
+ from,
12
+ to,
13
+ headers,
14
+ }) => {
5
15
  const moment = { depth, fen };
6
16
  if (move) {
7
17
  moment.move = move;
@@ -23,6 +33,9 @@ module.exports = ({ depth, move, fen, comment, suffix, from, to, headers }) => {
23
33
  if (suffix) {
24
34
  moment.suffix = suffix;
25
35
  }
36
+ if (glyph) {
37
+ moment.glyph = glyph;
38
+ }
26
39
  if (headers) {
27
40
  moment.headers = headers;
28
41
  }
@@ -142,6 +142,11 @@ const momentsToPgn = (moments) => {
142
142
  pgn += moment.suffix;
143
143
  }
144
144
 
145
+ // Add glyph if present (keep as NAG code from original PGN)
146
+ if (moment.glyph) {
147
+ pgn += ` ${moment.glyph}`;
148
+ }
149
+
145
150
  // Add comment if present
146
151
  if (moment.comment) {
147
152
  pgn += ` {${moment.comment}}`;
@@ -1,7 +1,9 @@
1
1
  const { Chess } = require('chess.js');
2
+ const { invert } = require('lodash');
2
3
  const { initial } = require('./fen');
3
4
  const pgn = require('./pgn');
4
5
  const moment = require('./moment');
6
+ const glyphs = require('../constants/glyphs');
5
7
 
6
8
  module.exports = (moves, fen = initial, depth = 1, headers = null) => {
7
9
  const chess = new Chess();
@@ -30,6 +32,7 @@ module.exports = (moves, fen = initial, depth = 1, headers = null) => {
30
32
  to: item.to,
31
33
  comment: chess.getComment(),
32
34
  suffix: chess.getSuffixAnnotation(),
35
+ glyph: invert(glyphs)[chess.getGlyph()],
33
36
  fen: chess.fen(),
34
37
  });
35
38
  });
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "chess-moments",
3
- "version": "1.5.0",
3
+ "version": "1.6.0",
4
4
  "description": "PGN parser that transforms PGN files into chess \"moments\"",
5
5
  "main": "index.js",
6
6
  "files": [
7
7
  "index.js",
8
8
  "chess.js",
9
- "functions/**/*.js"
9
+ "functions/**/*.js",
10
+ "constants/**/*.js"
10
11
  ],
11
12
  "scripts": {
12
13
  "test": "mocha",
@@ -24,7 +25,7 @@
24
25
  ],
25
26
  "license": "MIT",
26
27
  "dependencies": {
27
- "chess.js": "github:jhlywa/chess.js#master"
28
+ "chess.js": "github:brobert1/chess.js#master"
28
29
  },
29
30
  "devDependencies": {
30
31
  "chai": "^4.3.7",