@itsdreamy/fay-indo-formatter
v1.0.0
Published
Lightweight Indonesian utility formatters for Rupiah, dates, number to words, and phone validation.
Maintainers
Readme
fay-indo-formatter
A zero-dependency Node.js utility library with common formatting functions tailored for Indonesian developers.
✨ Key Features
| Feature | Description |
|---|---|
| 💰 Rupiah Formatter | Convert numbers to Rp currency strings with thousand separators |
| 📅 Indonesian Date Formatter | Format dates using full Bahasa Indonesia month & day names |
| 🔢 Terbilang | Spell out numbers in Indonesian words (e.g. invoice billing) |
| 📱 Phone Validator | Validate Indonesian mobile numbers (08xx, 628xx, +628xx) |
| 🧹 Phone Sanitizer | Normalize any phone format to the standard national format 08xx |
| 🚫 Zero Dependencies | Pure Node.js — nothing to audit, nothing extra to install |
📦 Installation
npm install fay-indo-formatter🚀 Quick Start
const {
toRupiah,
formatDateID,
terbilang,
isValidPhoneID,
sanitizePhoneID,
} = require('fay-indo-formatter');
console.log(toRupiah(15000)); // "Rp 15.000"
console.log(formatDateID('2026-10-30')); // "30 Oktober 2026"
console.log(terbilang(125000)); // "seratus dua puluh lima ribu"
console.log(isValidPhoneID('+6281234567890')); // true
console.log(sanitizePhoneID('+62 812-3456-7890')); // "081234567890"📖 Usage Examples
toRupiah(number, options?)
const { toRupiah } = require('fay-indo-formatter');
toRupiah(15000);
// → "Rp 15.000"
toRupiah(1500000);
// → "Rp 1.500.000"
toRupiah(1500000.5, { decimal: 2 });
// → "Rp 1.500.000,50"
toRupiah(75000, { withPrefix: false });
// → "75.000"
toRupiah(0);
// → "Rp 0"formatDateID(date, format?)
const { formatDateID } = require('fay-indo-formatter');
// Default format: "DD MMMM YYYY"
formatDateID('2026-10-30');
// → "30 Oktober 2026"
// Short month
formatDateID('2026-10-30', 'DD MMM YYYY');
// → "30 Okt 2026"
// With full day name
formatDateID('2026-10-30', 'dddd, DD MMMM YYYY');
// → "Jumat, 30 Oktober 2026"
// With short day name
formatDateID('2026-10-30', 'ddd, DD MMMM YYYY');
// → "Jum, 30 Oktober 2026"
// With time
formatDateID(new Date(), 'DD/MM/YYYY HH:mm:ss');
// → e.g. "30/10/2026 20:05:00"
// From a Date object
formatDateID(new Date('2026-06-17'), 'D MMMM YYYY');
// → "17 Juni 2026"Available format tokens:
| Token | Output | Example |
|--------|--------|---------|
| YYYY | 4-digit year | 2026 |
| YY | 2-digit year | 26 |
| MMMM | Full month (Indonesian) | Oktober |
| MMM | Short month (Indonesian) | Okt |
| MM | 2-digit month | 10 |
| M | Month, no padding | 10 |
| DD | 2-digit day | 05 |
| D | Day, no padding | 5 |
| dddd | Full day name (Indonesian) | Jumat |
| ddd | Short day name (Indonesian) | Jum |
| HH | Hours (00–23) | 20 |
| mm | Minutes (00–59) | 05 |
| ss | Seconds (00–59) | 00 |
terbilang(number)
const { terbilang } = require('fay-indo-formatter');
terbilang(0); // "nol"
terbilang(11); // "sebelas"
terbilang(100); // "seratus"
terbilang(1000); // "seribu"
terbilang(125000); // "seratus dua puluh lima ribu"
terbilang(1000000); // "satu juta"
terbilang(1500000); // "satu juta lima ratus ribu"
// Practical use: invoice amounts
const amount = 750000;
console.log(`Terbilang: ${terbilang(amount)} rupiah`);
// → "Terbilang: tujuh ratus lima puluh ribu rupiah"isValidPhoneID(phoneNumber)
const { isValidPhoneID } = require('fay-indo-formatter');
isValidPhoneID('081234567890'); // true
isValidPhoneID('6281234567890'); // true
isValidPhoneID('+6281234567890'); // true
isValidPhoneID('+62 812-3456-7890'); // true (spaces & dashes OK)
isValidPhoneID('(+62) 812.3456.7890'); // true
isValidPhoneID('021-555-1234'); // false (Jakarta landline)
isValidPhoneID('08123456'); // false (too short)
isValidPhoneID('1234'); // false
isValidPhoneID(81234567890); // false (not a string)sanitizePhoneID(phoneNumber)
const { sanitizePhoneID } = require('fay-indo-formatter');
sanitizePhoneID('+62 812-3456-7890'); // "081234567890"
sanitizePhoneID('6281234567890'); // "081234567890"
sanitizePhoneID('081234567890'); // "081234567890"
sanitizePhoneID('(+62) 812-3456-7890'); // "081234567890"
// Throws for invalid input
sanitizePhoneID('1234'); // Error: not a valid Indonesian phone number📚 API Reference
toRupiah(number, options?)
| Parameter | Type | Default | Description |
|---|---|---|---|
| number | number | — | The value to format. Finite numbers only. |
| options.withPrefix | boolean | true | Prepend "Rp " to the result. |
| options.decimal | number | 0 | Number of decimal places to show. Uses comma (,) as decimal separator per Indonesian convention. |
Returns: string
Throws: TypeError if number is not a finite number.
formatDateID(date, format?)
| Parameter | Type | Default | Description |
|---|---|---|---|
| date | Date \| string \| number | — | A Date object, ISO 8601 string, or Unix timestamp (ms). |
| format | string | 'DD MMMM YYYY' | Format string using the tokens listed above. |
Returns: string
Throws: TypeError if the date cannot be parsed or format is not a string.
terbilang(number)
| Parameter | Type | Description |
|---|---|---|
| number | number | Non-negative integer. Supports up to 999,999,999,999,999. |
Returns: string — Indonesian words for the number.
Throws: TypeError if not a finite number; RangeError if negative or too large.
isValidPhoneID(phoneNumber)
| Parameter | Type | Description |
|---|---|---|
| phoneNumber | string | Phone number in any common format. |
Returns: boolean — true if the number matches a valid Indonesian mobile pattern.
Accepted prefixes (after stripping spaces/dashes):
08xx— national format628xx— international without plus+628xx— E.164 international format
sanitizePhoneID(phoneNumber)
| Parameter | Type | Description |
|---|---|---|
| phoneNumber | string | Phone number in any valid format. |
Returns: string — Phone number normalised to 08xxxxxxxxx.
Throws: TypeError if argument is not a string; Error if the number is invalid.
🤝 Contributing
Contributions, issues, and feature requests are welcome!
Feel free to open an issue or submit a pull request.
📄 License
MIT © 2026 itsdreamy-fay
