npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

angka-terbilang-ts

v1.5.1

Published

A TypeScript library to convert numbers into words. Useful for generating human-readable text from numerical values.

Downloads

118

Readme

Angka-Terbilang-TS - Indonesian Number to Words Converter

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.

Features

  • Converts whole and decimal numbers into words.
  • Supports numbers up to vigintillion.
  • Easy to use and integrate into TypeScript or JavaScript projects.

Installation

You can install this library via npm:

npm install angka-terbilang-ts

Usage

Here is a basic example of how to use this library in a TypeScript project:

TypeScript

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"

JavaScript

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"

API

toWords(target: string | number, settings?: { decimal: string }): string

Converts numbers into words in Indonesian.

Parameters

  • 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

Returns the textual representation of the given number.

Testing

This library uses Jest for testing. To run the tests, follow these steps:

  1. Install dependencies for testing:

    npm install --save-dev jest ts-jest @types/jest
  2. Initialize Jest configuration:

    npx ts-jest config:init
  3. Run tests:

    npm test

Example Tests

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');
  });
});

Contribution

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.

License

This project is licensed under the ISC License. See the LICENSE file for more details.

Repository