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 🙏

© 2026 – Pkg Stats / Ryan Hefner

indonesian-validators

v1.0.3

Published

Validation library for Indonesian data formats (NIK, NPWP, phone numbers, bank accounts, etc.)

Readme

🇮🇩 Indonesian Validators

Library JavaScript untuk validasi data format Indonesia seperti NIK, NPWP, Nomor HP, Rekening Bank, dan lainnya.

npm version License: MIT

✨ Features

  • ✅ Validasi NIK (Nomor Induk Kependudukan)
  • ✅ Validasi NPWP (Nomor Pokok Wajib Pajak)
  • ✅ Validasi Nomor HP Indonesia (dengan deteksi operator)
  • ✅ Validasi Email
  • ✅ Validasi Nomor Rekening Bank (BCA, BNI, BRI, Mandiri, dll)
  • ✅ Validasi Kode Pos
  • ✅ Format helper functions
  • ✅ Zero dependencies
  • ✅ TypeScript support (coming soon)
  • ✅ Ringan (~5KB gzipped)

📦 Installation

npm install indonesian-validators

atau

yarn add indonesian-validators

🚀 Usage

Validasi NIK

import { validateNIK, formatNIK } from 'indonesian-validators';

const result = validateNIK('3201012901950001');

console.log(result);
// {
//   valid: true,
//   message: 'NIK valid',
//   data: {
//     provinceCode: '32',
//     districtCode: '3201',
//     subdistrictCode: '320101',
//     birthDate: { day: 29, month: 1, year: 95 },
//     gender: 'Laki-laki'
//   }
// }

// Format NIK untuk display
console.log(formatNIK('3201012901950001'));
// Output: "320101 290195 0001"

Validasi NPWP

import { validateNPWP, formatNPWP } from 'indonesian-validators';

const result = validateNPWP('01.234.567.8-901.000');

console.log(result);
// {
//   valid: true,
//   message: 'NPWP valid',
//   data: { formatted: '01.234.567.8-901.000' }
// }

Validasi Nomor HP

import { validatePhoneNumber, formatPhoneNumber } from 'indonesian-validators';

const result = validatePhoneNumber('081234567890');

console.log(result);
// {
//   valid: true,
//   message: 'Nomor HP valid',
//   data: {
//     formatted: '081234567890',
//     international: '+6281234567890',
//     operator: 'Telkomsel'
//   }
// }

// Format ke international
console.log(formatPhoneNumber('081234567890', 'international'));
// Output: "+6281234567890"

Validasi Email

import { validateEmail } from 'indonesian-validators';

const result = validateEmail('[email protected]');

console.log(result);
// {
//   valid: true,
//   message: 'Email valid',
//   data: { domain: 'example.com' }
// }

Validasi Nomor Rekening Bank

import { validateBankAccount } from 'indonesian-validators';

const result = validateBankAccount('1234567890', 'BCA');

console.log(result);
// {
//   valid: true,
//   message: 'Nomor rekening Bank Central Asia valid',
//   data: {
//     bank: 'Bank Central Asia',
//     accountNumber: '1234567890'
//   }
// }

Validasi Kode Pos

import { validatePostalCode } from 'indonesian-validators';

const result = validatePostalCode('12345');

console.log(result);
// {
//   valid: true,
//   message: 'Kode pos valid',
//   data: { postalCode: '12345' }
// }

📋 API Documentation

Validation Functions

Semua fungsi validasi mengembalikan object dengan struktur:

{
  valid: boolean,      // true jika valid, false jika tidak
  message: string,     // Pesan hasil validasi
  data?: object        // Data tambahan (jika valid)
}

validateNIK(nik: string | number)

Validasi NIK 16 digit dan ekstrak informasi dasar.

validateNPWP(npwp: string | number)

Validasi NPWP 15 digit dengan format yang fleksibel.

validatePhoneNumber(phone: string | number)

Validasi nomor HP Indonesia dengan deteksi operator.

validateEmail(email: string)

Validasi format email standar.

validateBankAccount(accountNumber: string | number, bankCode?: string)

Validasi nomor rekening bank. Bank code: BCA, BNI, BRI, MANDIRI, CIMB, PERMATA, DANAMON, BTN.

validatePostalCode(postalCode: string | number)

Validasi kode pos Indonesia (5 digit).

Format Functions

formatNIK(nik: string | number): string

Format NIK dengan spasi untuk readability.

formatNPWP(npwp: string | number): string

Format NPWP dengan titik dan strip.

formatPhoneNumber(phone: string | number, format?: 'local' | 'international'): string

Format nomor HP ke format lokal atau international.

🎯 Use Cases

React Form Validation

import { validateNIK, validatePhoneNumber } from 'indonesian-validators';

function RegistrationForm() {
  const [nik, setNik] = useState('');
  const [nikError, setNikError] = useState('');

  const handleNikChange = (e) => {
    const value = e.target.value;
    setNik(value);
    
    const result = validateNIK(value);
    if (!result.valid) {
      setNikError(result.message);
    } else {
      setNikError('');
    }
  };

  return (
    <input
      value={nik}
      onChange={handleNikChange}
      placeholder="Masukkan NIK"
    />
  );
}

Backend Validation (Node.js)

const { validateNPWP, validateBankAccount } = require('indonesian-validators');

app.post('/api/submit', (req, res) => {
  const { npwp, bankAccount } = req.body;
  
  const npwpResult = validateNPWP(npwp);
  if (!npwpResult.valid) {
    return res.status(400).json({ error: npwpResult.message });
  }
  
  const accountResult = validateBankAccount(bankAccount, 'BCA');
  if (!accountResult.valid) {
    return res.status(400).json({ error: accountResult.message });
  }
  
  // Process valid data...
});

🤝 Contributing

Kontribusi sangat diterima! Silakan buat issue atau pull request.

  1. Fork repository ini
  2. Buat branch feature (git checkout -b feature/AmazingFeature)
  3. Commit changes (git commit -m 'Add some AmazingFeature')
  4. Push ke branch (git push origin feature/AmazingFeature)
  5. Buka Pull Request

📝 License

MIT License - lihat file LICENSE untuk detail.

💖 Support

Jika library ini berguna untuk kamu:

🔗 Links


Made with ❤️ for Indonesian Developers