UNPKG

kokopu

Version:

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

107 lines (106 loc) 5.53 kB
/*! * -------------------------------------------------------------------------- * * * * 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/>. * * * * -------------------------------------------------------------------------- */ /** * Date of a chess game. It can be either partially defined (with the year only, or with the year and month but without day of month), * or fully defined (with year, month and day of month). * * @see {@link Game.date} */ export declare class DateValue { #private; /** * @param month - If provided, must be between 1 (January) and 12 (December) inclusive. * @param day - If provided, must be between 1 and the number of days in the corresponding month (thus 31 at most). */ constructor(year: number, month?: number, day?: number); /** * Construct a {@link DateValue} object from a standard JavaScript [Date](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date) * object. * * With this constructor, the type of the returned object is always `'ymd'` (see {@link DateValue.type}). */ constructor(date: Date); /** * Type of date value: * - `'y'` means that only the year is defined, * - `'ym'` means that the year and the month are defined, but not the day in month, * - `'ymd'` means that the exact day is defined. */ type(): 'y' | 'ym' | 'ymd'; /** * Year (e.g. `2022`). */ year(): number; /** * Month index, valued between 1 (January) and 12 (December) inclusive. * * @throws {@link exception.IllegalArgument} if the current type is `'y'` (see {@link DateValue.type}). */ month(): number; /** * Day in month, valued between 1 and the number of days in the corresponding month (thus 31 at most). * * @throws {@link exception.IllegalArgument} if the current type is `'y'` or `'ym'` (see {@link DateValue.type}). */ day(): number; /** * Convert the current object into a standard JavaScript [Date](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date) * object. * * If the type of the current object is `'ym'`, the returned `Date` object points at the first day of the corresponding month. * If the type of the current object is `'y'`, the returned `Date` object points at the first day of the corresponding year. */ toDate(): Date; /** * Get the date in a compact format (e.g. `'2022-07-19'`, `'2022-07-**'` or `'2022-**-**'` depending on the type of the current object). */ toString(): string; /** * Parse the given value as a date in compact format (e.g. `'2022-07-19'`, `'2022-07-**'` or `'2022-**-**'`). * * @returns `undefined` if the value does not represent a valid date. */ static fromString(value: string): DateValue | undefined; /** * Get the date in a PGN format (e.g. `'2022.07.19'`, `'2022.07.??'` or `'2022.??.??'` depending on the type of the current object). */ toPGNString(): string; /** * Parse the given value as a date in PGN format (e.g. `'2022.07.19'`, `'2022.07.??'` or `'2022.??.??'`). * * @returns `undefined` if the value does not represent a valid date. */ static fromPGNString(value: string): DateValue | undefined; /** * Get the date of the game as a human-readable string (e.g. `'November 1955'`, `'September 4, 2021'`). * * @param locales - Locales to use to generate the result. If undefined, the default locale of the execution environment is used. * See [Intl documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#locale_identification_and_negotiation) * for more details. */ toHumanReadableString(locales?: string | string[] | undefined): string; /** * Whether the given year/month/day would corresponds to a valid date or not. */ static isValid(year: number, month?: number, day?: number): boolean; }