@tagadapay/plugin-sdk 2.1.3 → 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/dist/data/iso3166.d.ts +10 -8
- package/dist/data/iso3166.js +79 -16
- package/dist/react/hooks/useISOData.d.ts +7 -6
- package/dist/react/hooks/useISOData.js +22 -61
- package/package.json +1 -1
package/dist/data/iso3166.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
export declare const AVAILABLE_LANGUAGES: readonly ["en", "ru", "de", "fr", "es", "zh", "hi", "pt", "ja", "ar", "it", "he"];
|
|
2
|
+
export type SupportedLanguage = typeof AVAILABLE_LANGUAGES[number];
|
|
1
3
|
export interface Country {
|
|
2
4
|
code: string;
|
|
3
5
|
name: string;
|
|
@@ -11,14 +13,14 @@ export interface State {
|
|
|
11
13
|
countryCode: string;
|
|
12
14
|
uniqueKey?: string;
|
|
13
15
|
}
|
|
14
|
-
export declare const getCountries: () => Country[];
|
|
15
|
-
export declare const getAllStates: () => State[];
|
|
16
|
-
export declare const getStatesForCountry: (countryCode: string) => State[];
|
|
17
|
-
export declare const findCountryByName: (countryName: string) => Country | null;
|
|
18
|
-
export declare const findRegionByCode: (regionCode: string) => State | null;
|
|
19
|
-
export declare const isValidCountryCode: (countryCode: string) => boolean;
|
|
20
|
-
export declare const isValidStateCode: (countryCode: string, stateCode: string) => boolean;
|
|
21
|
-
export declare const getCountryWithRegions: (countryCode: string) => {
|
|
16
|
+
export declare const getCountries: (language?: SupportedLanguage) => Country[];
|
|
17
|
+
export declare const getAllStates: (language?: SupportedLanguage) => State[];
|
|
18
|
+
export declare const getStatesForCountry: (countryCode: string, language?: SupportedLanguage) => State[];
|
|
19
|
+
export declare const findCountryByName: (countryName: string, language?: SupportedLanguage) => Country | null;
|
|
20
|
+
export declare const findRegionByCode: (regionCode: string, language?: SupportedLanguage) => State | null;
|
|
21
|
+
export declare const isValidCountryCode: (countryCode: string, language?: SupportedLanguage) => boolean;
|
|
22
|
+
export declare const isValidStateCode: (countryCode: string, stateCode: string, language?: SupportedLanguage) => boolean;
|
|
23
|
+
export declare const getCountryWithRegions: (countryCode: string, language?: SupportedLanguage) => {
|
|
22
24
|
country: {
|
|
23
25
|
code: any;
|
|
24
26
|
name: any;
|
package/dist/data/iso3166.js
CHANGED
|
@@ -1,11 +1,70 @@
|
|
|
1
|
-
// Import
|
|
1
|
+
// Import static language databases for better browser compatibility
|
|
2
|
+
// All supported languages from iso3166-2-db package
|
|
2
3
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
3
4
|
// @ts-ignore - iso3166-2-db doesn't have TypeScript definitions
|
|
4
|
-
import
|
|
5
|
-
//
|
|
6
|
-
|
|
5
|
+
import enDatabase from 'iso3166-2-db/i18n/dispute/UN/en';
|
|
6
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
7
|
+
// @ts-ignore - iso3166-2-db doesn't have TypeScript definitions
|
|
8
|
+
import ruDatabase from 'iso3166-2-db/i18n/dispute/UN/ru';
|
|
9
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
10
|
+
// @ts-ignore - iso3166-2-db doesn't have TypeScript definitions
|
|
11
|
+
import deDatabase from 'iso3166-2-db/i18n/dispute/UN/de';
|
|
12
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
13
|
+
// @ts-ignore - iso3166-2-db doesn't have TypeScript definitions
|
|
14
|
+
import frDatabase from 'iso3166-2-db/i18n/dispute/UN/fr';
|
|
15
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
16
|
+
// @ts-ignore - iso3166-2-db doesn't have TypeScript definitions
|
|
17
|
+
import esDatabase from 'iso3166-2-db/i18n/dispute/UN/es';
|
|
18
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
19
|
+
// @ts-ignore - iso3166-2-db doesn't have TypeScript definitions
|
|
20
|
+
import zhDatabase from 'iso3166-2-db/i18n/dispute/UN/zh';
|
|
21
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
22
|
+
// @ts-ignore - iso3166-2-db doesn't have TypeScript definitions
|
|
23
|
+
import hiDatabase from 'iso3166-2-db/i18n/dispute/UN/hi';
|
|
24
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
25
|
+
// @ts-ignore - iso3166-2-db doesn't have TypeScript definitions
|
|
26
|
+
import ptDatabase from 'iso3166-2-db/i18n/dispute/UN/pt';
|
|
27
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
28
|
+
// @ts-ignore - iso3166-2-db doesn't have TypeScript definitions
|
|
29
|
+
import jaDatabase from 'iso3166-2-db/i18n/dispute/UN/ja';
|
|
30
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
31
|
+
// @ts-ignore - iso3166-2-db doesn't have TypeScript definitions
|
|
32
|
+
import arDatabase from 'iso3166-2-db/i18n/dispute/UN/ar';
|
|
33
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
34
|
+
// @ts-ignore - iso3166-2-db doesn't have TypeScript definitions
|
|
35
|
+
import itDatabase from 'iso3166-2-db/i18n/dispute/UN/it';
|
|
36
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
37
|
+
// @ts-ignore - iso3166-2-db doesn't have TypeScript definitions
|
|
38
|
+
import heDatabase from 'iso3166-2-db/i18n/dispute/UN/he';
|
|
39
|
+
// All available languages from iso3166-2-db package
|
|
40
|
+
export const AVAILABLE_LANGUAGES = ['en', 'ru', 'de', 'fr', 'es', 'zh', 'hi', 'pt', 'ja', 'ar', 'it', 'he'];
|
|
41
|
+
// Static language database mapping for all supported languages
|
|
42
|
+
const languageDatabases = {
|
|
43
|
+
en: enDatabase, // English
|
|
44
|
+
ru: ruDatabase, // Russian
|
|
45
|
+
de: deDatabase, // German
|
|
46
|
+
fr: frDatabase, // French
|
|
47
|
+
es: esDatabase, // Spanish
|
|
48
|
+
zh: zhDatabase, // Chinese
|
|
49
|
+
hi: hiDatabase, // Hindi
|
|
50
|
+
pt: ptDatabase, // Portuguese
|
|
51
|
+
ja: jaDatabase, // Japanese
|
|
52
|
+
ar: arDatabase, // Arabic
|
|
53
|
+
it: itDatabase, // Italian
|
|
54
|
+
he: heDatabase, // Hebrew
|
|
55
|
+
};
|
|
56
|
+
// Function to get language-specific database
|
|
57
|
+
function getWorldDatabase(language = 'en') {
|
|
58
|
+
const database = languageDatabases[language];
|
|
59
|
+
if (!database) {
|
|
60
|
+
console.warn(`Language ${language} not available, falling back to English`);
|
|
61
|
+
return languageDatabases.en;
|
|
62
|
+
}
|
|
63
|
+
return database;
|
|
64
|
+
}
|
|
7
65
|
// Transform the ISO3166 data into our expected format
|
|
8
|
-
export const getCountries = () => {
|
|
66
|
+
export const getCountries = (language = 'en') => {
|
|
67
|
+
const worldDatabase = getWorldDatabase(language);
|
|
9
68
|
const countries = [];
|
|
10
69
|
Object.keys(worldDatabase).forEach((countryCode) => {
|
|
11
70
|
const countryData = worldDatabase[countryCode];
|
|
@@ -21,7 +80,8 @@ export const getCountries = () => {
|
|
|
21
80
|
return countries.sort((a, b) => a.name.localeCompare(b.name));
|
|
22
81
|
};
|
|
23
82
|
// Get all states/regions for all countries
|
|
24
|
-
export const getAllStates = () => {
|
|
83
|
+
export const getAllStates = (language = 'en') => {
|
|
84
|
+
const worldDatabase = getWorldDatabase(language);
|
|
25
85
|
const states = [];
|
|
26
86
|
Object.keys(worldDatabase).forEach((countryCode) => {
|
|
27
87
|
const countryData = worldDatabase[countryCode];
|
|
@@ -40,7 +100,8 @@ export const getAllStates = () => {
|
|
|
40
100
|
return states.sort((a, b) => a.name.localeCompare(b.name));
|
|
41
101
|
};
|
|
42
102
|
// Get states for a specific country
|
|
43
|
-
export const getStatesForCountry = (countryCode) => {
|
|
103
|
+
export const getStatesForCountry = (countryCode, language = 'en') => {
|
|
104
|
+
const worldDatabase = getWorldDatabase(language);
|
|
44
105
|
const countryData = worldDatabase[countryCode];
|
|
45
106
|
if (!countryData?.regions || !Array.isArray(countryData.regions)) {
|
|
46
107
|
return [];
|
|
@@ -55,8 +116,8 @@ export const getStatesForCountry = (countryCode) => {
|
|
|
55
116
|
.sort((a, b) => a.name.localeCompare(b.name));
|
|
56
117
|
};
|
|
57
118
|
// Find country by name (fuzzy search)
|
|
58
|
-
export const findCountryByName = (countryName) => {
|
|
59
|
-
const countries = getCountries();
|
|
119
|
+
export const findCountryByName = (countryName, language = 'en') => {
|
|
120
|
+
const countries = getCountries(language);
|
|
60
121
|
const normalizedSearchName = countryName.toLowerCase().trim();
|
|
61
122
|
// Exact match first
|
|
62
123
|
const exactMatch = countries.find((country) => country.name.toLowerCase() === normalizedSearchName);
|
|
@@ -68,24 +129,26 @@ export const findCountryByName = (countryName) => {
|
|
|
68
129
|
return partialMatch ?? null;
|
|
69
130
|
};
|
|
70
131
|
// Find region by ISO code (e.g., "US-CA" for California)
|
|
71
|
-
export const findRegionByCode = (regionCode) => {
|
|
132
|
+
export const findRegionByCode = (regionCode, language = 'en') => {
|
|
72
133
|
const [countryCode, stateCode] = regionCode.split('-');
|
|
73
134
|
if (!countryCode || !stateCode)
|
|
74
135
|
return null;
|
|
75
|
-
const states = getStatesForCountry(countryCode);
|
|
136
|
+
const states = getStatesForCountry(countryCode, language);
|
|
76
137
|
return states.find((state) => state.code === stateCode) ?? null;
|
|
77
138
|
};
|
|
78
139
|
// Validate if a country code exists
|
|
79
|
-
export const isValidCountryCode = (countryCode) => {
|
|
140
|
+
export const isValidCountryCode = (countryCode, language = 'en') => {
|
|
141
|
+
const worldDatabase = getWorldDatabase(language);
|
|
80
142
|
return Object.prototype.hasOwnProperty.call(worldDatabase, countryCode);
|
|
81
143
|
};
|
|
82
144
|
// Validate if a state code exists for a given country
|
|
83
|
-
export const isValidStateCode = (countryCode, stateCode) => {
|
|
84
|
-
const states = getStatesForCountry(countryCode);
|
|
145
|
+
export const isValidStateCode = (countryCode, stateCode, language = 'en') => {
|
|
146
|
+
const states = getStatesForCountry(countryCode, language);
|
|
85
147
|
return states.some((state) => state.code === stateCode);
|
|
86
148
|
};
|
|
87
149
|
// Get country info including regions
|
|
88
|
-
export const getCountryWithRegions = (countryCode) => {
|
|
150
|
+
export const getCountryWithRegions = (countryCode, language = 'en') => {
|
|
151
|
+
const worldDatabase = getWorldDatabase(language);
|
|
89
152
|
const countryData = worldDatabase[countryCode];
|
|
90
153
|
if (!countryData)
|
|
91
154
|
return null;
|
|
@@ -97,6 +160,6 @@ export const getCountryWithRegions = (countryCode) => {
|
|
|
97
160
|
numeric: countryData.numeric,
|
|
98
161
|
uniqueKey: `country-${countryData.iso}`,
|
|
99
162
|
},
|
|
100
|
-
regions: getStatesForCountry(countryCode),
|
|
163
|
+
regions: getStatesForCountry(countryCode, language),
|
|
101
164
|
};
|
|
102
165
|
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type SupportedLanguage } from '../../data/iso3166';
|
|
1
2
|
export interface ISOCountry {
|
|
2
3
|
iso: string;
|
|
3
4
|
iso3: string;
|
|
@@ -16,26 +17,26 @@ export interface UseISODataResult {
|
|
|
16
17
|
}
|
|
17
18
|
/**
|
|
18
19
|
* React hook for accessing ISO3166 countries and regions data
|
|
19
|
-
* @param language - Language code (en,
|
|
20
|
-
* @param disputeSetting - Territorial dispute perspective (UN
|
|
20
|
+
* @param language - Language code (supports: en, ru, de, fr, es, zh, hi, pt, ja, ar, it, he)
|
|
21
|
+
* @param disputeSetting - Territorial dispute perspective (currently only UN is supported)
|
|
21
22
|
* @returns Object with countries data and helper functions
|
|
22
23
|
*/
|
|
23
|
-
export declare function useISOData(language?:
|
|
24
|
+
export declare function useISOData(language?: SupportedLanguage, disputeSetting?: string): UseISODataResult;
|
|
24
25
|
/**
|
|
25
26
|
* Get available languages for ISO data
|
|
26
27
|
*/
|
|
27
|
-
export declare function getAvailableLanguages():
|
|
28
|
+
export declare function getAvailableLanguages(): SupportedLanguage[];
|
|
28
29
|
/**
|
|
29
30
|
* Get list of countries as options for select components
|
|
30
31
|
*/
|
|
31
|
-
export declare function useCountryOptions(language?:
|
|
32
|
+
export declare function useCountryOptions(language?: SupportedLanguage): {
|
|
32
33
|
value: string;
|
|
33
34
|
label: string;
|
|
34
35
|
}[];
|
|
35
36
|
/**
|
|
36
37
|
* Get list of regions/states for a country as options for select components
|
|
37
38
|
*/
|
|
38
|
-
export declare function useRegionOptions(countryCode: string, language?:
|
|
39
|
+
export declare function useRegionOptions(countryCode: string, language?: SupportedLanguage): {
|
|
39
40
|
value: string;
|
|
40
41
|
label: string;
|
|
41
42
|
}[];
|
|
@@ -1,75 +1,35 @@
|
|
|
1
|
-
import { useMemo
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
// Import the pre-built ISO data functions
|
|
3
|
+
import { getCountries, getStatesForCountry } from '../../data/iso3166';
|
|
2
4
|
/**
|
|
3
5
|
* React hook for accessing ISO3166 countries and regions data
|
|
4
|
-
* @param language - Language code (en,
|
|
5
|
-
* @param disputeSetting - Territorial dispute perspective (UN
|
|
6
|
+
* @param language - Language code (supports: en, ru, de, fr, es, zh, hi, pt, ja, ar, it, he)
|
|
7
|
+
* @param disputeSetting - Territorial dispute perspective (currently only UN is supported)
|
|
6
8
|
* @returns Object with countries data and helper functions
|
|
7
9
|
*/
|
|
8
10
|
export function useISOData(language = 'en', disputeSetting = 'UN') {
|
|
9
|
-
const [isoModule, setIsoModule] = useState(null);
|
|
10
|
-
const [isLoading, setIsLoading] = useState(true);
|
|
11
|
-
useEffect(() => {
|
|
12
|
-
let isMounted = true;
|
|
13
|
-
const loadModule = async () => {
|
|
14
|
-
try {
|
|
15
|
-
// Try dynamic import first (ES modules)
|
|
16
|
-
const isoModule = await import('iso3166-2-db');
|
|
17
|
-
if (isMounted) {
|
|
18
|
-
setIsoModule(isoModule);
|
|
19
|
-
setIsLoading(false);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
catch (importError) {
|
|
23
|
-
console.error(`Failed to load ISO data module:`, importError);
|
|
24
|
-
if (isMounted) {
|
|
25
|
-
setIsoModule(null);
|
|
26
|
-
setIsLoading(false);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
|
-
void loadModule();
|
|
31
|
-
return () => {
|
|
32
|
-
isMounted = false;
|
|
33
|
-
};
|
|
34
|
-
}, []);
|
|
35
11
|
const data = useMemo(() => {
|
|
36
|
-
if (isLoading || !isoModule) {
|
|
37
|
-
return {
|
|
38
|
-
countries: {},
|
|
39
|
-
getRegions: () => [],
|
|
40
|
-
findRegion: () => null,
|
|
41
|
-
mapGoogleToISO: () => null,
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
12
|
try {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
// Transform to our expected format
|
|
13
|
+
// Get countries from pre-built data with language support (now synchronous)
|
|
14
|
+
const countriesArray = getCountries(language);
|
|
15
|
+
// Transform to our expected format (Record<string, ISOCountry>)
|
|
49
16
|
const countries = {};
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
name: countryData.name,
|
|
17
|
+
countriesArray.forEach((country) => {
|
|
18
|
+
countries[country.code] = {
|
|
19
|
+
iso: country.code,
|
|
20
|
+
iso3: country.iso3 || '',
|
|
21
|
+
numeric: country.numeric || 0,
|
|
22
|
+
name: country.name,
|
|
57
23
|
};
|
|
58
24
|
});
|
|
59
25
|
// Helper to load regions for a specific country
|
|
60
26
|
const getRegions = (countryCode) => {
|
|
61
27
|
try {
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
const regionData = countryData.regions[regionCode];
|
|
68
|
-
return {
|
|
69
|
-
iso: regionData.iso,
|
|
70
|
-
name: regionData.name,
|
|
71
|
-
};
|
|
72
|
-
});
|
|
28
|
+
const states = getStatesForCountry(countryCode, language);
|
|
29
|
+
return states.map((state) => ({
|
|
30
|
+
iso: state.code,
|
|
31
|
+
name: state.name,
|
|
32
|
+
}));
|
|
73
33
|
}
|
|
74
34
|
catch {
|
|
75
35
|
return []; // Return empty array if no regions
|
|
@@ -117,14 +77,15 @@ export function useISOData(language = 'en', disputeSetting = 'UN') {
|
|
|
117
77
|
mapGoogleToISO: () => null,
|
|
118
78
|
};
|
|
119
79
|
}
|
|
120
|
-
}, [
|
|
80
|
+
}, [language, disputeSetting]);
|
|
121
81
|
return data;
|
|
122
82
|
}
|
|
123
83
|
/**
|
|
124
84
|
* Get available languages for ISO data
|
|
125
85
|
*/
|
|
126
86
|
export function getAvailableLanguages() {
|
|
127
|
-
|
|
87
|
+
// Return all statically imported languages for browser compatibility
|
|
88
|
+
return ['en', 'ru', 'de', 'fr', 'es', 'zh', 'hi', 'pt', 'ja', 'ar', 'it', 'he'];
|
|
128
89
|
}
|
|
129
90
|
/**
|
|
130
91
|
* Get list of countries as options for select components
|