localized-regions 1.0.2 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +31 -1
- package/dist/data/cities-nl.d.ts +3 -0
- package/dist/data/cities-nl.js +12345 -0
- package/dist/data/countries.d.ts +2 -2
- package/dist/data/countries.js +2 -2
- package/dist/data/provinces.d.ts +2 -2
- package/dist/data/provinces.js +2 -38
- package/dist/index.d.ts +14 -0
- package/dist/index.js +31 -0
- package/dist/types.d.ts +6 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -24,6 +24,7 @@ provinceOptions('ES'); // [{ value: 'ES-MA', label: 'Málaga' }, { value: 'ES-B
|
|
|
24
24
|
- **Correct Spanish provinces** - all **50 provinces** with ISO 3166-2 codes and their parent autonomous community. (Popular datasets like `country-state-city` return only ~16 of them for Spain.)
|
|
25
25
|
- **Stable, invoicing-safe values** - country = ISO 3166-1 code (`ES`), province = ISO 3166-2 code (`ES-MA`). Labels are display-only.
|
|
26
26
|
- **Full city database** - cities for every country, sourced from `country-state-city` at runtime.
|
|
27
|
+
- **Correct Dutch cities** - the Netherlands is served from the official Dutch place register (BAG woonplaatsen), not `country-state-city`, whose NL list is 19% `Gemeente X` municipality records and missing roughly 1000 real places.
|
|
27
28
|
- **Framework-agnostic** - no React / MUI / Chakra dependency. Plain data plus ready-to-use `{ value, label }` options.
|
|
28
29
|
- **TypeScript types included.**
|
|
29
30
|
|
|
@@ -92,6 +93,7 @@ import { countryOptions } from 'localized-regions';
|
|
|
92
93
|
| `getProvinces(countryCode)` | `Province[]` (Spain = curated 50) |
|
|
93
94
|
| `getProvince(provinceCode)` | `Province` |
|
|
94
95
|
| `getCities(countryCode, provinceCode?)` | `City[]` |
|
|
96
|
+
| `cityMatches(city, input)` | `boolean` - does this city match typed input, by name or alias |
|
|
95
97
|
| `countryOptions(locale?)` | `Option[]` (`{ value, label }`) |
|
|
96
98
|
| `provinceOptions(countryCode)` | `Option[]` |
|
|
97
99
|
| `cityOptions(countryCode, provinceCode?)` | `Option[]` |
|
|
@@ -102,7 +104,8 @@ Data is generated at build time (`npm run generate`) and committed under `data/`
|
|
|
102
104
|
|
|
103
105
|
- **Countries** - `Intl.DisplayNames` (English) plus a code list, 250 countries.
|
|
104
106
|
- **Provinces** - `iso-3166-2` subdivisions. Spain is curated to 50 provinces, with 4 regional-language names aliased to their common form (Nafarroa -> Navarra, Balears -> Balearic Islands, Alacant -> Alicante, Castelló -> Castellón).
|
|
105
|
-
- **Cities** - `country-state-city` at runtime.
|
|
107
|
+
- **Cities** - `country-state-city` at runtime, except the Netherlands.
|
|
108
|
+
- **Netherlands cities** - the official BAG woonplaats register, fetched at build time from the PDOK Locatieserver and baked into `data/cities-nl`. No runtime API call and no API key. Generation fails if a `Gemeente X` entry ever reappears.
|
|
106
109
|
|
|
107
110
|
Regenerate after a data-source bump:
|
|
108
111
|
|
|
@@ -110,6 +113,33 @@ Regenerate after a data-source bump:
|
|
|
110
113
|
npm run generate && npm run build
|
|
111
114
|
```
|
|
112
115
|
|
|
116
|
+
## Netherlands cities
|
|
117
|
+
|
|
118
|
+
NL city data comes from the official Dutch place register (BAG woonplaatsen, via
|
|
119
|
+
the PDOK Locatieserver) rather than `country-state-city`, whose NL list contains
|
|
120
|
+
325 `Gemeente X` municipality records and is missing roughly 1000 real places.
|
|
121
|
+
|
|
122
|
+
The Hague is returned as `Den Haag` - the name the municipality, PostNL and
|
|
123
|
+
Taaladvies all use for addresses. Its formal name `'s-Gravenhage` is kept as a
|
|
124
|
+
search alias on `City.aliases`, never as a separate selectable option. Use
|
|
125
|
+
`cityMatches` as your select's `filterOption` so aliases are searchable:
|
|
126
|
+
|
|
127
|
+
```js
|
|
128
|
+
import { getCities, cityMatches } from 'localized-regions';
|
|
129
|
+
|
|
130
|
+
<Select
|
|
131
|
+
options={getCities('NL', 'NL-ZH')}
|
|
132
|
+
getOptionLabel={(c) => c.name}
|
|
133
|
+
getOptionValue={(c) => c.name}
|
|
134
|
+
filterOption={(option, input) => cityMatches(option.data, input)}
|
|
135
|
+
/>
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
`getProvinces('NL')` returns the 12 real provinces. Aruba, Curacao and Sint
|
|
139
|
+
Maarten are separate constituent countries, and Bonaire, Saba and Sint Eustatius
|
|
140
|
+
are Caribbean special municipalities; ISO 3166-2 lists all six under NL, but they
|
|
141
|
+
are not provinces and have no cities, so they are excluded.
|
|
142
|
+
|
|
113
143
|
## Notes and limitations
|
|
114
144
|
|
|
115
145
|
- **Spain city cascade is community-level.** The source city data groups Spanish cities under autonomous communities, not the 50 provinces, so `getCities('ES', 'ES-MA')` returns the parent community's cities (best-effort). City is best treated as a free-text field.
|