UNPKG

spell-vn-number

Version:
124 lines 3.85 kB
export type InputNumber = string | number | bigint; /** * Options for normalizing number strings */ export interface NormalizeOptions { /** * Custom thousands separator character * @default ',' */ thousandSign?: string; /** * Custom decimal point character * @default '.' */ decimalPoint?: string; } export interface NumberData { isNegative: boolean; integralPart: string; fractionalPart: string; } export declare class InvalidFormatError extends Error { name: string; constructor(message: string); } export declare class InvalidNumberError extends Error { name: string; constructor(message: string); } /** * Group and position indices * Chỉ số nhóm và vị trí */ export declare enum Idx { BIL = 0,// BILLION:tỷ MIL = 1,// MILLION:triệu THO = 2,// THOUSAND:nghìn HUN = 3,// HUNDREDS:trăm TEN = 4,// TENS:mươi UNI = 5 } export interface SpecificText { oddText: string; tenText: string; oneToneText: string; fourToneText: string; fiveToneText: string; } export declare class SpellerConfig { separator: string; negativeSign: string; decimalPoint: string; thousandSign: string; negativeText: string; pointText: string; capitalizeInitial: boolean; currencyUnit: string; /** * Character used to represent redundant zeros in number strings. * This character will be trimmed from both the beginning and end of numbers. * Default is '0'. */ redundantZeroChar: string; keepOneZeroWhenAllZeros: boolean; /** * Custom names for digits (chữ số) * @example { '4': 'tư' } */ digitNames: Record<string, string>; /** * Custom names for all units (đơn vị) * @example { * 0: 'tỉ', // magnitude unit: billion * 1: 'triệu', // magnitude unit: million * 2: 'nghìn', // magnitude unit: thousand * 3: 'trăm', // position unit: hundred * 4: 'mươi', // position unit: ten * 5: '' // position unit: unit * } */ unitNames: Record<number, string>; specificText: SpecificText; constructor(config?: Partial<SpellerConfig>); getDigit(digit: string): string; findUnit(index: number): string; findMagUnit(magnitudeIndex: number): string; get oddText(): string; get tenText(): string; get oneToneText(): string; get fourToneText(): string; get fiveToneText(): string; /** * Parses and processes the input number into a structured format. * This method is responsible for: * - Cleaning and validating the input number * - Handling negative signs * - Splitting the number into integral and fractional parts * - Trimming redundant zeros according to configuration * * The method can be overridden in a subclass to implement custom parsing logic * while maintaining the default behavior through super.parseNumberData(). * * @param input - The number to parse, can be a string, number, or bigint * @returns A NumberData object containing: * - isNegative: boolean indicating if the number is negative * - integralPart: string containing the integral part * - fractionalPart: string containing the fractional part * * @example * ```typescript * class CustomSpellerConfig extends SpellerConfig { * parseNumberData(input: InputNumber): NumberData { * // Custom parsing logic here * // For example, handle special number formats * * // Use default implementation for standard cases * return super.parseNumberData(input); * } * } * ``` */ parseNumberData(input: InputNumber): NumberData; } //# sourceMappingURL=types.d.ts.map