UNPKG

@freemework/common

Version:

Common library of the Freemework Project.

260 lines (259 loc) 10.2 kB
import { FException } from "../exception/f_exception.js"; export declare abstract class FDecimal { static readonly REGEXP: RegExp; private static _cfg; private static get cfg(); private static get backend(); static get settings(): FDecimalSettings; static configure(backend: FDecimalBackend): void; /** * Analog of Math​.abs() * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/abs */ static abs(value: FDecimal): FDecimal; static add(left: FDecimal, right: FDecimal): FDecimal; static divide(left: FDecimal, right: FDecimal, roundMode?: FDecimalRoundMode): FDecimal; static equals(left: FDecimal, right: FDecimal): boolean; static fromFloat(value: number, roundMode?: FDecimalRoundMode): FDecimal; static fromInt(value: number): FDecimal; static gt(left: FDecimal, right: FDecimal): boolean; static gte(left: FDecimal, right: FDecimal): boolean; static inverse(value: FDecimal): FDecimal; static isDecimal(test: any): test is FDecimal; static isNegative(test: FDecimal): boolean; static isPositive(test: FDecimal): boolean; static isZero(test: FDecimal): boolean; static lt(left: FDecimal, right: FDecimal): boolean; static lte(left: FDecimal, right: FDecimal): boolean; /** * Analog of Math.max() * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/max */ static max(left: FDecimal, right: FDecimal): FDecimal; /** * Analog of Math.min() * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/min */ static min(left: FDecimal, right: FDecimal): FDecimal; static mod(left: FDecimal, right: FDecimal, roundMode?: FDecimalRoundMode): FDecimal; static multiply(left: FDecimal, right: FDecimal, roundMode?: FDecimalRoundMode): FDecimal; static parse(value: string): FDecimal; static round(value: FDecimal, fractionDigits: FDecimalFractionDigits, roundMode?: FDecimalRoundMode): FDecimal; static subtract(left: FDecimal, right: FDecimal): FDecimal; abstract abs(): FDecimal; abstract add(value: FDecimal): FDecimal; abstract divide(value: FDecimal, roundMode?: FDecimalRoundMode): FDecimal; abstract equals(value: FDecimal): boolean; abstract inverse(): FDecimal; abstract isNegative(): boolean; abstract isPositive(): boolean; abstract isZero(): boolean; abstract mod(value: FDecimal, roundMode?: FDecimalRoundMode): FDecimal; abstract multiply(value: FDecimal, roundMode?: FDecimalRoundMode): FDecimal; abstract round(fractionDigits: FDecimalFractionDigits, roundMode?: FDecimalRoundMode): FDecimal; abstract subtract(value: FDecimal): FDecimal; abstract toNumber(): number; abstract toString(): string; abstract toJSON(): string; } export type FDecimalFractionDigits = number; export declare function isDecimalFraction(test: number): test is FDecimalFractionDigits; export declare function verifyDecimalFraction(test: FDecimalFractionDigits): asserts test is FDecimalFractionDigits; export declare enum FDecimalRoundMode { /** * Round to the smallest Financial greater than or equal to a given Financial. * * In other words: Round UP * * Example of Ceil to fraction:2 * * 0.595 -> 0.60 * * 0.555 -> 0.56 * * 0.554 -> 0.56 * * -0.595 -> -0.59 * * -0.555 -> -0.55 * * -0.554 -> -0.55 */ Ceil = "Ceil", /** * Round to the largest Financial less than or equal to a given Financial. * * In other words: Round DOWN * * Example of Floor to fraction:2 * * 0.595 -> 0.59 * * 0.555 -> 0.55 * * 0.554 -> 0.55 * * -0.595 -> -0.60 * * -0.555 -> -0.56 * * -0.554 -> -0.56 */ Floor = "Floor", /** * Round to the Financial rounded to the nearest Financial. * * In other words: Round classic * * Example of Round to fraction:2 * * 0.595 -> 0.60 * * 0.555 -> 0.56 * * 0.554 -> 0.55 * * -0.595 -> -0.60 * * -0.555 -> -0.55 * * -0.554 -> -0.55 */ Round = "Round", /** * Round to the Financial by removing fractional digits. * * Works same as Floor in positive range. * * Works same as Ceil in negative range * * Example of Trunc to fraction:2 * * 0.595 -> 0.59 * * 0.555 -> 0.55 * * 0.554 -> 0.55 * * -0.595 -> -0.59 * * -0.555 -> -0.55 * * -0.554 -> -0.55 */ Trunc = "Trunc" } export declare class FDecimalRoundModeUnreachableException extends FException { constructor(roundMode: never); } export interface FDecimalBackend { readonly settings: FDecimalSettings; /** * Analog of Math​.abs() * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/abs */ abs(value: FDecimal): FDecimal; add(left: FDecimal, right: FDecimal): FDecimal; divide(left: FDecimal, right: FDecimal, roundMode?: FDecimalRoundMode): FDecimal; equals(left: FDecimal, right: FDecimal): boolean; fromFloat(value: number, roundMode?: FDecimalRoundMode): FDecimal; fromInt(value: number): FDecimal; gt(left: FDecimal, right: FDecimal): boolean; gte(left: FDecimal, right: FDecimal): boolean; inverse(value: FDecimal): FDecimal; isDecimal(test: any): test is FDecimal; isNegative(test: FDecimal): boolean; isPositive(test: FDecimal): boolean; isZero(test: FDecimal): boolean; lt(left: FDecimal, right: FDecimal): boolean; lte(left: FDecimal, right: FDecimal): boolean; /** * Analog of Math.max() * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/max */ max(left: FDecimal, right: FDecimal): FDecimal; /** * Analog of Math.min() * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/min */ min(left: FDecimal, right: FDecimal): FDecimal; mod(left: FDecimal, right: FDecimal, roundMode?: FDecimalRoundMode): FDecimal; multiply(left: FDecimal, right: FDecimal, roundMode?: FDecimalRoundMode): FDecimal; parse(value: string): FDecimal; round(value: FDecimal, fractionDigits: FDecimalFractionDigits, roundMode?: FDecimalRoundMode): FDecimal; subtract(left: FDecimal, right: FDecimal): FDecimal; toNumber(value: FDecimal): number; toString(value: FDecimal): string; } export interface FDecimalSettings { readonly decimalSeparator: string; readonly fractionalDigits: number; readonly roundMode: FDecimalRoundMode; } export declare namespace FDecimal { /** * @deprecated Use FDecimalFraction instead */ type FractionDigits = FDecimalFractionDigits; /** * @deprecated Use FDecimalFraction instead */ namespace FractionDigits { /** * @deprecated Use isDecimalFraction instead */ const isDecimalFractionDigits: (test: number) => test is FDecimalFractionDigits; /** * @deprecated Use verifyDecimalFraction instead */ const verifyFraction: (test: FDecimalFractionDigits) => asserts test is FDecimalFractionDigits; } /** * @deprecated Use FDecimalBackend instead */ type Backend = FDecimalBackend; /** * @deprecated Use FDecimalRoundMode instead */ type RoundMode = FDecimalRoundMode; /** * Use FDecimalSettings instead */ type Settings = FDecimalSettings; /** * @deprecated Use FDecimalRoundModeUnreachableException instead */ type UnreachableRoundMode = FDecimalRoundModeUnreachableException; } export declare class FDecimalBase<TInstance, TBackend extends FDecimalBackend> implements FDecimal { private readonly _instance; private readonly _backend; constructor(instance: TInstance, backend: TBackend); get instance(): TInstance; abs(): FDecimal; add(value: FDecimal): FDecimal; divide(value: FDecimal, roundMode?: FDecimalRoundMode): FDecimal; equals(value: FDecimal): boolean; inverse(): FDecimal; isNegative(): boolean; isPositive(): boolean; isZero(): boolean; mod(value: FDecimal): FDecimal; multiply(value: FDecimal, roundMode?: FDecimalRoundMode): FDecimal; round(fractionDigits: FDecimalFractionDigits, roundMode?: FDecimalRoundMode): FDecimal; subtract(value: FDecimal): FDecimal; toNumber(): number; toString(): string; toJSON(): string; protected get backend(): TBackend; } export declare class FDecimalBackendNumber implements FDecimalBackend { private static verifyInstance; readonly settings: FDecimalSettings; /** * * @param roundMode Default value is FDecimalRoundMode.Round */ constructor(fractionalDigits: number, roundMode: FDecimalRoundMode); abs(value: FDecimal): FDecimal; add(left: FDecimal, right: FDecimal): FDecimal; divide(left: FDecimal, right: FDecimal, roundMode?: FDecimalRoundMode | undefined): FDecimal; equals(left: FDecimal, right: FDecimal): boolean; fromFloat(value: number, _?: FDecimalRoundMode | undefined): FDecimal; fromInt(value: number): FDecimal; gt(left: FDecimal, right: FDecimal): boolean; gte(left: FDecimal, right: FDecimal): boolean; inverse(value: FDecimal): FDecimal; isDecimal(test: any): test is FDecimal; isNegative(test: FDecimal): boolean; isPositive(test: FDecimal): boolean; isZero(test: FDecimal): boolean; lt(left: FDecimal, right: FDecimal): boolean; lte(left: FDecimal, right: FDecimal): boolean; max(left: FDecimal, right: FDecimal): FDecimal; min(left: FDecimal, right: FDecimal): FDecimal; mod(left: FDecimal, right: FDecimal, roundMode?: FDecimalRoundMode): FDecimal; multiply(left: FDecimal, right: FDecimal, roundMode?: FDecimalRoundMode | undefined): FDecimal; parse(value: string): FDecimal; round(value: FDecimal, fractionDigits: number, roundMode?: FDecimalRoundMode | undefined): FDecimal; private _round; subtract(left: FDecimal, right: FDecimal): FDecimal; toNumber(value: FDecimal): number; toString(value: FDecimal): string; }