react-country-kit-core 1.2.0 → 2.0.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.
@@ -0,0 +1,233 @@
1
+ export interface IPhoneFormat {
2
+ iso2: string;
3
+ dialCode: string;
4
+ patterns: string;
5
+ possibleLengths: string;
6
+ example: string | number;
7
+ countryCode: string;
8
+ }
9
+ export interface ICurrency {
10
+ code: string;
11
+ name: string;
12
+ symbol: string;
13
+ countryCode: string;
14
+ precision: number;
15
+ }
16
+ export interface ITimezone {
17
+ name: string;
18
+ offset: number;
19
+ offset_name: string;
20
+ abbreviation: string;
21
+ tzName: string;
22
+ countryCode: string;
23
+ }
24
+ export interface IDivision {
25
+ name: string;
26
+ iso2: string;
27
+ timezone: string;
28
+ countryCode: string;
29
+ }
30
+ export interface ICountry {
31
+ name: string;
32
+ iso2: string;
33
+ iso3: string;
34
+ phone_code: string;
35
+ division_type: string;
36
+ /** Emoji flag computed from iso2 */
37
+ flag: string;
38
+ /** SVG/Image URL for the country flag */
39
+ flag_url: string;
40
+ /** Default language code for the country */
41
+ language_code: string;
42
+ /** Default currency code for the country */
43
+ currency_code: string;
44
+ /** Label for tax identification number (e.g. "VAT", "SSN", "ABN") */
45
+ tax_id_label: string;
46
+ /** Placeholder for tax identification number */
47
+ tax_id_placeholder: string;
48
+ /** Label for postal/zip code (e.g. "ZIP Code", "Postcode", "PIN Code") */
49
+ postal_code_label: string;
50
+ }
51
+ export interface ILanguage {
52
+ code: string;
53
+ english_name: string;
54
+ native_name: string;
55
+ }
56
+ export interface ICountryPickerProps {
57
+ /** Currently selected country */
58
+ value?: ICountry | null;
59
+ /** Callback when user selects a country */
60
+ onChange: (country: ICountry) => void;
61
+ placeholder?: string;
62
+ /** Enable search input */
63
+ searchable?: boolean;
64
+ /** Show emoji flag next to country name */
65
+ showFlag?: boolean;
66
+ /** Show phone dial code */
67
+ showPhoneCode?: boolean;
68
+ /** Disable the picker */
69
+ disabled?: boolean;
70
+ /** Additional wrapper class */
71
+ className?: string;
72
+ /** aria-label */
73
+ label?: string;
74
+ }
75
+ export interface ICurrencyPickerProps {
76
+ value?: ICurrency | null;
77
+ onChange: (currency: ICurrency) => void;
78
+ placeholder?: string;
79
+ searchable?: boolean;
80
+ /** Filter currencies to a specific country (iso2) and enable auto-selection */
81
+ countryIso2?: string;
82
+ /** Auto-select the first currency if countryIso2 is provided. Defaults to true if countryIso2 is present and value is empty. */
83
+ autoSelect?: boolean;
84
+ /** Show currency symbol alongside code */
85
+ showSymbol?: boolean;
86
+ disabled?: boolean;
87
+ className?: string;
88
+ label?: string;
89
+ }
90
+ export interface ITimezonePickerProps {
91
+ value?: ITimezone | null;
92
+ onChange: (timezone: ITimezone) => void;
93
+ placeholder?: string;
94
+ searchable?: boolean;
95
+ /** Filter timezones to a specific country (iso2) and enable auto-selection */
96
+ countryIso2?: string;
97
+ /** Auto-select the first timezone if countryIso2 is provided. Defaults to true if countryIso2 is present and value is empty. */
98
+ autoSelect?: boolean;
99
+ disabled?: boolean;
100
+ className?: string;
101
+ label?: string;
102
+ }
103
+ export interface ILanguagePickerProps {
104
+ value?: ILanguage | null;
105
+ onChange: (language: ILanguage) => void;
106
+ placeholder?: string;
107
+ searchable?: boolean;
108
+ /** Show native language name alongside english name */
109
+ showNativeName?: boolean;
110
+ disabled?: boolean;
111
+ className?: string;
112
+ label?: string;
113
+ }
114
+ export interface IDivisionPickerProps {
115
+ /** ISO2 code of the parent country (required) */
116
+ countryIso2: string;
117
+ value?: IDivision | null;
118
+ onChange: (division: IDivision) => void;
119
+ placeholder?: string;
120
+ searchable?: boolean;
121
+ disabled?: boolean;
122
+ className?: string;
123
+ label?: string;
124
+ }
125
+ export interface IUsePickerReturn<T> {
126
+ isOpen: boolean;
127
+ searchQuery: string;
128
+ filteredItems: T[];
129
+ selectedItem: T | null;
130
+ open: () => void;
131
+ close: () => void;
132
+ toggle: () => void;
133
+ setSearchQuery: (query: string) => void;
134
+ selectItem: (item: T) => void;
135
+ clearSelection: () => void;
136
+ }
137
+ /**
138
+ * Phone number validation rules and metadata for a country
139
+ */
140
+ export interface IPhoneValidation {
141
+ /** Min phone number length (without dial code) */
142
+ minLength?: number;
143
+ /** Max phone number length (without dial code) */
144
+ maxLength?: number;
145
+ /** Regex pattern for validation */
146
+ pattern?: string;
147
+ /** Example phone number without dial code */
148
+ example?: string;
149
+ /** Placeholder text for the phone input */
150
+ placeholder?: string;
151
+ }
152
+ /**
153
+ * Value object returned by PhoneInput.
154
+ */
155
+ export interface IPhoneValue {
156
+ /** Full Country object of the selected country */
157
+ country: ICountry;
158
+ /** Dial code with + prefix, e.g. "+1" */
159
+ dialCode: string;
160
+ /** Raw phone number without dial code, e.g. "4155551234" */
161
+ number: string;
162
+ /** Full number with dial code, e.g. "+14155551234" */
163
+ full: string;
164
+ /** Validation rules and metadata for the phone number */
165
+ validation?: IPhoneValidation;
166
+ }
167
+ export interface IPhoneInputProps {
168
+ value?: IPhoneValue | null;
169
+ onChange: (value: IPhoneValue) => void;
170
+ /** Pre-select a country by ISO2 on first render */
171
+ defaultCountryIso2?: string;
172
+ placeholder?: string;
173
+ showFlag?: boolean;
174
+ disabled?: boolean;
175
+ className?: string;
176
+ label?: string;
177
+ }
178
+ export interface ICountryMultiSelectProps {
179
+ value: ICountry[];
180
+ onChange: (countries: ICountry[]) => void;
181
+ placeholder?: string;
182
+ /** Maximum number of selections (undefined = unlimited) */
183
+ maxItems?: number;
184
+ showFlags?: boolean;
185
+ searchable?: boolean;
186
+ disabled?: boolean;
187
+ className?: string;
188
+ label?: string;
189
+ }
190
+ export interface ICurrencyMultiSelectProps {
191
+ value: ICurrency[];
192
+ onChange: (currencies: ICurrency[]) => void;
193
+ placeholder?: string;
194
+ maxItems?: number;
195
+ showSymbol?: boolean;
196
+ searchable?: boolean;
197
+ disabled?: boolean;
198
+ className?: string;
199
+ label?: string;
200
+ }
201
+ export interface IUseMultiSelectReturn<T> {
202
+ isOpen: boolean;
203
+ searchQuery: string;
204
+ filteredItems: T[];
205
+ selectedItems: T[];
206
+ open: () => void;
207
+ close: () => void;
208
+ toggle: () => void;
209
+ setSearchQuery: (query: string) => void;
210
+ toggleItem: (item: T) => void;
211
+ isSelected: (item: T) => boolean;
212
+ removeItem: (item: T) => void;
213
+ clearAll: () => void;
214
+ }
215
+ export interface IUseCountryReturn {
216
+ country: ICountry | null;
217
+ divisions: IDivision[];
218
+ timezones: ITimezone[];
219
+ currency: ICurrency | null;
220
+ phoneFormat: IPhoneFormat | null;
221
+ phoneLengths: {
222
+ min?: number;
223
+ max?: number;
224
+ };
225
+ exampleNumber?: string;
226
+ tax: {
227
+ label: string;
228
+ placeholder: string;
229
+ };
230
+ postalCode: {
231
+ label: string;
232
+ };
233
+ }
@@ -0,0 +1,62 @@
1
+ import { iso2ToFlag as _iso2ToFlag } from '../data/countries';
2
+ import { ICountry, ICurrency, IDivision, IPhoneFormat, ITimezone } from '../types';
3
+ /**
4
+ * Convert ISO2 code to emoji flag
5
+ * Re-exported from the generated data module.
6
+ */
7
+ export { _iso2ToFlag as iso2ToFlag };
8
+ /**
9
+ * Returns all countries
10
+ */
11
+ export declare function getAllCountries(): ICountry[];
12
+ /**
13
+ * Find a country by its ISO2 code (case-insensitive)
14
+ */
15
+ export declare function getCountryByIso2(iso2: string): ICountry | undefined;
16
+ /**
17
+ * Find a country by its ISO3 code (case-insensitive)
18
+ */
19
+ export declare function getCountryByIso3(iso3: string): ICountry | undefined;
20
+ /**
21
+ * Find a country by its name (partial, case-insensitive)
22
+ */
23
+ export declare function getCountryByName(name: string): ICountry | undefined;
24
+ /**
25
+ * Search countries by name, iso2, iso3 or phone code
26
+ */
27
+ export declare function searchCountries(query: string): ICountry[];
28
+ /**
29
+ * Get all divisions for a country
30
+ */
31
+ export declare function getDivisionsByCountry(iso2: string): IDivision[];
32
+ /**
33
+ * Get all timezones for a country
34
+ */
35
+ export declare function getTimezonesByCountry(iso2: string): ITimezone[];
36
+ /**
37
+ * Get the currency for a country
38
+ */
39
+ export declare function getCurrencyByCountry(iso2: string): ICurrency | undefined;
40
+ /**
41
+ * Get the phone format for a country
42
+ */
43
+ export declare function getPhoneFormatByCountry(iso2: string): IPhoneFormat | undefined;
44
+ /**
45
+ * Get the min and max phone number lengths for a country
46
+ */
47
+ export declare function getPhoneLengths(iso2: string): {
48
+ min?: number;
49
+ max?: number;
50
+ };
51
+ /**
52
+ * Get the localized Tax ID label for a country
53
+ */
54
+ export declare function getTaxLabelByCountry(iso2: string): string;
55
+ /**
56
+ * Get the localized Tax ID placeholder for a country
57
+ */
58
+ export declare function getTaxPlaceholderByCountry(iso2: string): string;
59
+ /**
60
+ * Get the localized Postal Code label for a country
61
+ */
62
+ export declare function getPostalLabelByCountry(iso2: string): string;
@@ -0,0 +1,13 @@
1
+ import { ICurrency } from '../types';
2
+ /**
3
+ * Returns all unique currencies across all countries
4
+ */
5
+ export declare function getAllCurrencies(): ICurrency[];
6
+ /**
7
+ * Find a currency by its code (e.g. "USD")
8
+ */
9
+ export declare function getCurrencyByCode(code: string): ICurrency | undefined;
10
+ /**
11
+ * Search currencies by code, name, or symbol
12
+ */
13
+ export declare function searchCurrencies(query: string, countryIso2?: string): ICurrency[];
@@ -0,0 +1,13 @@
1
+ import { ILanguage } from '../types';
2
+ /**
3
+ * Returns all languages
4
+ */
5
+ export declare function getAllLanguages(): ILanguage[];
6
+ /**
7
+ * Find a language by its BCP-47 code
8
+ */
9
+ export declare function getLanguageByCode(code: string): ILanguage | undefined;
10
+ /**
11
+ * Search languages by english name, native name, or code
12
+ */
13
+ export declare function searchLanguages(query: string): ILanguage[];
@@ -0,0 +1,21 @@
1
+ import { IPhoneValidation } from '../types';
2
+ /**
3
+ * Get phone number validation rules for a country
4
+ * Combines libphonenumber-js data with custom formatting rules
5
+ */
6
+ export declare function getPhoneValidation(countryIso2: string): IPhoneValidation;
7
+ /**
8
+ * Format phone example as a user-friendly placeholder
9
+ */
10
+ export declare function formatPhoneExample(example: string, countryIso2: string): string;
11
+ /**
12
+ * Validate phone number against country-specific rules
13
+ */
14
+ export declare function validatePhoneNumber(dialCode: string, number: string, countryIso2: string): {
15
+ isValid: boolean;
16
+ errors: string[];
17
+ };
18
+ /**
19
+ * Format phone number for display based on country conventions
20
+ */
21
+ export declare function formatPhoneNumber(number: string, countryIso2: string): string;
@@ -0,0 +1,14 @@
1
+ import { ITimezone } from '../types';
2
+ /**
3
+ * Returns all unique timezones across all countries
4
+ */
5
+ export declare function getAllTimezones(): ITimezone[];
6
+ /**
7
+ * Find a timezone by its IANA name (e.g. "America/New_York")
8
+ * Supports modern names and common deprecated aliases.
9
+ */
10
+ export declare function getTimezoneByName(name: string): ITimezone | undefined;
11
+ /**
12
+ * Search timezones by name, abbreviation, or offset string
13
+ */
14
+ export declare function searchTimezones(query: string, countryIso2?: string): ITimezone[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-country-kit-core",
3
- "version": "1.2.0",
3
+ "version": "2.0.0",
4
4
  "type": "module",
5
5
  "description": "Core datasets, utilities, and hooks for react-country-kit. Comprehensive data for countries, currencies, timezones, languages, and divisions.",
6
6
  "author": "Kishor Mainali",
@@ -20,9 +20,9 @@
20
20
  "types": "dist/index.d.ts",
21
21
  "exports": {
22
22
  ".": {
23
+ "types": "./dist/index.d.ts",
23
24
  "import": "./dist/index.mjs",
24
- "require": "./dist/index.js",
25
- "types": "./dist/index.d.ts"
25
+ "require": "./dist/index.js"
26
26
  }
27
27
  },
28
28
  "files": [