digit-to-words-nepali
Version:
A comprehensive TypeScript library for converting numbers to words in English and Nepali languages. Supports numbers up to 10^39 (Adanta Singhar), currency formatting, decimal handling with individual digit pronunciation, and BigInt. Zero dependencies, fu
38 lines (37 loc) • 1.68 kB
TypeScript
import { ConverterConfig, Language, ConversionResult, CustomUnits, CustomScales } from '../types/converterTypes';
import { WordMapping, NumberScale } from '../types/mappingTypes';
/**
* BaseConverter
* Abstract class for number-to-words conversion logic.
* Handles custom mappings, scale lookups, and large number processing.
*/
export declare abstract class BaseConverter {
protected wordCache: Map<number, WordMapping>;
protected scales: NumberScale[];
protected customUnits: CustomUnits;
protected customScales: CustomScales;
constructor();
/**
* Set custom unit and scale mappings from config.
* Throws if config is invalid.
*/
protected setCustomMappings(config: Required<ConverterConfig>): void;
/**
* Get the word mapping for a number in the specified language.
* Checks custom units first, then default cache.
*/
protected getWordMapping(num: number, lang: Language): string;
/**
* Get the scale name for a value in the specified language.
* Checks custom scales first, then default scale list.
*/
protected getScaleName(value: bigint, lang: Language): string;
/**
* Process a large number by recursively breaking it down into smaller components
* using the appropriate scale values.
* Uses binary search for performance (O(log n) for n scales).
*/
protected processLargeNumber(num: bigint, words: string[], config: Required<ConverterConfig>): void;
protected formatResult(words: string[], config: Required<ConverterConfig>): string;
abstract convert(num: number | string | bigint, config: Required<ConverterConfig>): ConversionResult;
}