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

jp-postal-json

v0.2.0

Published

TypeScript utilities and static JSON client for Japanese postal code address lookup.

Readme

jp-postal-json

Japanese postal code utilities and a static JSON address lookup client.

Current version 0.2.0 provides postal code normalization, validation, prefix extraction, static data URL helpers, and a lookup client for hosted static JSON data.

日本の郵便番号を扱うための TypeScript first なユーティリティです。住所データ自体は npm package に同梱せず、デフォルトでは https://data.jp-postal.com/v1 の静的 JSON を参照します。

Installation

npm install jp-postal-json

Usage

import {
  buildPostalCodeDataUrl,
  createPostalCodeClient,
  getPostalCodePrefix,
  lookupPostalCode,
  normalizePostalCode,
  validatePostalCode
} from "jp-postal-json";

normalizePostalCode("100-0001"); // "1000001"
validatePostalCode("100-0001"); // true
getPostalCodePrefix("100-0001"); // "100"
buildPostalCodeDataUrl("100-0001"); // "https://data.jp-postal.com/v1/100.json"

const client = createPostalCodeClient();
const addresses = await client.lookup("100-0001");

const addresses2 = await lookupPostalCode("100-0001");

API

normalizePostalCode(input: string): string

Normalizes Japanese postal code input into digits only.

  • Converts full-width digits to half-width digits
  • Removes half-width hyphens, full-width hyphens, whitespace, and other non-digit characters

validatePostalCode(input: string): boolean

Returns true when the normalized input is exactly seven digits.

getPostalCodePrefix(input: string): string | null

Returns the first three digits after normalization and validation. Returns null for invalid postal codes.

buildPostalCodeDataUrl(input: string, options?: { baseUrl?: string }): string | null

Builds a static JSON data URL for the postal code prefix. This helper only builds a URL; it does not call fetch.

The default base URL is:

export const DEFAULT_DATA_BASE_URL = "https://data.jp-postal.com/v1";

createPostalCodeClient(options?: PostalCodeClientOptions): PostalCodeClient

Creates a lookup client.

const client = createPostalCodeClient();
const addresses = await client.lookup("100-0001");

By default, the client fetches prefix JSON from https://data.jp-postal.com/v1.

const client = createPostalCodeClient({
  baseUrl: "https://example.com/postal/v1"
});

When a prefix JSON endpoint returns 404, lookup returns an empty array instead of throwing.

await client.lookup("000-0000"); // []
await client.lookup("abc"); // []

Other HTTP errors, network errors, JSON parse errors, and invalid response structures throw.

The client uses globalThis.fetch by default. Pass fetcher to inject a custom fetch implementation for tests or custom runtimes.

const client = createPostalCodeClient({
  fetcher: customFetch
});

Prefix JSON responses are cached in memory by default. Pass cache: false to fetch every time, or call clearCache() to reset the cache.

const client = createPostalCodeClient();

await client.lookup("100-0001"); // fetches /100.json
await client.lookup("100-0005"); // reuses cached /100.json

client.clearCache();

lookupPostalCode(input: string, options?: LookupPostalCodeOptions): Promise<PostalAddress[]>

Looks up addresses without creating a client explicitly.

const addresses = await lookupPostalCode("100-0001");

Types

export type PostalAddress = {
  postalCode: string;
  prefecture: string;
  city: string;
  town: string;
  prefectureKana?: string;
  cityKana?: string;
  townKana?: string;
};

export type PostalCodePrefixData = Record<string, PostalAddress[]>;

export type PostalCodeClient = {
  lookup(input: string, options?: PostalCodeLookupOptions): Promise<PostalAddress[]>;
  clearCache(): void;
};

export type PostalCodeClientOptions = {
  baseUrl?: string;
  fetcher?: typeof fetch;
  cache?: boolean;
};

export type PostalCodeLookupOptions = {
  signal?: AbortSignal;
};

export type LookupPostalCodeOptions = PostalCodeClientOptions & PostalCodeLookupOptions;

Roadmap

  • Cloudflare Pages demo
  • Monthly data update workflow

Data Source Note

Hosted address data is based on public postal code data from Japan Post.

This package does not bundle postal address data.

Disclaimer / No SLA

This package is provided as-is, without any SLA.

No warranty is made for accuracy, availability, continued operation, or fitness for a particular purpose. Hosted JSON data should be mirrored or cached by users for production use.

For production systems, avoid depending solely on the hosted endpoint. Mirror or cache the JSON data when availability, latency, or data retention matters.

License

MIT