localized-regions 1.0.2 → 1.2.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 +50 -1
- package/dist/address.d.ts +8 -0
- package/dist/address.js +28 -0
- 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 +15 -0
- package/dist/index.js +35 -0
- package/dist/types.d.ts +6 -0
- package/package.json +1 -1
package/dist/data/countries.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { Country } from '../types';
|
|
2
|
-
declare const
|
|
3
|
-
export default
|
|
2
|
+
declare const data: Country[];
|
|
3
|
+
export default data;
|
package/dist/data/countries.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const
|
|
3
|
+
const data = [
|
|
4
4
|
{
|
|
5
5
|
"code": "AF",
|
|
6
6
|
"name": "Afghanistan"
|
|
@@ -1002,4 +1002,4 @@ const countries = [
|
|
|
1002
1002
|
"name": "Zimbabwe"
|
|
1003
1003
|
}
|
|
1004
1004
|
];
|
|
1005
|
-
exports.default =
|
|
1005
|
+
exports.default = data;
|
package/dist/data/provinces.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { Province } from '../types';
|
|
2
|
-
declare const
|
|
3
|
-
export default
|
|
2
|
+
declare const data: Record<string, Province[]>;
|
|
3
|
+
export default data;
|
package/dist/data/provinces.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const
|
|
3
|
+
const data = {
|
|
4
4
|
"AF": [
|
|
5
5
|
{
|
|
6
6
|
"code": "AF-BDS",
|
|
@@ -17872,24 +17872,6 @@ const provinces = {
|
|
|
17872
17872
|
}
|
|
17873
17873
|
],
|
|
17874
17874
|
"NL": [
|
|
17875
|
-
{
|
|
17876
|
-
"code": "NL-AW",
|
|
17877
|
-
"countryCode": "NL",
|
|
17878
|
-
"name": "Aruba",
|
|
17879
|
-
"type": "Country"
|
|
17880
|
-
},
|
|
17881
|
-
{
|
|
17882
|
-
"code": "NL-BQ1",
|
|
17883
|
-
"countryCode": "NL",
|
|
17884
|
-
"name": "Bonaire",
|
|
17885
|
-
"type": "Special municipality"
|
|
17886
|
-
},
|
|
17887
|
-
{
|
|
17888
|
-
"code": "NL-CW",
|
|
17889
|
-
"countryCode": "NL",
|
|
17890
|
-
"name": "Curaçao",
|
|
17891
|
-
"type": "Country"
|
|
17892
|
-
},
|
|
17893
17875
|
{
|
|
17894
17876
|
"code": "NL-DR",
|
|
17895
17877
|
"countryCode": "NL",
|
|
@@ -17944,24 +17926,6 @@ const provinces = {
|
|
|
17944
17926
|
"name": "Overijssel",
|
|
17945
17927
|
"type": "Province"
|
|
17946
17928
|
},
|
|
17947
|
-
{
|
|
17948
|
-
"code": "NL-BQ2",
|
|
17949
|
-
"countryCode": "NL",
|
|
17950
|
-
"name": "Saba",
|
|
17951
|
-
"type": "Special municipality"
|
|
17952
|
-
},
|
|
17953
|
-
{
|
|
17954
|
-
"code": "NL-BQ3",
|
|
17955
|
-
"countryCode": "NL",
|
|
17956
|
-
"name": "Sint Eustatius",
|
|
17957
|
-
"type": "Special municipality"
|
|
17958
|
-
},
|
|
17959
|
-
{
|
|
17960
|
-
"code": "NL-SX",
|
|
17961
|
-
"countryCode": "NL",
|
|
17962
|
-
"name": "Sint Maarten",
|
|
17963
|
-
"type": "Country"
|
|
17964
|
-
},
|
|
17965
17929
|
{
|
|
17966
17930
|
"code": "NL-UT",
|
|
17967
17931
|
"countryCode": "NL",
|
|
@@ -31030,4 +30994,4 @@ const provinces = {
|
|
|
31030
30994
|
}
|
|
31031
30995
|
]
|
|
31032
30996
|
};
|
|
31033
|
-
exports.default =
|
|
30997
|
+
exports.default = data;
|
package/dist/index.d.ts
CHANGED
|
@@ -19,12 +19,27 @@ export declare function getProvince(provinceCode: string): Province | undefined;
|
|
|
19
19
|
* Cities. With no provinceCode, returns all cities of the country. With a
|
|
20
20
|
* provinceCode, returns cities for that subdivision (Spain: mapped to the
|
|
21
21
|
* parent community, best-effort).
|
|
22
|
+
*
|
|
23
|
+
* The Netherlands is served from our own baked list (RAT-2000) rather than
|
|
24
|
+
* country-state-city, whose NL data is 19% "Gemeente X" municipality records
|
|
25
|
+
* and missing roughly 1000 real places. See scripts/generate.js.
|
|
22
26
|
*/
|
|
23
27
|
export declare function getCities(countryCode: string, provinceCode?: string): City[];
|
|
28
|
+
/**
|
|
29
|
+
* Does this city match what the user typed? Matches the display name and any
|
|
30
|
+
* alias, so typing "'s-Gravenhage" finds "Den Haag" without ever offering the
|
|
31
|
+
* formal name as a selectable option (RAT-2000).
|
|
32
|
+
*
|
|
33
|
+
* Pass it to react-select's filterOption. Callers using a Creatable select
|
|
34
|
+
* must let the synthetic "create" option through before calling this - it has
|
|
35
|
+
* no `name` and would otherwise be filtered away.
|
|
36
|
+
*/
|
|
37
|
+
export declare function cityMatches(city: City, input: string): boolean;
|
|
24
38
|
/** Country options for react-select / MUI. value = ISO code, label = bilingual. */
|
|
25
39
|
export declare function countryOptions(locale?: string): Option[];
|
|
26
40
|
/** Province options. value = ISO 3166-2 code, label = province name. */
|
|
27
41
|
export declare function provinceOptions(countryCode: string): Option[];
|
|
28
42
|
/** City options. value = label = city name (cities have no stable code). */
|
|
29
43
|
export declare function cityOptions(countryCode: string, provinceCode?: string): Option[];
|
|
44
|
+
export { formatAddressLine1, isHouseNumberFirst } from './address';
|
|
30
45
|
export * from './types';
|
package/dist/index.js
CHANGED
|
@@ -17,12 +17,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
17
17
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
18
|
};
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
exports.isHouseNumberFirst = exports.formatAddressLine1 = void 0;
|
|
20
21
|
exports.getCountries = getCountries;
|
|
21
22
|
exports.getCountry = getCountry;
|
|
22
23
|
exports.formatCountryLabel = formatCountryLabel;
|
|
23
24
|
exports.getProvinces = getProvinces;
|
|
24
25
|
exports.getProvince = getProvince;
|
|
25
26
|
exports.getCities = getCities;
|
|
27
|
+
exports.cityMatches = cityMatches;
|
|
26
28
|
exports.countryOptions = countryOptions;
|
|
27
29
|
exports.provinceOptions = provinceOptions;
|
|
28
30
|
exports.cityOptions = cityOptions;
|
|
@@ -32,6 +34,7 @@ const country_state_city_1 = require("country-state-city");
|
|
|
32
34
|
// or dynamic `require`.
|
|
33
35
|
const countries_1 = __importDefault(require("./data/countries"));
|
|
34
36
|
const provinces_1 = __importDefault(require("./data/provinces"));
|
|
37
|
+
const cities_nl_1 = __importDefault(require("./data/cities-nl"));
|
|
35
38
|
function displayName(code, locale) {
|
|
36
39
|
try {
|
|
37
40
|
return new Intl.DisplayNames([locale], { type: 'region' }).of(code) || undefined;
|
|
@@ -87,9 +90,21 @@ const ES_COMMUNITY_TO_SOURCE = {
|
|
|
87
90
|
* Cities. With no provinceCode, returns all cities of the country. With a
|
|
88
91
|
* provinceCode, returns cities for that subdivision (Spain: mapped to the
|
|
89
92
|
* parent community, best-effort).
|
|
93
|
+
*
|
|
94
|
+
* The Netherlands is served from our own baked list (RAT-2000) rather than
|
|
95
|
+
* country-state-city, whose NL data is 19% "Gemeente X" municipality records
|
|
96
|
+
* and missing roughly 1000 real places. See scripts/generate.js.
|
|
90
97
|
*/
|
|
91
98
|
function getCities(countryCode, provinceCode) {
|
|
92
99
|
const cc = countryCode.toUpperCase();
|
|
100
|
+
if (cc === 'NL') {
|
|
101
|
+
if (!provinceCode) {
|
|
102
|
+
return Object.values(cities_nl_1.default)
|
|
103
|
+
.flat()
|
|
104
|
+
.sort((a, b) => a.name.localeCompare(b.name, 'nl'));
|
|
105
|
+
}
|
|
106
|
+
return cities_nl_1.default[provinceCode.toUpperCase()] || [];
|
|
107
|
+
}
|
|
93
108
|
if (!provinceCode) {
|
|
94
109
|
return country_state_city_1.City.getCitiesOfCountry(cc) || [];
|
|
95
110
|
}
|
|
@@ -103,6 +118,23 @@ function getCities(countryCode, provinceCode) {
|
|
|
103
118
|
const bare = provinceCode.includes('-') ? provinceCode.split('-').slice(1).join('-') : provinceCode;
|
|
104
119
|
return country_state_city_1.City.getCitiesOfState(cc, bare) || [];
|
|
105
120
|
}
|
|
121
|
+
/**
|
|
122
|
+
* Does this city match what the user typed? Matches the display name and any
|
|
123
|
+
* alias, so typing "'s-Gravenhage" finds "Den Haag" without ever offering the
|
|
124
|
+
* formal name as a selectable option (RAT-2000).
|
|
125
|
+
*
|
|
126
|
+
* Pass it to react-select's filterOption. Callers using a Creatable select
|
|
127
|
+
* must let the synthetic "create" option through before calling this - it has
|
|
128
|
+
* no `name` and would otherwise be filtered away.
|
|
129
|
+
*/
|
|
130
|
+
function cityMatches(city, input) {
|
|
131
|
+
const query = input.trim().toLowerCase();
|
|
132
|
+
if (!query)
|
|
133
|
+
return true;
|
|
134
|
+
if (city.name.toLowerCase().includes(query))
|
|
135
|
+
return true;
|
|
136
|
+
return (city.aliases ?? []).some((alias) => alias.toLowerCase().includes(query));
|
|
137
|
+
}
|
|
106
138
|
// --------------------------------------------------- ready-to-use dropdown options
|
|
107
139
|
/** Country options for react-select / MUI. value = ISO code, label = bilingual. */
|
|
108
140
|
function countryOptions(locale) {
|
|
@@ -116,4 +148,7 @@ function provinceOptions(countryCode) {
|
|
|
116
148
|
function cityOptions(countryCode, provinceCode) {
|
|
117
149
|
return getCities(countryCode, provinceCode).map((c) => ({ value: c.name, label: c.name }));
|
|
118
150
|
}
|
|
151
|
+
var address_1 = require("./address");
|
|
152
|
+
Object.defineProperty(exports, "formatAddressLine1", { enumerable: true, get: function () { return address_1.formatAddressLine1; } });
|
|
153
|
+
Object.defineProperty(exports, "isHouseNumberFirst", { enumerable: true, get: function () { return address_1.isHouseNumberFirst; } });
|
|
119
154
|
__exportStar(require("./types"), exports);
|
package/dist/types.d.ts
CHANGED
|
@@ -33,6 +33,12 @@ export interface City {
|
|
|
33
33
|
stateCode?: string;
|
|
34
34
|
latitude?: string;
|
|
35
35
|
longitude?: string;
|
|
36
|
+
/**
|
|
37
|
+
* Extra strings that should match while typing but are never displayed or
|
|
38
|
+
* stored, e.g. "'s-Gravenhage" for Den Haag (RAT-2000). Use cityMatches()
|
|
39
|
+
* rather than reading this directly.
|
|
40
|
+
*/
|
|
41
|
+
aliases?: string[];
|
|
36
42
|
}
|
|
37
43
|
/** react-select / MUI style option */
|
|
38
44
|
export interface Option {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "localized-regions",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "Country, province and city data with bilingual localized labels (e.g. \"España (Spain)\") and ISO 3166-1 / ISO 3166-2 codes. Ships all 50 Spanish provinces. Framework-agnostic, drop-in options for react-select and MUI dropdowns.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|