Indonesian identity toolkit for Ruby. Parse NIK, validate NPWP, phone numbers, and format Rupiah.
gem "nik-parser"$ gem install nik-parser
require "nik_parser"
# Parse NIK
nik = NikParser.parse("3204110609970004")
nik.province # => "JAWA BARAT"
nik.regency # => "KAB. BANDUNG"
nik.district # => "KATAPANG"
nik.sex # => "M"
nik.birthdate # => "1997-09-06"
# Validate
NikParser.valid_nik?("3204110609970004") # => true
NikParser.valid_npwp?("12.345.678.9-012.000") # => true
NikParser.valid_phone?("081234567890") # => true
# Format Rupiah
NikParser.rupiah(1500000) # => "Rp 1.500.000"nik = NikParser::NIK.new("3204110609970004")
nik.valid? # => true
nik.province # => "JAWA BARAT"
nik.province_code # => "32"
nik.regency # => "KAB. BANDUNG"
nik.district # => "KATAPANG"
nik.sex # => "M" / "F"
nik.birth_day # => 6
nik.birth_month # => 9
nik.birth_year # => 1997
nik.birthdate # => "1997-09-06"
nik.unique_code # => "0004"
nik.to_h # => { nik: "...", region: {...}, sex: "M", birth: {...} }NikParser.valid_npwp?("12.345.678.9-012.000") # => true
npwp = NikParser::NPWP.parse("12.345.678.9-012.000")
npwp[:kpp_code] # => "12"
npwp[:corporate] # => true (type 9)
npwp[:branch] # => "000"
npwp[:formatted] # => "12.345.678.9-012.000"NikParser.valid_phone?("081234567890") # => true
NikParser.valid_phone?("+6281234567890") # => true
NikParser::Phone.normalize("+6281234567890") # => "081234567890"
NikParser::Phone.format_international("081234567890") # => "+62 812-3456-7890"NikParser.rupiah(1500000) # => "Rp 1.500.000"
NikParser::Rupiah.format(1500000, symbol: false) # => "1.500.000"
NikParser::Rupiah.parse("Rp 1.500.000") # => 1500000Includes data for all Indonesian provinces, regencies, and districts. Data is loaded once and cached.
NikParser::Region.provinces # => { "11" => "ACEH", "12" => "SUMATERA UTARA", ... }
NikParser::Region.province("33") # => "JAWA TENGAH"
NikParser::Region.regency("33.74") # => "KOTA SEMARANG"Part of the Nusantara Indonesian toolkit ecosystem:
- nik-parser — Ruby (this gem)
- nusantara — JavaScript/TypeScript (npm)
- nusantara-php — PHP (Composer)
git clone https://github.com/gizipp/nik-parser.rb.git
cd nik-parser.rb
bundle install
bundle exec rspec