What is it?
A TypeScript library that converts integers to Indonesian words. It transforms numbers
like 12345 into "Dua Belas Ribu Tiga Ratus Empat Puluh Lima".
Inspired by terbilang-js by Naufal Rabbani, rebuilt with TypeScript for better type safety and modern JavaScript features.
Why use it?
- Type-safe: Written in TypeScript with full type definitions
- Validated: Input validation with clear error messages
- Comprehensive: Supports numbers from 0 to 999 Kuadriliun (10^18 - 1)
- Edge case handling: Properly handles zero, negative numbers, NaN, and Infinity
- Simple API: Single function with intuitive usage
How to use
import { terbilang } from 'terbilang-ts'
// Basic numbers
terbilang(1) // "Satu"
terbilang(10) // "Sepuluh"
terbilang(100) // "Seratus"
terbilang(1000) // "Seribu"
// Larger numbers
terbilang(12345) // "Dua Belas Ribu Tiga Ratus Empat Puluh Lima"
terbilang(1234567) // "Satu Juta Dua Ratus Tiga Puluh Empat Ribu Lima Ratus Enam Puluh Tujuh"
// Zero and negatives
terbilang(0) // "Nol"
terbilang(-5) // "Negatif Lima"
Error handling
// Non-integer numbers
try {
terbilang(123.45)
} catch (e) {
console.error(e.message) // "terbilang only accepts integer numbers"
}
// Numbers beyond supported range
try {
terbilang(10 ** 18)
} catch (e) {
console.error(e.message) // "terbilang only supports numbers up to 999 Kuadriliun"
}
// Edge cases
terbilang(NaN) // ""
terbilang(Infinity) // ""
Installation
npm install terbilang-ts
Or copy the terbilang.ts file directly to your project.
Features
- ✅ Converts integers to Indonesian words (Nol to Kuadriliun)
- ✅ Supports negative numbers with "Negatif" prefix
- ✅ Zero returns "Nol" instead of empty string
- ✅ Input validation for non-integer values
- ✅ Range validation (up to 999 Kuadriliun / 10^18 - 1)
- ✅ Handles edge cases (NaN, Infinity)
- ✅ Type-safe TypeScript implementation
Supported Range
The function supports integers from -999,999,999,999,999,999 to 999,999,999,999,999,999 (999 Kuadriliun).
Numbers outside this range will throw an error.