Skip to content

Commit

Permalink
pinyin utils + two currency methods
Browse files Browse the repository at this point in the history
  • Loading branch information
caseyryan committed Oct 31, 2022
1 parent 10ef877 commit c9f31fc
Show file tree
Hide file tree
Showing 9 changed files with 10,509 additions and 149 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## [2.9.0]
- Added more pinyin utils + HanziUtils
- Added to utility methods for currencies isCryptoCurrency(String currencyId) and isFiatCurrency(String currencyId)
## [2.8.8]
- One more minor fix for PinyinUtils
## [2.8.7]
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ packages:
path: ".."
relative: true
source: path
version: "2.8.8"
version: "2.9.0"
flutter_test:
dependency: "direct dev"
description: flutter
Expand Down
118 changes: 118 additions & 0 deletions lib/formatters/all_fiat_currencies.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
const allFiatCurrencies = const <String>[
'CNY',
'USD',
'EUR',
'JPY',
'GBP',
'KRW',
'INR',
'CAD',
'HKD',
'BRL',
'AUD',
'TWD',
'RUB',
'CHF',
'MXN',
'SAR',
'THB',
'AED',
'SGD',
'VND',
'IDR',
'ILS',
'MYR',
'SEK',
'PLN',
'TRY',
'BTC',
'CLP',
'NOK',
'PHP',
'ZAR',
'EGP',
'DKK',
'CZK',
'NZD',
'QAR',
'COP',
'MAD',
'PKR',
'LBP',
'KWD',
'RON',
'NGN',
'ARS',
'IQD',
'HUF',
'MOP',
'PEN',
'BGN',
'KZT',
'UAH',
'JOD',
'OMR',
'GTQ',
'BHD',
'DOP',
'XOF',
'KES',
'BOB',
'RSD',
'LKR',
'HRK',
'AZN',
'AOA',
'HNL',
'BYN',
'CRC',
'LYD',
'MUR',
'ISK',
'PYG',
'TZS',
'TTD',
'ALL',
'CDF',
'GEL',
'BND',
'UYU',
'MZN',
'BSD',
'UGX',
'MNT',
'LAK',
'SDG',
'BWP',
'NAD',
'BAM',
'MKD',
'AMD',
'MDL',
'XPF',
'JMD',
'NIO',
'GNF',
'MGA',
'KGS',
'MVR',
'RWF',
'GYD',
'BTN',
'CVE',
'SCR',
'XAF',
'BIF',
'SZL',
'GMD',
'LRD',
'SLL',
'LSL',
'KMF',
'BDT',
'TND',
'ZMK',
'TJS',
'MWK',
'STD',
];
8 changes: 8 additions & 0 deletions lib/formatters/formatter_extension_methods.dart
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ extension NumericInputFormatting on num {
}

extension StringInputFormatting on String {
bool get isFiatCurrency {
return fu.isFiatCurrency(this);
}

bool get isCryptoCurrency {
return fu.isCryptoCurrency(this);
}

/// [thousandSeparator] specifies what symbol will be used to separate
/// each block of 3 digits, e.g. [ThousandSeparator.Comma] will format
/// a million as 1,000,000
Expand Down
22 changes: 22 additions & 0 deletions lib/formatters/formatter_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
import 'package:flutter/foundation.dart';
import 'package:flutter_multi_formatter/formatters/all_fiat_currencies.dart';

import 'money_input_enums.dart';

Expand Down Expand Up @@ -457,6 +458,27 @@ String _getRoundedValue(
return result.toInt().toString();
}

/// Checks if currency is fiat
bool isFiatCurrency(String currencyId) {
if (currencyId.length != 3) {
return false;
}
return allFiatCurrencies.contains(
currencyId.toUpperCase(),
);
}

/// Basically it doesn't really check if the currencyId is
/// a crypto currency. It just checks if it's not fiat.
/// I decided not to collect all possible crypto currecies as
/// there's an endless amount of them
bool isCryptoCurrency(String currencyId) {
if (currencyId.length < 3 || currencyId.length > 4) {
return false;
}
return !isFiatCurrency(currencyId);
}

/// simply adds a period to an existing fractional part
/// or adds an empty fractional part if it was not filled
String _postProcessMantissa(String mantissaValue, int mantissaLength) {
Expand Down
Loading

0 comments on commit c9f31fc

Please sign in to comment.