kokopu
Version:
A JavaScript/TypeScript library implementing the chess game rules and providing tools to read/write the standard chess file formats.
60 lines • 3.15 kB
JavaScript
;
/*!
* -------------------------------------------------------------------------- *
* *
* Kokopu - A JavaScript/TypeScript chess library. *
* <https://www.npmjs.com/package/kokopu> *
* Copyright (C) 2018-2025 Yoann Le Montagner <yo35 -at- melix.net> *
* *
* Kokopu is free software: you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License *
* as published by the Free Software Foundation, either version 3 of *
* the License, or (at your option) any later version. *
* *
* Kokopu is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General *
* Public License along with this program. If not, see *
* <http://www.gnu.org/licenses/>. *
* *
* -------------------------------------------------------------------------- */
Object.defineProperty(exports, "__esModule", { value: true });
exports.pgnRead = pgnRead;
exports.pgnWrite = pgnWrite;
const database_1 = require("./database");
const exception_1 = require("./exception");
const game_1 = require("./game");
const pgn_read_impl_1 = require("./private_pgn/pgn_read_impl");
const pgn_write_impl_1 = require("./private_pgn/pgn_write_impl");
function pgnRead(pgnString, gameIndex) {
if (typeof pgnString !== 'string') {
throw new exception_1.IllegalArgument('pgnRead()');
}
if (arguments.length === 1) { // Parse all games (and return a Database object)...
return (0, pgn_read_impl_1.readDatabase)(pgnString);
}
else { // Parse one game...
if (!(0, database_1.isValidGameIndex)(gameIndex)) {
throw new exception_1.IllegalArgument('pgnRead()');
}
return (0, pgn_read_impl_1.readOneGame)(pgnString, gameIndex);
}
}
function pgnWrite(gameOrGames, options) {
if (options === undefined || options === null) {
options = {};
}
if (gameOrGames instanceof game_1.Game) {
return (0, pgn_write_impl_1.writeGame)(gameOrGames, options);
}
else if (Array.isArray(gameOrGames) && gameOrGames.every(game => game instanceof game_1.Game)) {
return (0, pgn_write_impl_1.writeGames)(gameOrGames, options);
}
else {
throw new exception_1.IllegalArgument('pgnWrite()');
}
}
//# sourceMappingURL=pgn.js.map