localized-regions 1.1.0 → 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 +19 -0
- package/dist/address.d.ts +8 -0
- package/dist/address.js +28 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +4 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -97,6 +97,8 @@ import { countryOptions } from 'localized-regions';
|
|
|
97
97
|
| `countryOptions(locale?)` | `Option[]` (`{ value, label }`) |
|
|
98
98
|
| `provinceOptions(countryCode)` | `Option[]` |
|
|
99
99
|
| `cityOptions(countryCode, provinceCode?)` | `Option[]` |
|
|
100
|
+
| `formatAddressLine1(countryCode, street, houseNumber)` | address line 1 in the country's own order |
|
|
101
|
+
| `isHouseNumberFirst(countryCode)` | `boolean` - does this country write the number before the street |
|
|
100
102
|
|
|
101
103
|
## How the data is built
|
|
102
104
|
|
|
@@ -140,6 +142,23 @@ Maarten are separate constituent countries, and Bonaire, Saba and Sint Eustatius
|
|
|
140
142
|
are Caribbean special municipalities; ISO 3166-2 lists all six under NL, but they
|
|
141
143
|
are not provinces and have no cities, so they are excluded.
|
|
142
144
|
|
|
145
|
+
## Address line 1 order
|
|
146
|
+
|
|
147
|
+
Countries disagree on whether the house number comes before or after the
|
|
148
|
+
street. `formatAddressLine1` builds line 1 from the separate street and number
|
|
149
|
+
(for example Google Places `route` + `street_number`) in the country's order:
|
|
150
|
+
|
|
151
|
+
```js
|
|
152
|
+
import { formatAddressLine1 } from 'localized-regions';
|
|
153
|
+
|
|
154
|
+
formatAddressLine1('NL', 'Boerendanserdijk', '43a'); // "Boerendanserdijk 43a"
|
|
155
|
+
formatAddressLine1('ES', 'Calle Mayor', '12'); // "Calle Mayor 12"
|
|
156
|
+
formatAddressLine1('GB', 'Downing Street', '10'); // "10 Downing Street"
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
GB, IE, LU, FR and US put the number first; every other country puts the street
|
|
160
|
+
first. A missing street or number is simply left out.
|
|
161
|
+
|
|
143
162
|
## Notes and limitations
|
|
144
163
|
|
|
145
164
|
- **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.
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** Does this country write the house number before the street? */
|
|
2
|
+
export declare function isHouseNumberFirst(countryCode: string): boolean;
|
|
3
|
+
/**
|
|
4
|
+
* Address line 1 in the order the country writes it. `houseNumber` keeps any
|
|
5
|
+
* addition as given ("43a"). A missing street or number is left out rather
|
|
6
|
+
* than leaving a stray space, so `formatAddressLine1('NL', 'Dam', '')` is "Dam".
|
|
7
|
+
*/
|
|
8
|
+
export declare function formatAddressLine1(countryCode: string, street: string, houseNumber: string): string;
|
package/dist/address.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isHouseNumberFirst = isHouseNumberFirst;
|
|
4
|
+
exports.formatAddressLine1 = formatAddressLine1;
|
|
5
|
+
/**
|
|
6
|
+
* Countries whose postal address puts the house number before the street, e.g.
|
|
7
|
+
* "10 Downing Street". Every other country writes the street first, e.g.
|
|
8
|
+
* "Boerendanserdijk 43a" (NL) or "Calle Mayor 12" (ES).
|
|
9
|
+
*
|
|
10
|
+
* ISO 3166-1 alpha-2, as Google Places returns it - the UK is "GB" (RAT-2178).
|
|
11
|
+
*/
|
|
12
|
+
const HOUSE_NUMBER_FIRST_COUNTRIES = new Set(['GB', 'IE', 'LU', 'FR', 'US']);
|
|
13
|
+
/** Does this country write the house number before the street? */
|
|
14
|
+
function isHouseNumberFirst(countryCode) {
|
|
15
|
+
return HOUSE_NUMBER_FIRST_COUNTRIES.has((countryCode ?? '').trim().toUpperCase());
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Address line 1 in the order the country writes it. `houseNumber` keeps any
|
|
19
|
+
* addition as given ("43a"). A missing street or number is left out rather
|
|
20
|
+
* than leaving a stray space, so `formatAddressLine1('NL', 'Dam', '')` is "Dam".
|
|
21
|
+
*/
|
|
22
|
+
function formatAddressLine1(countryCode, street, houseNumber) {
|
|
23
|
+
const parts = isHouseNumberFirst(countryCode) ? [houseNumber, street] : [street, houseNumber];
|
|
24
|
+
return parts
|
|
25
|
+
.map((part) => (part ?? '').trim())
|
|
26
|
+
.filter(Boolean)
|
|
27
|
+
.join(' ');
|
|
28
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -41,4 +41,5 @@ export declare function countryOptions(locale?: string): Option[];
|
|
|
41
41
|
export declare function provinceOptions(countryCode: string): Option[];
|
|
42
42
|
/** City options. value = label = city name (cities have no stable code). */
|
|
43
43
|
export declare function cityOptions(countryCode: string, provinceCode?: string): Option[];
|
|
44
|
+
export { formatAddressLine1, isHouseNumberFirst } from './address';
|
|
44
45
|
export * from './types';
|
package/dist/index.js
CHANGED
|
@@ -17,6 +17,7 @@ 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;
|
|
@@ -147,4 +148,7 @@ function provinceOptions(countryCode) {
|
|
|
147
148
|
function cityOptions(countryCode, provinceCode) {
|
|
148
149
|
return getCities(countryCode, provinceCode).map((c) => ({ value: c.name, label: c.name }));
|
|
149
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; } });
|
|
150
154
|
__exportStar(require("./types"), exports);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "localized-regions",
|
|
3
|
-
"version": "1.
|
|
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",
|