UNPKG

spell-vn-number

Version:
104 lines (103 loc) 4.13 kB
var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); var InvalidFormatError = /** @class */ (function (_super) { __extends(InvalidFormatError, _super); function InvalidFormatError(message) { var _this = _super.call(this, message) || this; // For IE 11 and older browsers without proper Error inheritance _this.name = 'InvalidFormatError'; Object.setPrototypeOf(_this, InvalidFormatError.prototype); return _this; } return InvalidFormatError; }(Error)); export { InvalidFormatError }; var InvalidNumberError = /** @class */ (function (_super) { __extends(InvalidNumberError, _super); function InvalidNumberError(message) { var _this = _super.call(this, message) || this; // For IE 11 and older browsers without proper Error inheritance _this.name = 'InvalidNumberError'; Object.setPrototypeOf(_this, InvalidNumberError.prototype); return _this; } return InvalidNumberError; }(Error)); export { InvalidNumberError }; var SpellerConfig = /** @class */ (function () { function SpellerConfig(config) { if (config === void 0) { config = {}; } this.separator = ' '; this.negativeSign = '-'; this.decimalPoint = '.'; this.thousandSign = ','; this.filledDigit = '0'; this.capitalizeInitial = true; this.currencyUnit = ''; // option for currency unit // Controls how to handle redundant zeros in decimal part this.keepOneZeroWhenAllZeros = false; // When true, keeps a single '0' after decimal point when all decimal digits are zeros (e.g., '123.000' -> '123.0') // When false, removes all trailing zeros and keeps only the decimal point (e.g., '123.000' -> '123.') // Vietnamese specific text this.negativeText = 'âm'; this.pointText = 'chấm'; this.oddText = 'lẻ'; this.tenText = 'mười'; this.oneToneText = 'mốt'; this.fourToneText = 'tư'; this.fiveToneText = 'lăm'; // Digits mapping this.digits = { '0': 'không', '1': 'một', '2': 'hai', '3': 'ba', '4': 'bốn', '5': 'năm', '6': 'sáu', '7': 'bảy', '8': 'tám', '9': 'chín', }; // Unit group names this.UNIT_GROUP = ['BILLION', 'MINION', 'THOUSAND']; this.UNIT_OF_GROUP = { 'BILLION': 'tỷ', 'MINION': 'triệu', 'THOUSAND': 'nghìn', }; // Unit mapping this.UNIT_GROUP_MAPPER = { 'BILLION': ['trăm', 'mươi', 'triệu'], 'MINION': ['trăm', 'mươi', 'nghìn'], 'THOUSAND': ['trăm', 'mươi', ''], }; // Constants for positions in a group this.UNIT_EACH_GROUP = ['HUNDRED', 'TENS', 'UNITS']; // Index of UNIT_EACH_GROUP this.AT_HUNDRED = 0; this.AT_TEN = 1; this.AT_UNIT = 2; // Apply configuration overrides in a browser-compatible way for (var key in config) { if (Object.prototype.hasOwnProperty.call(config, key)) { // @ts-ignore - This is safe as we're only overriding existing properties this[key] = config[key]; } } } return SpellerConfig; }()); export { SpellerConfig };