jp-local-gov-id

app-0.6.0data-0.1.0

API

Overview of the client returned by createLocalGovClient.

createLocalGovClient(options)

OptionDescription
datanpm dataset (or equivalent object)
urlVersioned URL to index.json
cachelocalStorage cache for url mode. Default true
cacheTtlSecondsCache TTL in seconds. Default 31536000 (1 year)

Exactly one of data or url is required. cache / cacheTtlSeconds apply to url mode (unused for URL caching when using data).

LocalGov

FieldTypeDescription
codestringEntity code
namestringName
nameKanastringHalfwidth kana
prefectureCodestringPrefecture code (2 digits)
prefectureNamestringPrefecture name
prefectureNameKanastringPrefecture kana

Methods

MethodReturnsDescription
listPrefectures()LocalGov[]All prefectures
getPrefectureByCode(code)LocalGov | nullLookup by prefecture code
getPrefectureCodeByName(name)string | nullPrefecture code from exact name
listMunicipalitiesByPrefecture(pref, options?)Promise<LocalGov[]>Municipalities in a prefecture (lazy)
getMunicipalityByCode(code)Promise<LocalGov | null>Lookup by 6-digit municipality code
getByCode(code)Promise<LocalGov | null>Auto-detect 2-digit / 6-digit
searchByText(text, options?)Promise<LocalGov[]>Partial-match search
getLocalGovCodeByName(name, options?)Promise<string | null>Code from exact name

designatedCity option

Filters designated-city bodies vs administrative wards. Default is "both". Tokyo special wards (e.g. 千代田区) are not affected.

ValueMeaning
"both"City body and wards (default)
"city"City body only (exclude wards)
"ward"Wards only (exclude city bodies)

Applies to: listMunicipalitiesByPrefecture / searchByText / getLocalGovCodeByName

listMunicipalitiesByPrefecture options

KeyTypeDefaultDescription
designatedCity'both' | 'city' | 'ward''both'Designated-city body/ward filter

searchByText / getLocalGovCodeByName options

KeyTypeDefaultDescription
prefecturestringFilter by prefecture
target'all' | 'prefectures' | 'cities''all'Search target
matchField'name' | 'nameKana' | 'both''both'Fields to match
designatedCity'both' | 'city' | 'ward''both'Designated-city body/ward filter

String search normalizes hiragana / fullwidth kana to halfwidth kana.

Errors and empty results

  • Schema mismatch / invalid JSON → LocalGovSchemaError
  • Network / HTTP failures → normal fetch errors
  • Missing or ambiguous results → null / [] (no throw)

Caching in url mode

  • By default, fetched files are cached in localStorage (key = URL)
  • Disable with cache: false
  • Set TTL with cacheTtlSeconds (seconds; default 1 year = 31536000)
  • Municipality JSON loaded by nationwide string search stays in memory only