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

@acfatah/malaysia-postcodes-data

v2.1.1

Published

Script to generate flattened JSON objects list of Malaysia postcodes data, sorted by the postcode number.

Downloads

123

Readme

Malaysia Postcodes Data

Flattened JSON objects list of Malaysia postcodes data, sorted by the postcode number.

[!IMPORTANT] Original data is pulled from AsyrafHussin/malaysia-postcodes. Credit belongs to the respective owner.

Read the changelog.

Development

To build the project locally, run:

bun install && bun run build

It will pull the latest data from the AsyrafHussin/malaysia-postcodes repository and generate the JSON files in the dist/ folder.

Why Create Another Repository?

The Problem:

When users need to input their address, they often have to manually type their city and state, which can be prone to errors. Additionally, querying a full database for postcode information can be slow and resource-intensive.

Our Solution:

This repository offers a lightweight and efficient solution to auto-populate city and state fields based on a postcode input. By extracting the first two digits from the postcode, we can quickly narrow down the possible locations and suggest accurate inputs using CDN.

How It Works:

Here's a simple example of how to use the repository to fetch city and state suggestions:

// Assuming 'postcodeInput' is a string containing the postcode entered by the user.
const [_, prefix] = postcodeInput.match(/^(\d{2})/) || [null, '']

let postcodes = []
if (prefix.length === 2) {
  // Fetch the relevant postcode data using the first two digits as a prefix.
  try {
    const cdnUrl = `https://raw.githubusercontent.com/acfatah/malaysia-postcodes-data/refs/heads/main/dist/${prefix}xxx-postcodes.json`
    const response = await fetch(cdnUrl)
    postcodes = await response.json()
  }
  catch (error) {
    // Handle fetch error (e.g., file not found, network issues)
  }
}
else if (postcodes.length > 0 && prefix.length > 2) {
  // If more than two digits are provided, we can filter the results further.
  postcodes = postcodes.filter(pc => pc.postcode.startsWith(prefix))
}

// Now you can use 'postcodes' to suggest city and state names.

CDN Url Examples

Advantages:

  • Performance: This method is fast as it avoids loading the entire postcode dataset into memory.

  • Ease of Use: Developers can integrate this functionality without setting up and maintaining a separate database.

  • Scalability: It scales well because each request only retrieves a small, specific subset of data.

By utilizing this approach, we can significantly improve user experience by streamlining the form completion process and reducing input errors.

Database Seeding

You can use data from the dist/all-postcodes.json file to seed your database with Malaysia postcodes.

Each entry in all-postcodes.json is a flat JSON object (e.g. { "postcode": "43000", "city": "Kajang", "state": "Selangor" }), so you can iterate over the array and insert each record into your database using your preferred migration or seeding tool.