Skip to content

Commit c9f31fc

Browse files
committed
pinyin utils + two currency methods
1 parent 10ef877 commit c9f31fc

9 files changed

Lines changed: 10509 additions & 149 deletions

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## [2.9.0]
2+
- Added more pinyin utils + HanziUtils
3+
- Added to utility methods for currencies isCryptoCurrency(String currencyId) and isFiatCurrency(String currencyId)
14
## [2.8.8]
25
- One more minor fix for PinyinUtils
36
## [2.8.7]

example/pubspec.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ packages:
9696
path: ".."
9797
relative: true
9898
source: path
99-
version: "2.8.8"
99+
version: "2.9.0"
100100
flutter_test:
101101
dependency: "direct dev"
102102
description: flutter
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
const allFiatCurrencies = const <String>[
2+
'CNY',
3+
'USD',
4+
'EUR',
5+
'JPY',
6+
'GBP',
7+
'KRW',
8+
'INR',
9+
'CAD',
10+
'HKD',
11+
'BRL',
12+
'AUD',
13+
'TWD',
14+
'RUB',
15+
'CHF',
16+
'MXN',
17+
'SAR',
18+
'THB',
19+
'AED',
20+
'SGD',
21+
'VND',
22+
'IDR',
23+
'ILS',
24+
'MYR',
25+
'SEK',
26+
'PLN',
27+
'TRY',
28+
'BTC',
29+
'CLP',
30+
'NOK',
31+
'PHP',
32+
'ZAR',
33+
'EGP',
34+
'DKK',
35+
'CZK',
36+
'NZD',
37+
'QAR',
38+
'COP',
39+
'MAD',
40+
'PKR',
41+
'LBP',
42+
'KWD',
43+
'RON',
44+
'NGN',
45+
'ARS',
46+
'IQD',
47+
'HUF',
48+
'MOP',
49+
'PEN',
50+
'BGN',
51+
'KZT',
52+
'UAH',
53+
'JOD',
54+
'OMR',
55+
'GTQ',
56+
'BHD',
57+
'DOP',
58+
'XOF',
59+
'KES',
60+
'BOB',
61+
'RSD',
62+
'LKR',
63+
'HRK',
64+
'AZN',
65+
'AOA',
66+
'HNL',
67+
'BYN',
68+
'CRC',
69+
'LYD',
70+
'MUR',
71+
'ISK',
72+
'PYG',
73+
'TZS',
74+
'TTD',
75+
'ALL',
76+
'CDF',
77+
'GEL',
78+
'BND',
79+
'UYU',
80+
'MZN',
81+
'BSD',
82+
'UGX',
83+
'MNT',
84+
'LAK',
85+
'SDG',
86+
'BWP',
87+
'NAD',
88+
'BAM',
89+
'MKD',
90+
'AMD',
91+
'MDL',
92+
'XPF',
93+
'JMD',
94+
'NIO',
95+
'GNF',
96+
'MGA',
97+
'KGS',
98+
'MVR',
99+
'RWF',
100+
'GYD',
101+
'BTN',
102+
'CVE',
103+
'SCR',
104+
'XAF',
105+
'BIF',
106+
'SZL',
107+
'GMD',
108+
'LRD',
109+
'SLL',
110+
'LSL',
111+
'KMF',
112+
'BDT',
113+
'TND',
114+
'ZMK',
115+
'TJS',
116+
'MWK',
117+
'STD',
118+
];

lib/formatters/formatter_extension_methods.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,14 @@ extension NumericInputFormatting on num {
7474
}
7575

7676
extension StringInputFormatting on String {
77+
bool get isFiatCurrency {
78+
return fu.isFiatCurrency(this);
79+
}
80+
81+
bool get isCryptoCurrency {
82+
return fu.isCryptoCurrency(this);
83+
}
84+
7785
/// [thousandSeparator] specifies what symbol will be used to separate
7886
/// each block of 3 digits, e.g. [ThousandSeparator.Comma] will format
7987
/// a million as 1,000,000

lib/formatters/formatter_utils.dart

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2424
THE SOFTWARE.
2525
*/
2626
import 'package:flutter/foundation.dart';
27+
import 'package:flutter_multi_formatter/formatters/all_fiat_currencies.dart';
2728

2829
import 'money_input_enums.dart';
2930

@@ -457,6 +458,27 @@ String _getRoundedValue(
457458
return result.toInt().toString();
458459
}
459460

461+
/// Checks if currency is fiat
462+
bool isFiatCurrency(String currencyId) {
463+
if (currencyId.length != 3) {
464+
return false;
465+
}
466+
return allFiatCurrencies.contains(
467+
currencyId.toUpperCase(),
468+
);
469+
}
470+
471+
/// Basically it doesn't really check if the currencyId is
472+
/// a crypto currency. It just checks if it's not fiat.
473+
/// I decided not to collect all possible crypto currecies as
474+
/// there's an endless amount of them
475+
bool isCryptoCurrency(String currencyId) {
476+
if (currencyId.length < 3 || currencyId.length > 4) {
477+
return false;
478+
}
479+
return !isFiatCurrency(currencyId);
480+
}
481+
460482
/// simply adds a period to an existing fractional part
461483
/// or adds an empty fractional part if it was not filled
462484
String _postProcessMantissa(String mantissaValue, int mantissaLength) {

0 commit comments

Comments
 (0)