read-vietnamese-number
Version:
Convert numbers to text in Vietnamese
40 lines (39 loc) • 1.43 kB
JavaScript
/**
* The base error class for all errors in the library.
*/
export class ReadVietnameseNumberError extends Error {
}
/**
* The error class used when the input number is invalid.
*/
export class InvalidNumberError extends ReadVietnameseNumberError {
}
/**
* The reading configuration class containing default options for reading numbers.
*/
export class ReadingConfig {
constructor() {
// Input parsing options
this.negativeSign = '-';
this.pointSign = '.'; // point/comma
this.thousandSign = ','; // comma/point/space
// Output building options
this.separator = ' '; // space/newline/tab
this.unit = ['đơn', 'vị']; // đơn vị/đồng
this.units = [[], ['nghìn'], ['triệu'], ['tỉ']]; // nghìn/ngàn, tỉ/tỷ
this.digits = ['không', 'một', 'hai', 'ba', 'bốn', 'năm', 'sáu', 'bảy', 'tám', 'chín']; // bảy/bẩy
this.negativeText = 'âm'; // âm/trừ
this.pointText = 'chấm'; // chấm/phẩy
this.oddText = 'lẻ'; // lẻ/linh
this.tenText = 'mười';
this.hundredText = 'trăm';
this.oneToneText = 'mốt';
this.fourToneText = 'tư'; // tư/bốn
this.fiveToneText = 'lăm';
this.tenToneText = 'mươi';
// Conditional options
this.skipTenTone = false;
}
}
ReadingConfig.PERIOD_SIZE = 3;
ReadingConfig.FILLED_DIGIT = '0';