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

@damarkuncoro/posindonesia

v1.0.7

Published

Library untuk mencari Kodepos Indonesia berdasarkan data statis TypeScript.

Readme

@damarkuncoro/posindonesia

Library TypeScript berperforma tinggi untuk mencari Kodepos Indonesia berdasarkan database statis internal. Mendukung pencarian fuzzy, pencarian terstruktur, dan pemuatan data yang sangat efisien (Lazy Loading).

CI npm version

Fitur Utama 🚀

  • Hybrid Search: Pilih antara pencarian Local (offline & super cepat) atau Remote (real-time dari situs resmi).
  • Offline-First: Tidak memerlukan koneksi internet untuk pencarian data lokal (~80.000+ data).
  • Fuzzy Search: Cerdas menangani typo menggunakan Fuse.js (Mode Local).
  • Inverted Index: Pencarian kata kunci instan dengan performa tinggi.
  • Lazy Loading: Hanya memuat data provinsi yang dibutuhkan untuk menghemat RAM.
  • Structured Search: Pencarian spesifik berdasarkan Provinsi, Kota, Kecamatan, atau Desa.
  • CLI Tool: Cari kodepos langsung dari terminal.

Instalasi

npm install @damarkuncoro/posindonesia

Penggunaan (Library)

1. Pencarian Cepat (Rekomendasi)

Gunakan fungsi search global yang sudah dioptimalkan dengan cache internal.

import { search, searchByCode } from '@damarkuncoro/posindonesia';

// 🔍 Pencarian Lokal (Default, Offline, Super Cepat)
const localResults = await search(['Gambir', 'Jakarta Pusat']);

// 🌐 Pencarian Remote (Real-time dari situs Pos Indonesia)
const remoteResults = await search('Gambir', { source: 'remote' });

// 🧠 Pencarian Fuzzy (menangani typo: 'Gmbir' -> 'Gambir')
const fuzzy = await search('Gmbir', { useFuzzy: true });

// 📍 Pencarian Terstruktur (Structured)
const structured = await search({ 
  village: 'Gambir', 
  city: 'Jakarta Pusat' 
});

// ⚡ Pencarian Spesifik Provinsi (Nama atau Kode)
const byProvince = await search('Bandung', { province: 'Jawa Barat' });

// 🔢 Pencarian berdasarkan Kodepos (Instan/Indexed)
const byCode = await searchByCode('10110');

2. Penggunaan Advanced (Repository & Custom Data)

Untuk skenario yang lebih kompleks, seperti menggunakan sumber data Anda sendiri (misal: dari database), Anda dapat menyuntikkan DataProvider custom ke dalam TsPostalCodeRepository.

import { 
  TsPostalCodeRepository, 
  SearchPostalCode, 
  type DataProvider, 
  type PostalCodeData 
} from '@damarkuncoro/posindonesia';

// 1. Buat DataProvider Anda sendiri
class MyDbProvider implements DataProvider {
  async getAll(): Promise<PostalCodeData[]> {
    // Logika untuk mengambil data dari database Anda
    return []; 
  }
  async getByProvince(provinceCode: string): Promise<PostalCodeData[]> {
    // Logika untuk mengambil data provinsi tertentu dari DB
    return [];
  }
}

// 2. Suntikkan ke Repository
const myProvider = new MyDbProvider();
const repo = new TsPostalCodeRepository({ dataProvider: myProvider });

const searchUseCase = new SearchPostalCode(repo);
const results = await searchUseCase.execute(['Bandung']);

Penggunaan (CLI)

Anda dapat menggunakan library ini langsung dari terminal tanpa menulis kode.

# Setelah package di-publish ke npm:
npx @damarkuncoro/posindonesia search "Jakarta Pusat"

# Atau dengan cara lain:
npx posindonesia search "Jakarta Pusat"

Pengembangan (CLI Lokal)

Untuk pengembangan lokal atau sebelum package di-publish ke npm:

# Build terlebih dahulu
npm run build

# Cara 1: Langsung jalankan binary hasil build
node lib/esm/cli.js search "Jakarta Pusat" --remote

# Cara 2: Menggunakan tsx (tanpa build)
npx tsx src/cli.ts search "Jakarta Pusat" --remote

Contoh Penggunaan CLI

# Mencari berdasarkan kata kunci (Mode Lokal)
npx tsx src/cli.ts search "Gambir Jakarta"

# Mencari secara real-time dari situs resmi
npx tsx src/cli.ts search "Gambir" --remote

# Mencari dengan filter provinsi dan mode fuzzy
npx tsx src/cli.ts search "Gmbir" -p 31 --fuzzy

# Mencari berdasarkan kode postal
npx tsx src/cli.ts code 10110 --remote

Skema Data

Setiap hasil pencarian mengembalikan array objek PostalCode dengan struktur:

{
  province: string;       // Nama Provinsi
  provinceCode: string;   // Kode Kemendagri Provinsi
  city: string;           // Nama Kabupaten/Kota
  cityCode: string;       // Kode Kemendagri Kabupaten/Kota
  district: string;       // Nama Kecamatan
  districtCode: string;   // Kode Kemendagri Kecamatan
  village: string;        // Nama Desa/Kelurahan
  villageCode: string;    // Kode Kemendagri Desa/Kelurahan
  postalCode: string;     // Kodepos (5 digit)
}

Pengembangan

npm install
npm test            # Menjalankan unit tests
npm run lint        # Memeriksa standar kode
npm run build       # Build library (ESM & CJS)

Lisensi

MIT