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

@b4moss/jp-local-gov-id

v0.6.0

Published

日本の全国地方公共団体コードを扱う npm パッケージ

Readme

@b4moss/jp-local-gov-id

日本語

JS API for Japan’s nationwide local government codes. Data is not bundled — pass @b4moss/jp-local-gov-id-data or a versioned index URL.

Install

npm install @b4moss/jp-local-gov-id @b4moss/jp-local-gov-id-data
# or API only:
npm install @b4moss/jp-local-gov-id

Usage

createLocalGovClient is async. Either data or url (a versioned URL to index.json) is required.

On init it loads only the index and prefectures; municipalities are lazy-loaded per prefecture. Nationwide string search fetches unloaded prefecture JSON with concurrency of 6.

import { createLocalGovClient } from "@b4moss/jp-local-gov-id";
import dataset from "@b4moss/jp-local-gov-id-data";

const client = await createLocalGovClient({ data: dataset });

client.listPrefectures();
client.getPrefectureByCode("27");
client.getPrefectureCodeByName("大阪府"); // "27"
await client.listMunicipalitiesByPrefecture("13");
await client.listMunicipalitiesByPrefecture("01", { designatedCity: "city" }); // city body only
await client.getMunicipalityByCode("131016");
await client.getByCode("131016");
await client.searchByText("中央", { prefecture: "01", target: "cities" });
await client.searchByText("ちよだ", { prefecture: "13", target: "cities" });
await client.getLocalGovCodeByName("千代田区"); // "131016"

designatedCity ("both" | "city" | "ward", default "both") filters designated-city bodies vs wards on listMunicipalitiesByPrefecture, searchByText, and getLocalGovCodeByName. Tokyo special wards are not affected.

Fetch from a versioned index URL:

const client = await createLocalGovClient({
  url: "https://example.com/jp-local-gov-id-data/0.2.0/index.json",
});
  • When url is set, fetched files are cached in localStorage by default (key = file URL)
  • Disable with cache: false; set TTL via cacheTtlSeconds (seconds; default 1 year = 31536000)
  • Exception: municipality JSON loaded by nationwide string search is kept in memory only (not written to localStorage)
  • Environments without localStorage (e.g. Node) skip caching
  • String search normalizes hiragana / fullwidth kana to halfwidth kana (matchField default: "both")
  • Schema mismatches / invalid JSON raise LocalGovSchemaError; network / HTTP failures are normal fetch errors
  • Missing or ambiguous query results return null / [] (they do not throw)

Code formats

| Target | Format | Accepted input | |--------|--------|----------------| | Prefecture | 2-digit half-width digits | With or without zero-padding ("1" / "01") | | Municipality | 6 digits including check digit | 6 digits is the canonical form |

License

MIT

See the monorepo README for data layout, versioning, and development notes.