UNPKG

kokopu

Version:

A JavaScript/TypeScript library implementing the chess game rules and providing tools to read/write the standard chess file formats.

122 lines 4.38 kB
"use strict"; /*! * -------------------------------------------------------------------------- * * * * 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.InvalidPOJO = exports.InvalidPGN = exports.InvalidNotation = exports.InvalidFEN = exports.IllegalArgument = void 0; /** * This module contains the exceptions used by the library. * @module */ /** * Exception thrown when an invalid argument is passed to a function. */ class IllegalArgument { constructor(functionName) { this.functionName = functionName; } /** * @ignore */ toString() { return `Illegal argument in function ${this.functionName}`; } } exports.IllegalArgument = IllegalArgument; /** * Exception thrown by the FEN parsing functions. */ class InvalidFEN { constructor(fen, message, ...tokens) { this.fen = fen; this.message = buildMessage(message, tokens); } /** * @ignore */ toString() { return toStringImpl('InvalidFEN', this.message); } } exports.InvalidFEN = InvalidFEN; /** * Exception thrown by the move notation parsing functions. */ class InvalidNotation { constructor(fen, notation, message, ...tokens) { this.fen = fen; this.notation = notation; this.message = buildMessage(message, tokens); } /** * @ignore */ toString() { return toStringImpl('InvalidNotation', this.message); } } exports.InvalidNotation = InvalidNotation; /** * Exception thrown by the PGN parsing functions. */ class InvalidPGN { constructor(pgn, index, lineNumber, message, ...tokens) { this.pgn = pgn; this.index = index; this.lineNumber = lineNumber; this.message = buildMessage(message, tokens); } /** * @ignore */ toString() { return toStringImpl('InvalidPGN', `[character=${this.index} line=${this.lineNumber}] ${this.message}`); } } exports.InvalidPGN = InvalidPGN; /** * Exception thrown by the POJO deserializing functions. */ class InvalidPOJO { constructor(pojo, fieldName, message, ...tokens) { this.pojo = pojo; this.fieldName = fieldName; this.message = buildMessage(message, tokens); } /** * @ignore */ toString() { return toStringImpl('InvalidPOJO', this.message); } } exports.InvalidPOJO = InvalidPOJO; function buildMessage(message, tokens) { return message.replace(/{(\d+)}/g, (match, placeholder) => { const placeholderIndex = Number(placeholder); return placeholderIndex < tokens.length ? String(tokens[placeholderIndex]) : match; }); } function toStringImpl(exceptionName, message) { return exceptionName + ' -> ' + message; } //# sourceMappingURL=exception.js.map