react-country-kit-core 1.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Kishor Mainali
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,20 @@
1
+ # @react-country-kit/core
2
+
3
+ Core datasets, utilities, and hooks for `react-country-kit`.
4
+
5
+ ## Features
6
+
7
+ - **Comprehensive Data**: Full datasets for countries, currencies, timezones, languages, and divisions.
8
+ - **Relational Integrity**: Unified `countryCode` links across all datasets.
9
+ - **Phone Formatting**: Powered by `libphonenumber-js` with localized formatting rules.
10
+ - **Performance Optimized**: Optimized React hooks for smooth picker implementations.
11
+
12
+ ## Installation
13
+
14
+ ```bash
15
+ npm install @react-country-kit/core
16
+ ```
17
+
18
+ ## License
19
+
20
+ MIT
@@ -0,0 +1,371 @@
1
+ export declare const COUNTRIES: Country[];
2
+
3
+ export declare interface Country {
4
+ name: string;
5
+ iso2: string;
6
+ iso3: string;
7
+ phone_code: string;
8
+ phone_format?: PhoneFormat;
9
+ currency?: Currency;
10
+ division_type: string;
11
+ divisions?: Division[];
12
+ timezones?: Timezone[];
13
+ /** Emoji flag computed from iso2 */
14
+ flag: string;
15
+ /** SVG/Image URL for the country flag */
16
+ flag_url: string;
17
+ /** Default language code for the country */
18
+ language_code: string;
19
+ /** Default currency code for the country */
20
+ currency_code: string;
21
+ }
22
+
23
+ export declare interface CountryMultiSelectProps {
24
+ value: Country[];
25
+ onChange: (countries: Country[]) => void;
26
+ placeholder?: string;
27
+ /** Maximum number of selections (undefined = unlimited) */
28
+ maxItems?: number;
29
+ showFlags?: boolean;
30
+ searchable?: boolean;
31
+ disabled?: boolean;
32
+ className?: string;
33
+ label?: string;
34
+ }
35
+
36
+ export declare interface CountryPickerProps {
37
+ /** Currently selected country */
38
+ value?: Country | null;
39
+ /** Callback when user selects a country */
40
+ onChange: (country: Country) => void;
41
+ placeholder?: string;
42
+ /** Enable search input */
43
+ searchable?: boolean;
44
+ /** Show emoji flag next to country name */
45
+ showFlag?: boolean;
46
+ /** Show phone dial code */
47
+ showPhoneCode?: boolean;
48
+ /** Disable the picker */
49
+ disabled?: boolean;
50
+ /** Additional wrapper class */
51
+ className?: string;
52
+ /** aria-label */
53
+ label?: string;
54
+ }
55
+
56
+ export declare const CURRENCIES: Currency[];
57
+
58
+ export declare interface Currency {
59
+ code: string;
60
+ name: string;
61
+ symbol: string;
62
+ countryCode: string;
63
+ }
64
+
65
+ export declare interface CurrencyMultiSelectProps {
66
+ value: Currency[];
67
+ onChange: (currencies: Currency[]) => void;
68
+ placeholder?: string;
69
+ maxItems?: number;
70
+ showSymbol?: boolean;
71
+ searchable?: boolean;
72
+ disabled?: boolean;
73
+ className?: string;
74
+ label?: string;
75
+ }
76
+
77
+ export declare interface CurrencyPickerProps {
78
+ value?: Currency | null;
79
+ onChange: (currency: Currency) => void;
80
+ placeholder?: string;
81
+ searchable?: boolean;
82
+ /** Filter currencies to a specific country (iso2) and enable auto-selection */
83
+ countryIso2?: string;
84
+ /** Auto-select the first currency if countryIso2 is provided. Defaults to true if countryIso2 is present and value is empty. */
85
+ autoSelect?: boolean;
86
+ /** Show currency symbol alongside code */
87
+ showSymbol?: boolean;
88
+ disabled?: boolean;
89
+ className?: string;
90
+ label?: string;
91
+ }
92
+
93
+ export declare interface Division {
94
+ name: string;
95
+ iso2: string;
96
+ timezone: string;
97
+ countryCode: string;
98
+ }
99
+
100
+ export declare interface DivisionPickerProps {
101
+ /** ISO2 code of the parent country (required) */
102
+ countryIso2: string;
103
+ value?: Division | null;
104
+ onChange: (division: Division) => void;
105
+ placeholder?: string;
106
+ searchable?: boolean;
107
+ disabled?: boolean;
108
+ className?: string;
109
+ label?: string;
110
+ }
111
+
112
+ export declare const DIVISIONS: Division[];
113
+
114
+ /**
115
+ * Returns all countries
116
+ */
117
+ export declare function getAllCountries(): Country[];
118
+
119
+ /**
120
+ * Returns all unique currencies across all countries
121
+ */
122
+ export declare function getAllCurrencies(): Currency[];
123
+
124
+ /**
125
+ * Returns all languages
126
+ */
127
+ export declare function getAllLanguages(): Language[];
128
+
129
+ /**
130
+ * Returns all unique timezones across all countries
131
+ */
132
+ export declare function getAllTimezones(): Timezone[];
133
+
134
+ /**
135
+ * Find a country by its ISO2 code (case-insensitive)
136
+ */
137
+ export declare function getCountryByIso2(iso2: string): Country | undefined;
138
+
139
+ /**
140
+ * Find a country by its ISO3 code (case-insensitive)
141
+ */
142
+ export declare function getCountryByIso3(iso3: string): Country | undefined;
143
+
144
+ /**
145
+ * Find a country by its name (partial, case-insensitive)
146
+ */
147
+ export declare function getCountryByName(name: string): Country | undefined;
148
+
149
+ /**
150
+ * Find a currency by its code (e.g. "USD")
151
+ */
152
+ export declare function getCurrencyByCode(code: string): Currency | undefined;
153
+
154
+ /**
155
+ * Get the currency of a country
156
+ */
157
+ /**
158
+ * Get the currency for a country
159
+ */
160
+ export declare function getCurrencyByCountry(iso2: string): Currency | undefined;
161
+
162
+ /**
163
+ * Get all divisions for a country
164
+ */
165
+ export declare function getDivisionsByCountry(iso2: string): Division[];
166
+
167
+ /**
168
+ * Find a language by its BCP-47 code
169
+ */
170
+ export declare function getLanguageByCode(code: string): Language | undefined;
171
+
172
+ /**
173
+ * Get the phone format for a country
174
+ */
175
+ export declare function getPhoneFormatByCountry(iso2: string): PhoneFormat | undefined;
176
+
177
+ /**
178
+ * Get the min and max phone number lengths for a country
179
+ */
180
+ export declare function getPhoneLengths(iso2: string): {
181
+ min?: number;
182
+ max?: number;
183
+ };
184
+
185
+ /**
186
+ * Find a timezone by its IANA name (e.g. "America/New_York")
187
+ */
188
+ export declare function getTimezoneByName(name: string): Timezone | undefined;
189
+
190
+ /**
191
+ * Get all timezones for a country
192
+ */
193
+ export declare function getTimezonesByCountry(iso2: string): Timezone[];
194
+
195
+ /**
196
+ * Auto-generated country dataset — DO NOT EDIT MANUALLY.
197
+ * Source: https://raw.githubusercontent.com/kishormainali/country_division_database/refs/heads/main/countries.json
198
+ * Generated: 2026-05-15T06:35:47.156Z
199
+ * Countries: 250
200
+ */
201
+ export declare function iso2ToFlag(iso2: string): string;
202
+
203
+ export declare interface Language {
204
+ code: string;
205
+ english_name: string;
206
+ native_name: string;
207
+ }
208
+
209
+ export declare interface LanguagePickerProps {
210
+ value?: Language | null;
211
+ onChange: (language: Language) => void;
212
+ placeholder?: string;
213
+ searchable?: boolean;
214
+ /** Show native language name alongside english name */
215
+ showNativeName?: boolean;
216
+ disabled?: boolean;
217
+ className?: string;
218
+ label?: string;
219
+ }
220
+
221
+ export declare const PHONE_FORMATS: PhoneFormat[];
222
+
223
+ export declare interface PhoneFormat {
224
+ countryCode?: string;
225
+ iso2: string;
226
+ dialCode: string;
227
+ patterns: string;
228
+ possibleLengths: string;
229
+ example: string | number;
230
+ }
231
+
232
+ export declare interface PhoneInputProps {
233
+ value?: PhoneValue | null;
234
+ onChange: (value: PhoneValue) => void;
235
+ /** Pre-select a country by ISO2 on first render */
236
+ defaultCountryIso2?: string;
237
+ placeholder?: string;
238
+ showFlag?: boolean;
239
+ disabled?: boolean;
240
+ className?: string;
241
+ label?: string;
242
+ }
243
+
244
+ /**
245
+ * Value object returned by PhoneInput.
246
+ */
247
+ export declare interface PhoneValue {
248
+ /** Full Country object of the selected country */
249
+ country: Country;
250
+ /** Dial code with + prefix, e.g. "+1" */
251
+ dialCode: string;
252
+ /** Raw phone number without dial code, e.g. "4155551234" */
253
+ number: string;
254
+ /** Full number with dial code, e.g. "+14155551234" */
255
+ full: string;
256
+ }
257
+
258
+ /**
259
+ * Search countries by name, iso2, iso3 or phone code
260
+ */
261
+ export declare function searchCountries(query: string): Country[];
262
+
263
+ /**
264
+ * Search currencies by code, name, or symbol
265
+ */
266
+ export declare function searchCurrencies(query: string, countryIso2?: string): Currency[];
267
+
268
+ /**
269
+ * Search languages by english name, native name, or code
270
+ */
271
+ export declare function searchLanguages(query: string): Language[];
272
+
273
+ /**
274
+ * Search timezones by name, abbreviation, or offset string
275
+ */
276
+ export declare function searchTimezones(query: string, countryIso2?: string): Timezone[];
277
+
278
+ export declare interface Timezone {
279
+ name: string;
280
+ offset: number;
281
+ offset_name: string;
282
+ abbreviation: string;
283
+ tzName: string;
284
+ countryCode: string;
285
+ }
286
+
287
+ export declare interface TimezonePickerProps {
288
+ value?: Timezone | null;
289
+ onChange: (timezone: Timezone) => void;
290
+ placeholder?: string;
291
+ searchable?: boolean;
292
+ /** Filter timezones to a specific country (iso2) and enable auto-selection */
293
+ countryIso2?: string;
294
+ /** Auto-select the first timezone if countryIso2 is provided. Defaults to true if countryIso2 is present and value is empty. */
295
+ autoSelect?: boolean;
296
+ disabled?: boolean;
297
+ className?: string;
298
+ label?: string;
299
+ }
300
+
301
+ export declare const TIMEZONES: Timezone[];
302
+
303
+ /**
304
+ * Generic base hook for all pickers.
305
+ * Handles open/close state, search query, and item selection.
306
+ */
307
+ export declare function useBasePicker<T>(allItems: T[], filterFn: (items: T[], query: string) => T[], initialValue?: T | null, onChange?: (item: T) => void): UsePickerReturn<T>;
308
+
309
+ export declare function useCountryPicker(initialValue?: Country | null, onChange?: (country: Country) => void): UsePickerReturn<Country>;
310
+
311
+ export declare function useCurrencyPicker(initialValue?: Currency | null, onChange?: (currency: Currency) => void): UsePickerReturn<Currency>;
312
+
313
+ export declare function useDivisionPicker(countryIso2: string, initialValue?: Division | null, onChange?: (division: Division) => void): UsePickerReturn<Division>;
314
+
315
+ export declare function useLanguagePicker(initialValue?: Language | null, onChange?: (language: Language) => void): UsePickerReturn<Language>;
316
+
317
+ /**
318
+ * Generic multi-selection hook.
319
+ * Handles open/close, search, and toggle-selection of multiple items.
320
+ */
321
+ export declare function useMultiSelect<T>(allItems: T[], filterFn: (items: T[], query: string) => T[], keyFn: (item: T) => string, initialValue?: T[], onChange?: (items: T[]) => void, maxItems?: number): UseMultiSelectReturn<T>;
322
+
323
+ export declare interface UseMultiSelectReturn<T> {
324
+ isOpen: boolean;
325
+ searchQuery: string;
326
+ filteredItems: T[];
327
+ selectedItems: T[];
328
+ open: () => void;
329
+ close: () => void;
330
+ toggle: () => void;
331
+ setSearchQuery: (query: string) => void;
332
+ toggleItem: (item: T) => void;
333
+ isSelected: (item: T) => boolean;
334
+ removeItem: (item: T) => void;
335
+ clearAll: () => void;
336
+ }
337
+
338
+ export declare function usePhoneInput(initialValue?: PhoneValue | null, onChange?: (value: PhoneValue) => void, defaultCountryIso2?: string): UsePhoneInputReturn;
339
+
340
+ export declare interface UsePhoneInputReturn {
341
+ country: Country | null;
342
+ number: string;
343
+ value: PhoneValue | null;
344
+ isOpen: boolean;
345
+ searchQuery: string;
346
+ filteredCountries: Country[];
347
+ minLength?: number;
348
+ maxLength?: number;
349
+ setSearchQuery: (q: string) => void;
350
+ selectCountry: (country: Country) => void;
351
+ setNumber: (num: string) => void;
352
+ toggle: () => void;
353
+ close: () => void;
354
+ }
355
+
356
+ export declare interface UsePickerReturn<T> {
357
+ isOpen: boolean;
358
+ searchQuery: string;
359
+ filteredItems: T[];
360
+ selectedItem: T | null;
361
+ open: () => void;
362
+ close: () => void;
363
+ toggle: () => void;
364
+ setSearchQuery: (query: string) => void;
365
+ selectItem: (item: T) => void;
366
+ clearSelection: () => void;
367
+ }
368
+
369
+ export declare function useTimezonePicker(initialValue?: Timezone | null, onChange?: (timezone: Timezone) => void, countryIso2?: string): UsePickerReturn<Timezone>;
370
+
371
+ export { }