angka-terbilang-ts
is a TypeScript library that converts numbers into words in Indonesian. This library is highly useful for applications that require a textual representation of numbers, such as financial reporting, check writing systems, and more.
- Converts whole and decimal numbers into words.
- Supports numbers up to
vigintillion
. - Easy to use and integrate into TypeScript or JavaScript projects.
You can install this library via npm:
npm install angka-terbilang-ts
Here is a basic example of how to use this library in a TypeScript project:
import toWords from 'angka-terbilang-ts';
const number = 1234;
console.log(toWords(number)); // Output: "seribu dua ratus tiga puluh empat"
const decimalNumber = '1234.56';
console.log(toWords(decimalNumber)); // Output: "seribu dua ratus tiga puluh empat koma lima enam"
const toWords = require('angka-terbilang-ts').default;
const number = 1234;
console.log(toWords(number)); // Output: "seribu dua ratus tiga puluh empat"
const decimalNumber = '1234.56';
console.log(toWords(decimalNumber)); // Output: "seribu dua ratus tiga puluh empat koma lima enam"
Converts numbers into words in Indonesian.
target
- The number to be converted. Can be a string or number.settings
- (Optional) Configuration object to set the decimal separator. Default is{ decimal: '.' }
.
Returns the textual representation of the given number.
This library uses Jest for testing. To run the tests, follow these steps:
-
Install dependencies for testing:
npm install --save-dev jest ts-jest @types/jest
-
Initialize Jest configuration:
npx ts-jest config:init
-
Run tests:
npm test
Here are some example tests to ensure the library functions correctly:
import toWords from '../src/index';
describe('toWords', () => {
it('should convert single digit numbers to words', () => {
expect(toWords(1)).toBe('satu');
expect(toWords(5)).toBe('lima');
});
it('should convert tens to words', () => {
expect(toWords(10)).toBe('sepuluh');
expect(toWords(11)).toBe('sebelas');
expect(toWords(21)).toBe('dua puluh satu');
});
it('should convert hundreds to words', () => {
expect(toWords(100)).toBe('seratus');
expect(toWords(105)).toBe('seratus lima');
expect(toWords(123)).toBe('seratus dua puluh tiga');
});
it('should convert thousands to words', () => {
expect(toWords(1000)).toBe('seribu');
expect(toWords(1001)).toBe('seribu satu');
expect(toWords(1234)).toBe('seribu dua ratus tiga puluh empat');
});
it('should convert large numbers to words', () => {
expect(toWords(1000000)).toBe('satu juta');
expect(toWords(1000000000)).toBe('satu milyar');
});
it('should handle decimals', () => {
expect(toWords('1234.56')).toBe('seribu dua ratus tiga puluh empat koma lima enam');
});
});
Contributions are welcome! If you have suggestions, bug reports, or new features to add, please open an issue or pull request on the GitHub repository.
This project is licensed under the ISC License. See the LICENSE file for more details.