@arkyn/templates 3.0.1-beta.12 → 3.0.1-beta.121
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 +394 -0
- package/{src/countries.ts → dist/bundle.js} +304 -249
- package/dist/bundle.umd.cjs +1 -0
- package/package.json +24 -4
- package/src/brazilianStates.ts +0 -31
- package/src/countryCurrencies.ts +0 -26
- package/src/index.ts +0 -4
- package/src/maximumFractionDigits.ts +0 -3
- package/tsconfig.json +0 -20
package/README.md
ADDED
|
@@ -0,0 +1,394 @@
|
|
|
1
|
+
# @arkyn/templates
|
|
2
|
+
|
|
3
|
+
Ready-to-use data templates and constants for international and Brazilian applications. Provides comprehensive country data, Brazilian states, currency information, and locale configurations to accelerate your development workflow.
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@arkyn/templates)
|
|
6
|
+
[](https://opensource.org/licenses/Apache-2.0)
|
|
7
|
+
[](https://www.typescriptlang.org/)
|
|
8
|
+
|
|
9
|
+
## ✨ Features
|
|
10
|
+
|
|
11
|
+
- 🌍 **Global Countries Data** - Complete list of 195+ countries with flags, codes, and phone masks
|
|
12
|
+
- 🇧🇷 **Brazilian States** - All 26 states plus Federal District with codes and names
|
|
13
|
+
- 💱 **Currency Information** - Country-specific currency data and formatting rules
|
|
14
|
+
- 📊 **Locale Configurations** - Maximum fraction digits for different currencies
|
|
15
|
+
- 🎯 **TypeScript Support** - Fully typed data structures
|
|
16
|
+
- 📱 **Phone Number Masks** - Country-specific phone formatting patterns
|
|
17
|
+
|
|
18
|
+
## 📦 Installation
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
npm install @arkyn/templates
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## 🚀 Quick Start
|
|
25
|
+
|
|
26
|
+
```typescript
|
|
27
|
+
import {
|
|
28
|
+
countries,
|
|
29
|
+
brazilianStates,
|
|
30
|
+
countryCurrencies,
|
|
31
|
+
} from "@arkyn/templates";
|
|
32
|
+
|
|
33
|
+
// Find a specific country
|
|
34
|
+
const brazil = countries.find((country) => country.iso === "BR");
|
|
35
|
+
console.log(brazil);
|
|
36
|
+
// {
|
|
37
|
+
// name: "Brazil",
|
|
38
|
+
// code: "+55",
|
|
39
|
+
// prefix: null,
|
|
40
|
+
// iso: "BR",
|
|
41
|
+
// flag: "https://cdn.kcak11.com/CountryFlags/countries/br.svg",
|
|
42
|
+
// mask: "(__) _____-____"
|
|
43
|
+
// }
|
|
44
|
+
|
|
45
|
+
// Get Brazilian states
|
|
46
|
+
const saoPaulo = brazilianStates.find((state) => state.code === "SP");
|
|
47
|
+
console.log(saoPaulo); // { code: 'SP', name: 'São Paulo' }
|
|
48
|
+
|
|
49
|
+
// Access currency data
|
|
50
|
+
console.log(countryCurrencies.USD); // Currency information for USD
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## 📋 API Reference
|
|
54
|
+
|
|
55
|
+
### 🌍 Countries Data
|
|
56
|
+
|
|
57
|
+
The `countries` array contains comprehensive data for all world countries:
|
|
58
|
+
|
|
59
|
+
```typescript
|
|
60
|
+
interface Country {
|
|
61
|
+
name: string; // Country name in English
|
|
62
|
+
code: string; // International dialing code (e.g., "+55")
|
|
63
|
+
prefix: string | null; // Additional prefix for specific regions
|
|
64
|
+
iso: string; // ISO 3166-1 alpha-2 country code
|
|
65
|
+
flag: string; // URL to country flag SVG
|
|
66
|
+
mask: string; // Phone number formatting mask
|
|
67
|
+
}
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
#### Usage Examples
|
|
71
|
+
|
|
72
|
+
```typescript
|
|
73
|
+
import { countries } from "@arkyn/templates";
|
|
74
|
+
|
|
75
|
+
// Get all countries
|
|
76
|
+
console.log(countries.length); // 195+
|
|
77
|
+
|
|
78
|
+
// Find by ISO code
|
|
79
|
+
const usa = countries.find((country) => country.iso === "US");
|
|
80
|
+
|
|
81
|
+
// Find by country code
|
|
82
|
+
const brazilianCountries = countries.filter(
|
|
83
|
+
(country) => country.code === "+55"
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
// Get all European countries (you'll need additional logic)
|
|
87
|
+
const europeanCountries = countries.filter((country) =>
|
|
88
|
+
["FR", "DE", "IT", "ES", "PT"].includes(country.iso)
|
|
89
|
+
);
|
|
90
|
+
|
|
91
|
+
// Create a phone input selector
|
|
92
|
+
function CountrySelector() {
|
|
93
|
+
return (
|
|
94
|
+
<select>
|
|
95
|
+
{countries.map((country) => (
|
|
96
|
+
<option key={country.iso} value={country.code}>
|
|
97
|
+
<img src={country.flag} alt={country.name} />
|
|
98
|
+
{country.name} ({country.code})
|
|
99
|
+
</option>
|
|
100
|
+
))}
|
|
101
|
+
</select>
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### 🇧🇷 Brazilian States
|
|
107
|
+
|
|
108
|
+
The `brazilianStates` array contains all Brazilian states and the Federal District:
|
|
109
|
+
|
|
110
|
+
```typescript
|
|
111
|
+
interface BrazilianState {
|
|
112
|
+
code: string; // Two-letter state code (e.g., "SP", "RJ")
|
|
113
|
+
name: string; // State name in Portuguese (e.g., "São Paulo")
|
|
114
|
+
}
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
#### Usage Examples
|
|
118
|
+
|
|
119
|
+
```typescript
|
|
120
|
+
import { brazilianStates } from "@arkyn/templates";
|
|
121
|
+
|
|
122
|
+
// Get all states
|
|
123
|
+
console.log(brazilianStates.length); // 27 (26 states + Federal District)
|
|
124
|
+
|
|
125
|
+
// Find specific state
|
|
126
|
+
const rioDeJaneiro = brazilianStates.find((state) => state.code === "RJ");
|
|
127
|
+
console.log(rioDeJaneiro); // { code: 'RJ', name: 'Rio de Janeiro' }
|
|
128
|
+
|
|
129
|
+
// Create a state selector
|
|
130
|
+
function StateSelector() {
|
|
131
|
+
return (
|
|
132
|
+
<select>
|
|
133
|
+
{brazilianStates.map((state) => (
|
|
134
|
+
<option key={state.code} value={state.code}>
|
|
135
|
+
{state.name}
|
|
136
|
+
</option>
|
|
137
|
+
))}
|
|
138
|
+
</select>
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// Validate state code
|
|
143
|
+
function isValidState(stateCode: string): boolean {
|
|
144
|
+
return brazilianStates.some((state) => state.code === stateCode);
|
|
145
|
+
}
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
### 💱 Country Currencies
|
|
149
|
+
|
|
150
|
+
The `countryCurrencies` object provides currency information mapped by currency codes:
|
|
151
|
+
|
|
152
|
+
```typescript
|
|
153
|
+
interface CountryCurrency {
|
|
154
|
+
[currencyCode: string]: {
|
|
155
|
+
symbol: string;
|
|
156
|
+
name: string;
|
|
157
|
+
countries: string[];
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
#### Usage Examples
|
|
163
|
+
|
|
164
|
+
```typescript
|
|
165
|
+
import { countryCurrencies } from "@arkyn/templates";
|
|
166
|
+
|
|
167
|
+
// Get USD information
|
|
168
|
+
console.log(countryCurrencies.USD);
|
|
169
|
+
// {
|
|
170
|
+
// symbol: '$',
|
|
171
|
+
// name: 'US Dollar',
|
|
172
|
+
// countries: ['US', 'EC', 'SV', ...]
|
|
173
|
+
// }
|
|
174
|
+
|
|
175
|
+
// Get Brazilian Real
|
|
176
|
+
console.log(countryCurrencies.BRL);
|
|
177
|
+
// {
|
|
178
|
+
// symbol: 'R$',
|
|
179
|
+
// name: 'Brazilian Real',
|
|
180
|
+
// countries: ['BR']
|
|
181
|
+
// }
|
|
182
|
+
|
|
183
|
+
// Find all countries using EUR
|
|
184
|
+
const euroCountries = countryCurrencies.EUR.countries;
|
|
185
|
+
|
|
186
|
+
// Get currency by country
|
|
187
|
+
function getCurrencyByCountry(countryCode: string): string | null {
|
|
188
|
+
for (const [currency, data] of Object.entries(countryCurrencies)) {
|
|
189
|
+
if (data.countries.includes(countryCode)) {
|
|
190
|
+
return currency;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
return null;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
const brazilCurrency = getCurrencyByCountry("BR"); // 'BRL'
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
### 📊 Maximum Fraction Digits
|
|
200
|
+
|
|
201
|
+
The `maximumFractionDigits` object provides locale-specific decimal place configurations:
|
|
202
|
+
|
|
203
|
+
```typescript
|
|
204
|
+
interface MaximumFractionDigits {
|
|
205
|
+
[locale: string]: number;
|
|
206
|
+
}
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
#### Usage Examples
|
|
210
|
+
|
|
211
|
+
```typescript
|
|
212
|
+
import { maximumFractionDigits } from "@arkyn/templates";
|
|
213
|
+
|
|
214
|
+
// Get maximum decimal places for different locales
|
|
215
|
+
console.log(maximumFractionDigits["pt-BR"]); // 2 (for Brazilian Real)
|
|
216
|
+
console.log(maximumFractionDigits["en-US"]); // 2 (for US Dollar)
|
|
217
|
+
console.log(maximumFractionDigits["ja-JP"]); // 0 (for Japanese Yen)
|
|
218
|
+
|
|
219
|
+
// Format currency with correct decimal places
|
|
220
|
+
function formatCurrency(amount: number, locale: string): string {
|
|
221
|
+
const fractionDigits = maximumFractionDigits[locale] || 2;
|
|
222
|
+
|
|
223
|
+
return new Intl.NumberFormat(locale, {
|
|
224
|
+
style: "currency",
|
|
225
|
+
currency: getCurrencyForLocale(locale),
|
|
226
|
+
maximumFractionDigits: fractionDigits,
|
|
227
|
+
minimumFractionDigits: fractionDigits,
|
|
228
|
+
}).format(amount);
|
|
229
|
+
}
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
## 🔧 Advanced Usage
|
|
233
|
+
|
|
234
|
+
### International Phone Input
|
|
235
|
+
|
|
236
|
+
```typescript
|
|
237
|
+
import { countries } from "@arkyn/templates";
|
|
238
|
+
|
|
239
|
+
function InternationalPhoneInput() {
|
|
240
|
+
const [selectedCountry, setSelectedCountry] = useState(countries[0]);
|
|
241
|
+
const [phoneNumber, setPhoneNumber] = useState("");
|
|
242
|
+
|
|
243
|
+
const formatPhoneNumber = (number: string) => {
|
|
244
|
+
let formatted = number;
|
|
245
|
+
const mask = selectedCountry.mask;
|
|
246
|
+
|
|
247
|
+
// Apply mask logic here
|
|
248
|
+
return formatted;
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
return (
|
|
252
|
+
<div className="phone-input">
|
|
253
|
+
<select
|
|
254
|
+
value={selectedCountry.iso}
|
|
255
|
+
onChange={(e) => {
|
|
256
|
+
const country = countries.find((c) => c.iso === e.target.value);
|
|
257
|
+
setSelectedCountry(country);
|
|
258
|
+
}}
|
|
259
|
+
>
|
|
260
|
+
{countries.map((country) => (
|
|
261
|
+
<option key={country.iso} value={country.iso}>
|
|
262
|
+
<img src={country.flag} alt="" />
|
|
263
|
+
{country.name} ({country.code})
|
|
264
|
+
</option>
|
|
265
|
+
))}
|
|
266
|
+
</select>
|
|
267
|
+
|
|
268
|
+
<input
|
|
269
|
+
type="tel"
|
|
270
|
+
value={phoneNumber}
|
|
271
|
+
onChange={(e) => setPhoneNumber(formatPhoneNumber(e.target.value))}
|
|
272
|
+
placeholder={selectedCountry.mask.replace(/_/g, "0")}
|
|
273
|
+
/>
|
|
274
|
+
</div>
|
|
275
|
+
);
|
|
276
|
+
}
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
### Multi-Currency Calculator
|
|
280
|
+
|
|
281
|
+
```typescript
|
|
282
|
+
import { countryCurrencies, maximumFractionDigits } from "@arkyn/templates";
|
|
283
|
+
|
|
284
|
+
class CurrencyCalculator {
|
|
285
|
+
private exchangeRates: Record<string, number> = {};
|
|
286
|
+
|
|
287
|
+
setExchangeRates(rates: Record<string, number>) {
|
|
288
|
+
this.exchangeRates = rates;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
convert(amount: number, fromCurrency: string, toCurrency: string): number {
|
|
292
|
+
if (!this.exchangeRates[fromCurrency] || !this.exchangeRates[toCurrency]) {
|
|
293
|
+
throw new Error("Exchange rate not available");
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
const usdAmount = amount / this.exchangeRates[fromCurrency];
|
|
297
|
+
return usdAmount * this.exchangeRates[toCurrency];
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
format(amount: number, currency: string, locale: string): string {
|
|
301
|
+
const fractionDigits = maximumFractionDigits[locale] || 2;
|
|
302
|
+
const currencyInfo = countryCurrencies[currency];
|
|
303
|
+
|
|
304
|
+
return new Intl.NumberFormat(locale, {
|
|
305
|
+
style: "currency",
|
|
306
|
+
currency: currency,
|
|
307
|
+
maximumFractionDigits: fractionDigits,
|
|
308
|
+
}).format(amount);
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
### Address Form with Brazilian States
|
|
314
|
+
|
|
315
|
+
```typescript
|
|
316
|
+
import { brazilianStates } from "@arkyn/templates";
|
|
317
|
+
|
|
318
|
+
function AddressForm() {
|
|
319
|
+
const [address, setAddress] = useState({
|
|
320
|
+
street: "",
|
|
321
|
+
city: "",
|
|
322
|
+
state: "",
|
|
323
|
+
zipCode: "",
|
|
324
|
+
});
|
|
325
|
+
|
|
326
|
+
return (
|
|
327
|
+
<form>
|
|
328
|
+
<input
|
|
329
|
+
type="text"
|
|
330
|
+
placeholder="Street Address"
|
|
331
|
+
value={address.street}
|
|
332
|
+
onChange={(e) => setAddress({ ...address, street: e.target.value })}
|
|
333
|
+
/>
|
|
334
|
+
|
|
335
|
+
<input
|
|
336
|
+
type="text"
|
|
337
|
+
placeholder="City"
|
|
338
|
+
value={address.city}
|
|
339
|
+
onChange={(e) => setAddress({ ...address, city: e.target.value })}
|
|
340
|
+
/>
|
|
341
|
+
|
|
342
|
+
<select
|
|
343
|
+
value={address.state}
|
|
344
|
+
onChange={(e) => setAddress({ ...address, state: e.target.value })}
|
|
345
|
+
>
|
|
346
|
+
<option value="">Select State</option>
|
|
347
|
+
{brazilianStates.map((state) => (
|
|
348
|
+
<option key={state.code} value={state.code}>
|
|
349
|
+
{state.name}
|
|
350
|
+
</option>
|
|
351
|
+
))}
|
|
352
|
+
</select>
|
|
353
|
+
|
|
354
|
+
<input
|
|
355
|
+
type="text"
|
|
356
|
+
placeholder="ZIP Code"
|
|
357
|
+
value={address.zipCode}
|
|
358
|
+
onChange={(e) => setAddress({ ...address, zipCode: e.target.value })}
|
|
359
|
+
/>
|
|
360
|
+
</form>
|
|
361
|
+
);
|
|
362
|
+
}
|
|
363
|
+
```
|
|
364
|
+
|
|
365
|
+
## 🧪 Development
|
|
366
|
+
|
|
367
|
+
```bash
|
|
368
|
+
# Install dependencies
|
|
369
|
+
bun install
|
|
370
|
+
|
|
371
|
+
# Build the package
|
|
372
|
+
bun run build
|
|
373
|
+
|
|
374
|
+
# Type check
|
|
375
|
+
bun run typecheck
|
|
376
|
+
```
|
|
377
|
+
|
|
378
|
+
## 🤝 Contributing
|
|
379
|
+
|
|
380
|
+
Contributions are welcome! Please read our contributing guidelines and submit pull requests to help improve the package.
|
|
381
|
+
|
|
382
|
+
## 📄 License
|
|
383
|
+
|
|
384
|
+
This project is licensed under the Apache 2.0 License - see the [LICENSE](./LICENSE.txt) file for details.
|
|
385
|
+
|
|
386
|
+
## 🔗 Links
|
|
387
|
+
|
|
388
|
+
- [GitHub Repository](https://github.com/Lucas-Eduardo-Goncalves/arkyn)
|
|
389
|
+
- [NPM Package](https://www.npmjs.com/package/@arkyn/templates)
|
|
390
|
+
- [Full Documentation](https://github.com/Lucas-Eduardo-Goncalves/arkyn#readme)
|
|
391
|
+
|
|
392
|
+
---
|
|
393
|
+
|
|
394
|
+
Made with ❤️ by the Arkyn team
|