number-to-words-multilingual
v1.2.0
Published
A package to convert numbers to their text representation in multiple languages (Vietnamese, English, Korean, Japanese, Chinese, Hindi, Spanish, French, German, Russian, Arabic, Portuguese, Italian, Thai)
Maintainers
Readme
number-to-words-multilingual
A simple and lightweight package to convert numbers to their text representation in multiple languages.
Features
- Convert numbers to words in multiple languages:
- English, Vietnamese, Korean, Japanese, Chinese, Hindi
- Spanish, French, German, Russian
- Arabic, Portuguese, Italian, Thai
- Supports negative numbers
- Handles numbers up to quintillions (10^18)
- Zero dependencies
- TypeScript support
Installation
npm install number-to-words-multilingualUsage
const {
numberToWords,
numberToEnglish,
numberToVietnamese,
numberToKorean,
numberToJapanese,
numberToChinese,
numberToHindi,
numberToSpanish,
numberToFrench,
numberToGerman,
numberToRussian,
numberToArabic,
numberToPortuguese,
numberToItalian,
numberToThai
} = require('number-to-words-multilingual');
// Using the main function with language option
console.log(numberToWords(123, 'en')); // "one hundred twenty-three"
console.log(numberToWords(123, 'vi')); // "một trăm hai mươi ba"
console.log(numberToWords(123, 'ko')); // "백이십삼"
console.log(numberToWords(123, 'ja')); // "百二十三"
console.log(numberToWords(123, 'zh')); // "一百二十三"
console.log(numberToWords(123, 'hi')); // "एक सौ तेईस"
console.log(numberToWords(123, 'es')); // "ciento veintitrés"
console.log(numberToWords(123, 'fr')); // "cent vingt-trois"
console.log(numberToWords(123, 'de')); // "einhundertdreiundzwanzig"
// Or use the specific language functions
console.log(numberToEnglish(1234)); // "one thousand two hundred thirty-four"
console.log(numberToVietnamese(1234)); // "một nghìn hai trăm ba mươi bốn"
console.log(numberToKorean(1234)); // "천이백삼십사"
console.log(numberToJapanese(1234)); // "千二百三十四"
console.log(numberToChinese(1234)); // "一千二百三十四"
console.log(numberToHindi(1234)); // "हज़ार दो सौ चौंतीस"
console.log(numberToRussian(1234)); // "одна тысяча двести тридцать четыре"
console.log(numberToArabic(1234)); // "ألف و مائتان و أربعة و ثلاثون"
console.log(numberToThai(1234)); // "หนึ่งพันสองร้อยสามสิบสี่"
// Handle negative numbers
console.log(numberToWords(-42, 'en')); // "negative forty-two"
console.log(numberToWords(-42, 'vi')); // "âm bốn mươi hai"
console.log(numberToWords(-42, 'ko')); // "마이너스 사십이"With TypeScript:
import { numberToWords } from 'number-to-words-multilingual';
// The language parameter is type-safe
const words = numberToWords(12345, 'vi'); // Must be one of the supported languagesAPI
numberToWords(num, language)
Converts a number to its text representation.
num: The number to convertlanguage: The language to use for conversion:'en'for English'vi'for Vietnamese'ko'for Korean'ja'for Japanese'zh'for Chinese'hi'for Hindi'es'for Spanish'fr'for French'de'for German'ru'for Russian'ar'for Arabic'pt'for Portuguese'it'for Italian'th'for Thai
- Returns: The text representation of the number
numberToEnglish(num)
Converts a number to its English text representation.
num: The number to convert- Returns: The English text representation of the number
numberToVietnamese(num)
Converts a number to its Vietnamese text representation.
num: The number to convert- Returns: The Vietnamese text representation of the number
numberToKorean(num)
Converts a number to its Korean text representation.
num: The number to convert- Returns: The Korean text representation of the number
numberToJapanese(num)
Converts a number to its Japanese text representation.
num: The number to convert- Returns: The Japanese text representation of the number
numberToChinese(num)
Converts a number to its Chinese text representation (Simplified Chinese).
num: The number to convert- Returns: The Chinese text representation of the number
numberToHindi(num)
Converts a number to its Hindi text representation.
num: The number to convert- Returns: The Hindi text representation of the number
numberToSpanish(num)
Converts a number to its Spanish text representation.
num: The number to convert- Returns: The Spanish text representation of the number
numberToFrench(num)
Converts a number to its French text representation.
num: The number to convert- Returns: The French text representation of the number
numberToGerman(num)
Converts a number to its German text representation.
num: The number to convert- Returns: The German text representation of the number
numberToRussian(num)
Converts a number to its Russian text representation.
num: The number to convert- Returns: The Russian text representation of the number
numberToArabic(num)
Converts a number to its Arabic text representation.
num: The number to convert- Returns: The Arabic text representation of the number
numberToPortuguese(num)
Converts a number to its Portuguese text representation.
num: The number to convert- Returns: The Portuguese text representation of the number
numberToItalian(num)
Converts a number to its Italian text representation.
num: The number to convert- Returns: The Italian text representation of the number
numberToThai(num)
Converts a number to its Thai text representation.
num: The number to convert- Returns: The Thai text representation of the number
License
MIT
