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 🙏

© 2025 – Pkg Stats / Ryan Hefner

indokit

v1.0.8

Published

Utility TypeScript untuk format & validasi data Indonesia (Rupiah, NIK, phone, slug, dsb.)

Downloads

6

Readme

Apa itu Indokit?

Indokit adalah library TypeScript (Support JS) untuk format & validasi data Indonesia. Definisikan fungsi yang kamu butuhkan dan gunakan dengan mudah. Kamu akan mendapat hasil yang sudah divalidasi dan type-safe! Ini baru rilis pertama jadi masih sangat sederhana belum sempurna. Namun, sudah cukup bagus untuk kebutuhan dasar.

import { formatRupiah, terbilang, isValidNIK } from "indokit";

// format mata uang
formatRupiah(1500000); // "Rp 1.500.000,00"

// konversi angka ke kata-kata
terbilang(1500); // "seribu lima ratus"

// validasi NIK
isValidNIK("1234567890123456"); // true

Fitur

  • Zero external dependencies
  • Kecil: bundle core hanya ~7kb (gzipped)
  • TypeScript-first dengan full type definitions
  • Interface yang sederhana
  • 100% test coverage

Instalasi

pnpm add indokit
npm install indokit
yarn add indokit

Penggunaan Dasar

Sebelum menggunakan, kamu perlu import fungsi yang dibutuhkan:

import {
  formatRupiah,
  terbilang,
  isValidNIK,
  isValidPhone,
  formatTanggalID,
  randomString,
} from "indokit";

Format Rupiah

Gunakan formatRupiah untuk mengkonversi angka ke format mata uang Rupiah Indonesia.

formatRupiah(1000); // "Rp 1.000,00"
formatRupiah(1500000); // "Rp 1.500.000,00"
formatRupiah(-500000); // "-Rp 500.000,00"
formatRupiah(1000.5); // "Rp 1.000,50"

Terbilang (Angka ke Kata)

Fungsi terbilang mengkonversi angka menjadi kata-kata dalam bahasa Indonesia.

terbilang(1500); // "seribu lima ratus"
terbilang(-500); // "minus lima ratus"
terbilang("1000"); // "seribu" (mendukung string)
terbilang("  123  "); // "seratus dua puluh tiga" (auto-trim)

Handling Error

Ketika input tidak valid, fungsi terbilang akan throw TypeError dengan pesan yang jelas:

try {
  terbilang("abc");
} catch (err) {
  console.log(err.message); // "terbilang: input tidak boleh berupa huruf"
}

try {
  terbilang(1.5);
} catch (err) {
  console.log(err.message); // "terbilang: input harus berupa bilangan bulat"
}

Validasi NIK

Gunakan isValidNIK untuk memvalidasi format NIK:

isValidNIK("1234567890123456"); // true
isValidNIK("123456789012345"); // false (kurang dari 16 digit)
isValidNIK("123456789012345a"); // false (mengandung huruf)

Validasi Nomor HP

Fungsi isValidPhone mendukung berbagai format nomor HP Indonesia:

isValidPhone("08123456789"); // true
isValidPhone("+628123456789"); // true
isValidPhone("628123456789"); // true
isValidPhone("07123456789"); // false (tidak dimulai dengan 8)

Format Tanggal Indonesia

Konversi tanggal ke format bahasa Indonesia:

formatTanggalID("2023-08-17"); // "17 Agustus 2023"
formatTanggalID(new Date("2023-12-25")); // "25 Desember 2023"
formatTanggalID(1692230400000); // "17 Agustus 2023"

Random String

Generate string acak untuk berbagai keperluan:

randomString(8); // "aB3xY9Zk"
randomString(16); // "mN8pQ2rS7tU4vW6x"
randomString(0); // ""

Error Handling

Semua fungsi di Indokit memiliki error handling yang konsisten. Ketika terjadi error, kamu akan mendapat TypeError dengan pesan yang jelas:

// Contoh berbagai error yang mungkin terjadi
terbilang(null); // TypeError: input tidak boleh null atau undefined
terbilang("123abc"); // TypeError: input tidak boleh mengandung campuran huruf dan angka
formatRupiah(NaN); // TypeError: formatRupiah: angka must be a number
randomString(-1); // TypeError: randomString: length must be a non-negative integer

TypeScript Support

Indokit ditulis dalam TypeScript dan menyediakan type definitions yang lengkap:

import { formatRupiah, terbilang } from "indokit";

// TypeScript akan otomatis mendeteksi tipe return
const rupiah: string = formatRupiah(1000);
const kata: string = terbilang(1500);

// Error akan muncul saat compile time jika tipe salah
formatRupiah("1000"); // ❌ TypeScript error

License

MIT License - lihat file LICENSE untuk detail lengkap.

Nashih Amin