@innovayse/geo-atlas 2.1.0 → 2.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 +57 -20
- package/dist/cjs/cities.d.ts +12 -0
- package/dist/cjs/cities.js +58 -0
- package/dist/cjs/helpers/CountriesAtlas.d.ts +11 -71
- package/dist/cjs/helpers/CountriesAtlas.js +11 -161
- package/dist/cjs/helpers/CountriesData.d.ts +86 -0
- package/dist/cjs/helpers/CountriesData.js +157 -0
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/index.js +7 -1
- package/dist/cjs/lite.d.ts +27 -0
- package/dist/cjs/lite.js +30 -0
- package/dist/esm/cities.d.ts +12 -0
- package/dist/esm/cities.js +51 -0
- package/dist/esm/helpers/CountriesAtlas.d.ts +11 -71
- package/dist/esm/helpers/CountriesAtlas.js +11 -161
- package/dist/esm/helpers/CountriesData.d.ts +86 -0
- package/dist/esm/helpers/CountriesData.js +150 -0
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js +4 -0
- package/dist/esm/lite.d.ts +27 -0
- package/dist/esm/lite.js +22 -0
- package/package.json +13 -1
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import countriesData from '../data/atlas.json';
|
|
2
|
+
/**
|
|
3
|
+
* Lightweight country-list helper.
|
|
4
|
+
*
|
|
5
|
+
* Loads ONLY the bundled `atlas.json` (the country list plus per-country
|
|
6
|
+
* metadata: names, translations, phone, currency, timezones). It deliberately
|
|
7
|
+
* does NOT import the per-country state/city loaders (`countryLoaders`), so
|
|
8
|
+
* importing this class never drags the ~171 MB of per-country state/city JSON
|
|
9
|
+
* into a consumer's bundle.
|
|
10
|
+
*
|
|
11
|
+
* Use this when you only need countries, phone codes, currencies or timezones
|
|
12
|
+
* — e.g. on a server-rendered path. When you need states/cities, use
|
|
13
|
+
* `CountriesAtlas` (which extends this) or the `@touchestate/geo-atlas/cities`
|
|
14
|
+
* entry point.
|
|
15
|
+
*/
|
|
16
|
+
export class CountriesData {
|
|
17
|
+
/** Initializes the atlas by loading the bundled country data. */
|
|
18
|
+
constructor() {
|
|
19
|
+
this.countries = countriesData;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Retrieve all countries with specified properties, or all countries if no properties are specified.
|
|
23
|
+
*
|
|
24
|
+
* @param {string[]} properties - Array of properties to retrieve.
|
|
25
|
+
* @return {Country[]} - Array of country objects with specified properties or all countries.
|
|
26
|
+
*/
|
|
27
|
+
getCountries(properties) {
|
|
28
|
+
if (properties) {
|
|
29
|
+
return this.countries.map(country => {
|
|
30
|
+
const newCountry = {};
|
|
31
|
+
properties.forEach(property => {
|
|
32
|
+
newCountry[property] = country[property];
|
|
33
|
+
});
|
|
34
|
+
return newCountry;
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
return this.countries;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Find a country by its ISO2 code.
|
|
41
|
+
*
|
|
42
|
+
* @param {string} iso2 - ISO2 code of the country to find.
|
|
43
|
+
* @return {Country | undefined} - Country object or undefined if not found.
|
|
44
|
+
*/
|
|
45
|
+
find(iso2) {
|
|
46
|
+
return this.countries.find(country => { var _a; return ((_a = country.iso2) === null || _a === void 0 ? void 0 : _a.toUpperCase()) === iso2.toUpperCase(); });
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Find a country by its ISO3 code.
|
|
50
|
+
*
|
|
51
|
+
* @param {string} iso3 - ISO3 code of the country to find.
|
|
52
|
+
* @return {Country | undefined} - Country object or undefined if not found.
|
|
53
|
+
*/
|
|
54
|
+
findByIso3(iso3) {
|
|
55
|
+
return this.countries.find(country => { var _a; return ((_a = country.iso3) === null || _a === void 0 ? void 0 : _a.toUpperCase()) === iso3.toUpperCase(); });
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Retrieve all timezones of all available countries.
|
|
59
|
+
*
|
|
60
|
+
* @returns {Timezone[]} - Array of timezone objects.
|
|
61
|
+
*/
|
|
62
|
+
getTimezones() {
|
|
63
|
+
const timezoneSet = new Set();
|
|
64
|
+
this.countries.forEach(country => {
|
|
65
|
+
var _a;
|
|
66
|
+
(_a = country.timezones) === null || _a === void 0 ? void 0 : _a.forEach(timezone => {
|
|
67
|
+
timezoneSet.add(timezone);
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
return Array.from(timezoneSet);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Retrieve all timezones of a country by its ISO2 code.
|
|
74
|
+
*
|
|
75
|
+
* @param {string} iso2 - ISO2 code of the country.
|
|
76
|
+
* @returns {Timezone[] | undefined} - Array of timezone objects or undefined if not found.
|
|
77
|
+
*/
|
|
78
|
+
timezone(iso2) {
|
|
79
|
+
const country = this.find(iso2);
|
|
80
|
+
if (country) {
|
|
81
|
+
return country.timezones;
|
|
82
|
+
}
|
|
83
|
+
return undefined;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Retrieve all calling codes of all available countries.
|
|
87
|
+
*
|
|
88
|
+
* @returns {PhoneCode[]} - Array of phone code objects.
|
|
89
|
+
*/
|
|
90
|
+
getCallingCodes() {
|
|
91
|
+
return this.getCountries(['name', 'phone', 'iso2', 'phone_format']).map(country => {
|
|
92
|
+
var _a;
|
|
93
|
+
return Object.assign(Object.assign({}, country), { phone_code: `+${country.phone}`, flag: `flag flag-${(_a = country.iso2) === null || _a === void 0 ? void 0 : _a.toLowerCase()}` });
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Retrieve calling codes of a country by its ISO2 code.
|
|
98
|
+
*
|
|
99
|
+
* @param {string} iso2 - ISO2 code of the country.
|
|
100
|
+
* @returns {PhoneCode | undefined} - Phone code object or undefined if not found.
|
|
101
|
+
*/
|
|
102
|
+
callingCode(iso2) {
|
|
103
|
+
var _a;
|
|
104
|
+
const country = this.find(iso2);
|
|
105
|
+
if (country) {
|
|
106
|
+
return {
|
|
107
|
+
name: country.name,
|
|
108
|
+
phone: country.phone,
|
|
109
|
+
iso2: country.iso2,
|
|
110
|
+
phone_code: `+${country.phone}`,
|
|
111
|
+
flag: `flag flag-${(_a = country.iso2) === null || _a === void 0 ? void 0 : _a.toLowerCase()}`,
|
|
112
|
+
phone_format: country.phone_format
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
return undefined;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Retrieve all currencies of all available countries.
|
|
119
|
+
*
|
|
120
|
+
* @returns {Currency[]} - Array of currency objects.
|
|
121
|
+
*/
|
|
122
|
+
getCurrencies() {
|
|
123
|
+
return this.getCountries(['name', 'iso2', 'currency', 'currency_symbol', 'currency_name']).map(country => {
|
|
124
|
+
var _a;
|
|
125
|
+
return Object.assign(Object.assign({}, country), { flag: `flag flag-${(_a = country.iso2) === null || _a === void 0 ? void 0 : _a.toLowerCase()}` });
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Retrieve currency of a country by its ISO2 code.
|
|
130
|
+
*
|
|
131
|
+
* @param {string} iso2 - ISO2 code of the country.
|
|
132
|
+
* @returns {Currency | undefined} - Currency object or undefined if not found.
|
|
133
|
+
*/
|
|
134
|
+
currency(iso2) {
|
|
135
|
+
var _a;
|
|
136
|
+
const country = this.find(iso2);
|
|
137
|
+
if (country) {
|
|
138
|
+
return {
|
|
139
|
+
name: country.name,
|
|
140
|
+
iso2: country.iso2,
|
|
141
|
+
currency: country.currency,
|
|
142
|
+
currency_symbol: country.currency_symbol,
|
|
143
|
+
currency_name: country.currency_name,
|
|
144
|
+
flag: `flag flag-${(_a = country.iso2) === null || _a === void 0 ? void 0 : _a.toLowerCase()}`
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
return undefined;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
export default new CountriesData();
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
* const country = CountriesAtlas.find('US');
|
|
14
14
|
*/
|
|
15
15
|
export { default as CountriesAtlas } from './helpers/CountriesAtlas';
|
|
16
|
+
export { default as CountriesData, CountriesData as CountriesDataClass } from './helpers/CountriesData';
|
|
16
17
|
export { default as ValidatorAtlas } from './helpers/ValidatorAtlas';
|
|
17
18
|
export type { Country } from './types/country.interface';
|
|
18
19
|
export type { State } from './types/state.interface';
|
package/dist/esm/index.js
CHANGED
|
@@ -13,4 +13,8 @@
|
|
|
13
13
|
* const country = CountriesAtlas.find('US');
|
|
14
14
|
*/
|
|
15
15
|
export { default as CountriesAtlas } from './helpers/CountriesAtlas';
|
|
16
|
+
// Lightweight country-list helper (no per-country state/city dataset). Prefer
|
|
17
|
+
// importing this — or the `@touchestate/geo-atlas/lite` entry — on paths that
|
|
18
|
+
// only need the country list, to avoid bundling the ~171 MB per-country data.
|
|
19
|
+
export { default as CountriesData, CountriesData as CountriesDataClass } from './helpers/CountriesData';
|
|
16
20
|
export { default as ValidatorAtlas } from './helpers/ValidatorAtlas';
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @packageDocumentation
|
|
3
|
+
* @module touchestate/geo-atlas/lite
|
|
4
|
+
*
|
|
5
|
+
* @description Lightweight entry point exposing only the country list and its
|
|
6
|
+
* metadata (names, translations, phone codes, currencies, timezones). Importing
|
|
7
|
+
* from here loads just the small bundled `atlas.json` — it never references the
|
|
8
|
+
* per-country state/city dataset (~171 MB), so it is safe to use on
|
|
9
|
+
* server-rendered / memory-constrained bundling paths.
|
|
10
|
+
*
|
|
11
|
+
* For states/cities, import from `@touchestate/geo-atlas/cities` (loaded on
|
|
12
|
+
* demand, browser/client side) or use the full `CountriesAtlas` from the root
|
|
13
|
+
* entry point.
|
|
14
|
+
*
|
|
15
|
+
* @license MIT
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* import CountriesData from '@touchestate/geo-atlas/lite';
|
|
19
|
+
* const countries = CountriesData.getCountries();
|
|
20
|
+
* const country = CountriesData.find('US');
|
|
21
|
+
*/
|
|
22
|
+
export { CountriesData, default } from './helpers/CountriesData';
|
|
23
|
+
export type { Country } from './types/country.interface';
|
|
24
|
+
export type { Timezone } from './types/timezone.type';
|
|
25
|
+
export type { Translations } from './types/translation.type';
|
|
26
|
+
export type { Currency } from './types/currency.type';
|
|
27
|
+
export type { PhoneCode } from './types/phone-code.interface';
|
package/dist/esm/lite.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @packageDocumentation
|
|
3
|
+
* @module touchestate/geo-atlas/lite
|
|
4
|
+
*
|
|
5
|
+
* @description Lightweight entry point exposing only the country list and its
|
|
6
|
+
* metadata (names, translations, phone codes, currencies, timezones). Importing
|
|
7
|
+
* from here loads just the small bundled `atlas.json` — it never references the
|
|
8
|
+
* per-country state/city dataset (~171 MB), so it is safe to use on
|
|
9
|
+
* server-rendered / memory-constrained bundling paths.
|
|
10
|
+
*
|
|
11
|
+
* For states/cities, import from `@touchestate/geo-atlas/cities` (loaded on
|
|
12
|
+
* demand, browser/client side) or use the full `CountriesAtlas` from the root
|
|
13
|
+
* entry point.
|
|
14
|
+
*
|
|
15
|
+
* @license MIT
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* import CountriesData from '@touchestate/geo-atlas/lite';
|
|
19
|
+
* const countries = CountriesData.getCountries();
|
|
20
|
+
* const country = CountriesData.find('US');
|
|
21
|
+
*/
|
|
22
|
+
export { CountriesData, default } from './helpers/CountriesData';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@innovayse/geo-atlas",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"description": "Offline countries, states and cities with multilingual support (EN/RU/HY + 15 languages).",
|
|
5
5
|
"main": "dist/cjs/index.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -11,6 +11,16 @@
|
|
|
11
11
|
"require": "./dist/cjs/index.js",
|
|
12
12
|
"types": "./dist/cjs/index.d.ts"
|
|
13
13
|
},
|
|
14
|
+
"./lite": {
|
|
15
|
+
"import": "./dist/esm/lite.js",
|
|
16
|
+
"require": "./dist/cjs/lite.js",
|
|
17
|
+
"types": "./dist/cjs/lite.d.ts"
|
|
18
|
+
},
|
|
19
|
+
"./cities": {
|
|
20
|
+
"import": "./dist/esm/cities.js",
|
|
21
|
+
"require": "./dist/cjs/cities.js",
|
|
22
|
+
"types": "./dist/cjs/cities.d.ts"
|
|
23
|
+
},
|
|
14
24
|
"./country": {
|
|
15
25
|
"import": "./dist/esm/types/country.interface.js",
|
|
16
26
|
"require": "./dist/cjs/types/country.interface.js",
|
|
@@ -49,6 +59,8 @@
|
|
|
49
59
|
},
|
|
50
60
|
"typesVersions": {
|
|
51
61
|
"*": {
|
|
62
|
+
"lite": ["./dist/cjs/lite.d.ts"],
|
|
63
|
+
"cities": ["./dist/cjs/cities.d.ts"],
|
|
52
64
|
"country": ["./dist/cjs/types/country.interface.d.ts"],
|
|
53
65
|
"state": ["./dist/cjs/types/state.interface.d.ts"],
|
|
54
66
|
"city": ["./dist/cjs/types/city.type.d.ts"],
|