localized-regions 1.0.0 → 1.0.2
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 +6 -6
- package/dist/data/countries.d.ts +3 -0
- package/dist/data/countries.js +1005 -0
- package/dist/data/provinces.d.ts +3 -0
- package/dist/data/provinces.js +31033 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +14 -36
- package/dist/types.d.ts +1 -1
- package/package.json +2 -3
- package/data/countries.json +0 -1002
- package/data/provinces.json +0 -31030
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
[](./dist/index.d.ts)
|
|
7
7
|
|
|
8
8
|
**Country, province and city data with bilingual localized labels and ISO 3166 codes.**
|
|
9
|
-
Get country / province / city dropdown options with labels like `
|
|
9
|
+
Get country / province / city dropdown options with labels like `España (Spain)`, stable ISO
|
|
10
10
|
3166-1 and ISO 3166-2 codes, and the full set of **50 Spanish provinces** (not the 17
|
|
11
11
|
autonomous communities). Framework-agnostic and TypeScript-first: the data drops straight into
|
|
12
12
|
**react-select**, **MUI Autocomplete**, or any dropdown.
|
|
@@ -14,13 +14,13 @@ autonomous communities). Framework-agnostic and TypeScript-first: the data drops
|
|
|
14
14
|
```ts
|
|
15
15
|
import { countryOptions, provinceOptions } from 'localized-regions';
|
|
16
16
|
|
|
17
|
-
countryOptions('es'); // [{ value: 'ES', label: '
|
|
17
|
+
countryOptions('es'); // [{ value: 'ES', label: 'España (Spain)' }, { value: 'NL', label: 'Nederland (Netherlands)' }, ...]
|
|
18
18
|
provinceOptions('ES'); // [{ value: 'ES-MA', label: 'Málaga' }, { value: 'ES-B', label: 'Barcelona' }, ...]
|
|
19
19
|
```
|
|
20
20
|
|
|
21
21
|
## Features
|
|
22
22
|
|
|
23
|
-
- **Bilingual / localized country labels** - `
|
|
23
|
+
- **Bilingual / localized country labels** - `España (Spain)`, `Deutschland (Germany)`, `Nederland (Netherlands)`, computed from the browser-native `Intl.DisplayNames` for any locale.
|
|
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.
|
|
@@ -43,7 +43,7 @@ import {
|
|
|
43
43
|
} from 'localized-regions';
|
|
44
44
|
|
|
45
45
|
// Bilingual country labels (the locale drives the native part)
|
|
46
|
-
getCountries({ locale: 'es' }); // [{ code:'ES', name:'Spain', localized:'España', label:'
|
|
46
|
+
getCountries({ locale: 'es' }); // [{ code:'ES', name:'Spain', localized:'España', label:'España (Spain)' }, ...]
|
|
47
47
|
getCountries(); // English-only labels
|
|
48
48
|
|
|
49
49
|
// Spain -> 50 provinces (ISO 3166-2 codes + community grouping)
|
|
@@ -53,11 +53,11 @@ getProvinces('ES'); // [{ code:'ES-MA', countryCode:'ES', name:'Má
|
|
|
53
53
|
getCities('ES', 'ES-MA');
|
|
54
54
|
|
|
55
55
|
// Ready-to-use dropdown options
|
|
56
|
-
countryOptions('es'); // [{ value:'ES', label:'
|
|
56
|
+
countryOptions('es'); // [{ value:'ES', label:'España (Spain)' }, ...]
|
|
57
57
|
provinceOptions('ES'); // [{ value:'ES-MA', label:'Málaga' }, ...]
|
|
58
58
|
cityOptions('ES', 'ES-MA'); // [{ value:'Málaga', label:'Málaga' }, ...]
|
|
59
59
|
|
|
60
|
-
formatCountryLabel('ES', 'es'); // "
|
|
60
|
+
formatCountryLabel('ES', 'es'); // "España (Spain)"
|
|
61
61
|
```
|
|
62
62
|
|
|
63
63
|
### With react-select (editable / creatable dropdowns)
|