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
30 lines (29 loc) • 792 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.formatWords = formatWords;
exports.padDecimal = padDecimal;
exports.formatCurrencyAmount = formatCurrencyAmount;
/**
* Joins an array of words into a single string, removing extra spaces.
*/
function formatWords(words) {
return words
.filter(Boolean)
.join(' ')
.replace(/\s+/g, ' ')
.trim();
}
/**
* Pads a decimal string to at least 2 digits (e.g., '5' -> '05').
*/
function padDecimal(decimal) {
return decimal.padStart(2, '0');
}
/**
* Formats a currency amount with the currency name, language-aware.
*/
function formatCurrencyAmount(amount, currency, lang) {
return lang === 'ne'
? `${currency} ${amount}`
: `${amount} ${currency}`;
}