indonesian-number-words v1.0.1
Indonesian Number Words
Convert numerical values into their word equivalents in Bahasa Indonesia with high precision and no floating-point errors.
๐ Features
- High Precision: Utilizes
decimal.js
to avoid floating-point inaccuracies. - Comprehensive Range: Supports numbers from zero up to triliuns.
- Negative Number Support: Accurately converts negative numbers with the "minus" prefix.
- Decimal Handling: Converts fractional parts with precise word representations.
- TypeScript Support: Fully typed with TypeScript declarations for enhanced developer experience.
- No Floating Errors: Ensures accurate conversions without common floating-point pitfalls.
- Lightweight: Optimized for performance and minimal footprint.
- Easy Integration: Simple API for seamless integration into your projects.
๐ฆ Installation
Ensure you have Node.js installed (version 14 or higher).
npm install indonesian-number-words decimal.js
or using Yarn:
yarn add indonesian-number-words decimal.js
๐ Usage
JavaScript
const { Terbilang } = require('indonesian-number-words');
const Decimal = require('decimal.js');
console.log(Terbilang.Convert(0)); // "nol"
console.log(Terbilang.Convert(15)); // "sebelas"
console.log(Terbilang.Convert(123)); // "seratus dua puluh tiga"
console.log(Terbilang.Convert(1000)); // "seribu"
console.log(Terbilang.Convert(2500000)); // "dua juta lima ratus ribu"
console.log(Terbilang.Convert(new Decimal(-75))); // "minus tujuh puluh lima"
console.log(Terbilang.Convert(123.45)); // "seratus dua puluh tiga koma empat lima"
TypeScript
import { Terbilang } from 'indonesian-number-words';
import Decimal from 'decimal.js';
console.log(Terbilang.Convert(0)); // "nol"
console.log(Terbilang.Convert(15)); // "sebelas"
console.log(Terbilang.Convert(123)); // "seratus dua puluh tiga"
console.log(Terbilang.Convert(1000)); // "seribu"
console.log(Terbilang.Convert(2500000)); // "dua juta lima ratus ribu"
console.log(Terbilang.Convert(new Decimal(-75))); // "minus tujuh puluh lima"
console.log(Terbilang.Convert(123.45)); // "seratus dua puluh tiga koma empat lima"
Using in a Project
import { Terbilang } from 'indonesian-number-words';
import Decimal from 'decimal.js';
const number = new Decimal(-12345.67);
const words = Terbilang.Convert(number);
console.log(words); // "minus dua belas ribu tiga ratus empat puluh lima koma enam tujuh"
๐ API
Terbilang.Convert(convertNumber: number | Decimal, firstTry?: boolean): string
Parameters
convertNumber
(number | Decimal): The number to convert. Can be a native JavaScriptnumber
or aDecimal
instance for higher precision.firstTry
(boolean, optional): Internal parameter for recursive calls. Do not modify. Defaults totrue
.
Returns
- (string): The word representation of the number in Bahasa Indonesia.
Throws
TypeError
: If the input is not anumber
orDecimal
instance.RangeError
: If the number exceeds the supported range (up to triliuns).
Examples
Terbilang.Convert(100); // "seratus"
Terbilang.Convert(new Decimal(100.5)); // "seratus koma lima"
Terbilang.Convert(-50); // "minus lima puluh"
๐งช Testing
The package uses Jest for testing to ensure reliability and correctness.
Running Tests
npm test
All tests should pass, confirming that the package handles various scenarios correctly, including negative numbers, decimals, and large numbers.
๐ง Development
Building the Package
npm run build
Compiles the TypeScript code into JavaScript, outputting to the dist
directory.
๐ Contributing
Contributions are welcome! Please follow these steps:
Fork the Repository
Create a Feature Branch
git checkout -b feature/YourFeature
Commit Your Changes
git commit -m "Add some feature"
Push to the Branch
git push origin feature/YourFeature
Open a Pull Request
Provide a clear description of your changes and the problem they solve.
๐ Issues
If you encounter any issues or have feature requests, please open an issue on GitHub.
๐ License
This project is licensed under the MIT License.
๐ก Unique Selling Points
- No Floating-Point Errors: By leveraging
decimal.js
, the library ensures precise conversions without the common floating-point inaccuracies found in native JavaScriptnumber
types. - High Precision: Handles large numbers and decimals with exceptional accuracy, making it ideal for financial and critical applications.
- Comprehensive Language Support: Specifically tailored for Bahasa Indonesia, ensuring culturally and linguistically accurate representations.
- TypeScript Ready: Fully typed with TypeScript declarations, providing excellent developer experience and integration with TypeScript projects.
- Robust Testing: Extensive test coverage ensures reliability across various scenarios, including edge cases and large numbers.
- Ease of Use: Simple and intuitive API design makes it easy to integrate and use in any JavaScript or TypeScript project.