cm-chessboard 7.7.6 → 7.7.7

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cm-chessboard",
3
- "version": "7.7.6",
3
+ "version": "7.7.7",
4
4
  "description": "A JavaScript chessboard which is lightweight, ES6 module based, responsive, SVG rendered and without dependencies.",
5
5
  "keywords": [
6
6
  "chess",
@@ -110,14 +110,23 @@ export class Position {
110
110
  }
111
111
 
112
112
  static squareToIndex(square) {
113
- const file = square.substring(0, 1).charCodeAt(0) - 97
114
- const rank = square.substring(1, 2) - 1
115
- return 8 * rank + file
113
+ const coordinates = Position.squareToCoordinates(square)
114
+ return coordinates[0] + coordinates[1] * 8
116
115
  }
117
116
 
118
117
  static indexToSquare(index) {
119
- const file = String.fromCharCode(index % 8 + 97)
120
- const rank = Math.floor(index / 8) + 1
118
+ return this.coordinatesToSquare([Math.floor(index % 8), index / 8])
119
+ }
120
+
121
+ static squareToCoordinates(square) {
122
+ const file = square.charCodeAt(0) - 97
123
+ const rank = square.charCodeAt(1) - 49
124
+ return [file, rank]
125
+ }
126
+
127
+ static coordinatesToSquare(coordinates) {
128
+ const file = String.fromCharCode(coordinates[0] + 97)
129
+ const rank = String.fromCharCode(coordinates[1] + 49)
121
130
  return file + rank
122
131
  }
123
132