currencyFormatter-rails 0.1.0 → 0.2.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/README.md +6 -2
- data/VERSIONS.md +2 -1
- data/lib/currencyFormatter/rails/version.rb +1 -1
- data/vendor/assets/javascripts/currencyFormatter.js +129 -127
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0a7409cd475c5b9ba48bec12d850d53c1d1ed71d
|
4
|
+
data.tar.gz: 3ca2aca505548fc914905ac3a094f57bd7c8111d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d1536ddb782c5d1280a72e50365a61d93b8f369bd5191e9d90c7aaae8e62cae9727c1adeb57644ca8f1a72ef497d9c1e68bfb9da6fdaf4f6d25cdb628c852141
|
7
|
+
data.tar.gz: c08a8eb01fbfa6578d3fc570019d4f733883a7b21d91f725aca9cc5d83eff64e84868389fa47a969f93caea6f4eb5b2044c3747245106996a5c54ae81dc69782
|
data/CHANGELOG.md
ADDED
data/README.md
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
[](https://github.com/tanvir002700/currencyFormatter-rails)
|
6
6
|
[](https://github.com/tanvir002700/currencyFormatter-rails/blob/master/LICENSE)
|
7
7
|
|
8
|
-
This gem packages the
|
8
|
+
This gem packages the jQuery currencyFormatter.js plugin. So you never have to download a custom package through the web interface again.
|
9
9
|
|
10
10
|
CurrencyFormatter.js allows you to format numbers as currencies. It contains 155 currency definitions and 715 locale definitions out of the box. It handles unusually formatted currencies, such as the INR.
|
11
11
|
|
@@ -30,12 +30,16 @@ Or install it yourself as:
|
|
30
30
|
And then edit your app/assets/stylesheets/application.js file to look something like:
|
31
31
|
``` css
|
32
32
|
/*
|
33
|
-
*=
|
33
|
+
*= require jqeury
|
34
34
|
*= require currencyFormatter
|
35
|
+
*= require_self
|
35
36
|
*= require_tree .
|
36
37
|
*/
|
37
38
|
```
|
38
39
|
|
40
|
+
**currencyFormatter-rails is dependant on jQuer, so make sure you have it in your Gemfile.**
|
41
|
+
|
42
|
+
|
39
43
|
## Usage
|
40
44
|
|
41
45
|
View [CurrencyFormatter.js](https://osrec.github.io/currencyFormatter.js/) for complete useage information.
|
data/VERSIONS.md
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
1
3
|
// CurrencyFormatter.js
|
2
4
|
// ---------------------------------------------------------------------
|
3
5
|
// Version: 2.0
|
@@ -9,10 +11,8 @@
|
|
9
11
|
|
10
12
|
var OSREC = OSREC || {};
|
11
13
|
|
12
|
-
OSREC.CurrencyFormatter =
|
13
|
-
{
|
14
|
-
symbols:
|
15
|
-
{
|
14
|
+
OSREC.CurrencyFormatter = {
|
15
|
+
symbols: {
|
16
16
|
AED: 'د.إ.',
|
17
17
|
AFN: '؋',
|
18
18
|
ALL: 'Lekë',
|
@@ -36,6 +36,7 @@ OSREC.CurrencyFormatter =
|
|
36
36
|
BSD: '$',
|
37
37
|
BTN: 'Nu.',
|
38
38
|
BWP: 'P',
|
39
|
+
BYN: 'p.',
|
39
40
|
BYR: 'р.',
|
40
41
|
BZD: '$',
|
41
42
|
CAD: '$',
|
@@ -104,6 +105,7 @@ OSREC.CurrencyFormatter =
|
|
104
105
|
MNT: '₮',
|
105
106
|
MOP: 'MOP$',
|
106
107
|
MRO: 'UM',
|
108
|
+
MRU: 'UM',
|
107
109
|
MUR: 'Rs',
|
108
110
|
MWK: 'MK',
|
109
111
|
MXN: '$',
|
@@ -139,6 +141,7 @@ OSREC.CurrencyFormatter =
|
|
139
141
|
SRD: '$',
|
140
142
|
SSP: '£',
|
141
143
|
STD: 'Db',
|
144
|
+
STN: 'Db',
|
142
145
|
SYP: '£',
|
143
146
|
SZL: 'E',
|
144
147
|
THB: '฿',
|
@@ -167,8 +170,7 @@ OSREC.CurrencyFormatter =
|
|
167
170
|
ZMW: 'K'
|
168
171
|
},
|
169
172
|
|
170
|
-
defaultLocales:
|
171
|
-
{
|
173
|
+
defaultLocales: {
|
172
174
|
AED: 'ar_AE',
|
173
175
|
AFN: 'fa_AF',
|
174
176
|
ALL: 'sq',
|
@@ -192,6 +194,7 @@ OSREC.CurrencyFormatter =
|
|
192
194
|
BSD: 'en_BS',
|
193
195
|
BTN: 'dz',
|
194
196
|
BWP: 'en_BW',
|
197
|
+
BYN: 'be',
|
195
198
|
BYR: 'be',
|
196
199
|
BZD: 'en_BZ',
|
197
200
|
CAD: 'en_CA',
|
@@ -259,6 +262,7 @@ OSREC.CurrencyFormatter =
|
|
259
262
|
MNT: 'mn',
|
260
263
|
MOP: 'zh',
|
261
264
|
MRO: 'ar_MR',
|
265
|
+
MRU: 'ar_MR',
|
262
266
|
MUR: 'en_MU',
|
263
267
|
MVR: 'en',
|
264
268
|
MWK: 'en',
|
@@ -296,6 +300,7 @@ OSREC.CurrencyFormatter =
|
|
296
300
|
SRD: 'nl_SR',
|
297
301
|
SSP: 'en',
|
298
302
|
STD: 'pt_ST',
|
303
|
+
STN: 'pt_ST',
|
299
304
|
SYP: 'ar_SY',
|
300
305
|
SZL: 'en_SZ',
|
301
306
|
THB: 'th',
|
@@ -323,12 +328,11 @@ OSREC.CurrencyFormatter =
|
|
323
328
|
YER: 'ar_YE',
|
324
329
|
ZAR: 'zu',
|
325
330
|
ZMW: 'en_ZM',
|
326
|
-
ZWL: 'en_ZW'
|
331
|
+
ZWL: 'en_ZW'
|
327
332
|
|
328
333
|
},
|
329
334
|
|
330
|
-
locales:
|
331
|
-
{
|
335
|
+
locales: {
|
332
336
|
af: { p: '!#,##0.00', g: ' ', d: ',' },
|
333
337
|
af_NA: { h: 'af' },
|
334
338
|
af_ZA: { h: 'af' },
|
@@ -341,22 +345,22 @@ OSREC.CurrencyFormatter =
|
|
341
345
|
ar: { p: '! #,##0.00', g: ',', d: '.' },
|
342
346
|
ar_001: { h: 'ar' },
|
343
347
|
ar_AE: { h: 'ar' },
|
344
|
-
ar_BH: {
|
348
|
+
ar_BH: { p: '! #,##0.000', g: ',', d: '.' },
|
345
349
|
ar_DJ: { h: 'ar' },
|
346
350
|
ar_DZ: { p: '! #,##0.00', g: '.', d: ',' },
|
347
351
|
ar_EG: { h: 'ar' },
|
348
352
|
ar_EH: { h: 'ar' },
|
349
353
|
ar_ER: { h: 'ar' },
|
350
354
|
ar_IL: { h: 'ar' },
|
351
|
-
ar_IQ: {
|
352
|
-
ar_JO: {
|
355
|
+
ar_IQ: { p: '! #,##0.000', g: ',', d: '.' },
|
356
|
+
ar_JO: { p: '! #,##0.000', g: ',', d: '.' },
|
353
357
|
ar_KM: { h: 'ar' },
|
354
|
-
ar_KW: {
|
358
|
+
ar_KW: { p: '! #,##0.000', g: ',', d: '.' },
|
355
359
|
ar_LB: { p: '! #,##0.00', g: '.', d: ',' },
|
356
|
-
ar_LY: { p: '! #,##0.
|
360
|
+
ar_LY: { p: '! #,##0.000', g: '.', d: ',' },
|
357
361
|
ar_MA: { p: '! #,##0.00', g: '.', d: ',' },
|
358
362
|
ar_MR: { p: '! #,##0.00', g: '.', d: ',' },
|
359
|
-
ar_OM: {
|
363
|
+
ar_OM: { p: '! #,##0.000', g: ',', d: '.' },
|
360
364
|
ar_PS: { h: 'ar' },
|
361
365
|
ar_QA: { h: 'ar' },
|
362
366
|
ar_SA: { h: 'ar' },
|
@@ -365,7 +369,7 @@ OSREC.CurrencyFormatter =
|
|
365
369
|
ar_SS: { h: 'ar' },
|
366
370
|
ar_SY: { h: 'ar' },
|
367
371
|
ar_TD: { h: 'ar' },
|
368
|
-
ar_TN: { p: '! #,##0.
|
372
|
+
ar_TN: { p: '! #,##0.000', g: '.', d: ',' },
|
369
373
|
ar_YE: { h: 'ar' },
|
370
374
|
as: { p: '! #,##,##0.00', g: ',', d: '.' },
|
371
375
|
as_IN: { h: 'as' },
|
@@ -569,7 +573,7 @@ OSREC.CurrencyFormatter =
|
|
569
573
|
es_AR: { p: '! #,##0.00', g: '.', d: ',' },
|
570
574
|
es_BO: { h: 'es' },
|
571
575
|
es_BR: { h: 'es' },
|
572
|
-
es_CL: { p: '!#,##0
|
576
|
+
es_CL: { p: '!#,##0;!-#,##0', g: '.', d: ',' },
|
573
577
|
es_CO: { p: '! #,##0.00', g: '.', d: ',' },
|
574
578
|
es_CR: { p: '#,##0.00 !', g: ' ', d: ',' },
|
575
579
|
es_CU: { h: 'es' },
|
@@ -587,7 +591,7 @@ OSREC.CurrencyFormatter =
|
|
587
591
|
es_PE: { h: 'es' },
|
588
592
|
es_PH: { h: 'es' },
|
589
593
|
es_PR: { h: 'es' },
|
590
|
-
es_PY: { p: '! #,##0
|
594
|
+
es_PY: { p: '! #,##0;! -#,##0', g: '.', d: ',' },
|
591
595
|
es_SV: { h: 'es' },
|
592
596
|
es_US: { h: 'es' },
|
593
597
|
es_UY: { p: '! #,##0.00', g: '.', d: ',' },
|
@@ -631,7 +635,7 @@ OSREC.CurrencyFormatter =
|
|
631
635
|
fr_FR: { h: 'fr' },
|
632
636
|
fr_GA: { h: 'fr' },
|
633
637
|
fr_GF: { h: 'fr' },
|
634
|
-
fr_GN: {
|
638
|
+
fr_GN: { p: '#,##0 !', g: ' ', d: ',' },
|
635
639
|
fr_GP: { h: 'fr' },
|
636
640
|
fr_GQ: { h: 'fr' },
|
637
641
|
fr_HT: { h: 'fr' },
|
@@ -705,13 +709,13 @@ OSREC.CurrencyFormatter =
|
|
705
709
|
ig_NG: { h: 'ig' },
|
706
710
|
ii: { p: '!#,##0.00', g: ',', d: '.' },
|
707
711
|
ii_CN: { h: 'ii' },
|
708
|
-
is: { p: '#,##0
|
712
|
+
is: { p: '#,##0 !', g: '.', d: ',' },
|
709
713
|
is_IS: { h: 'is' },
|
710
714
|
it: { p: '#,##0.00 !', g: '.', d: ',' },
|
711
715
|
it_CH: { p: '! #,##0.00;!-#,##0.00', g: '\'', d: '.' },
|
712
716
|
it_IT: { h: 'it' },
|
713
717
|
it_SM: { h: 'it' },
|
714
|
-
ja: { p: '!#,##0
|
718
|
+
ja: { p: '!#,##0', g: ',', d: '.' },
|
715
719
|
ja_JP: { h: 'ja' },
|
716
720
|
jgo: { p: '! #,##0.00', g: '.', d: ',' },
|
717
721
|
jgo_CM: { h: 'jgo' },
|
@@ -743,7 +747,7 @@ OSREC.CurrencyFormatter =
|
|
743
747
|
km_KH: { h: 'km' },
|
744
748
|
kn: { p: '!#,##0.00', g: ',', d: '.' },
|
745
749
|
kn_IN: { h: 'kn' },
|
746
|
-
ko: { p: '!#,##0
|
750
|
+
ko: { p: '!#,##0', g: ',', d: '.' },
|
747
751
|
ko_KP: { h: 'ko' },
|
748
752
|
ko_KR: { h: 'ko' },
|
749
753
|
kok: { p: '! #,##,##0.00', g: ',', d: '.' },
|
@@ -1011,7 +1015,7 @@ OSREC.CurrencyFormatter =
|
|
1011
1015
|
vai_Latn_LR: { h: 'vai' },
|
1012
1016
|
vai_Vaii: { h: 'vai' },
|
1013
1017
|
vai_Vaii_LR: { h: 'vai' },
|
1014
|
-
vi: { p: '
|
1018
|
+
vi: { p: '#,##0 !', g: '.', d: ',' },
|
1015
1019
|
vi_VN: { h: 'vi' },
|
1016
1020
|
vo: { p: '!#,##0.00', g: ',', d: '.' },
|
1017
1021
|
vo_001: { h: 'vo' },
|
@@ -1043,67 +1047,77 @@ OSREC.CurrencyFormatter =
|
|
1043
1047
|
zh_Hant_MO: { h: 'zh' },
|
1044
1048
|
zh_Hant_TW: { h: 'zh' },
|
1045
1049
|
zu: { p: '!#,##0.00', g: ',', d: '.' },
|
1046
|
-
zu_ZA: { h: 'zu' }
|
1050
|
+
zu_ZA: { h: 'zu' }
|
1047
1051
|
},
|
1048
1052
|
|
1049
|
-
getFormatDetails: function(p)
|
1050
|
-
|
1051
|
-
var
|
1052
|
-
var
|
1053
|
-
var symbols = OSREC.CurrencyFormatter.symbols;
|
1053
|
+
getFormatDetails: function getFormatDetails(p) {
|
1054
|
+
var locales = OSREC.CurrencyFormatter.locales;
|
1055
|
+
var defaultLocales = OSREC.CurrencyFormatter.defaultLocales;
|
1056
|
+
var symbols = OSREC.CurrencyFormatter.symbols;
|
1054
1057
|
|
1055
|
-
var locale, currency, symbol, pattern, decimal, group;
|
1058
|
+
var locale, currency, symbol, pattern, decimal, group, valueOnError;
|
1056
1059
|
|
1057
1060
|
// Perform checks on inputs and set up defaults as needed (defaults to en, USD)
|
1058
1061
|
|
1059
1062
|
p = p || {};
|
1060
1063
|
|
1061
|
-
currency
|
1062
|
-
locale
|
1064
|
+
currency = (p.currency || 'USD').toUpperCase();
|
1065
|
+
locale = locales[p.locale || defaultLocales[currency]];
|
1066
|
+
|
1067
|
+
if (typeof locale.h !== 'undefined') {
|
1068
|
+
locale = locales[locale.h];
|
1069
|
+
} // Locale inheritance
|
1063
1070
|
|
1064
|
-
|
1071
|
+
symbol = p.symbol || symbols[currency] || currency;
|
1072
|
+
pattern = p.pattern || locale.p;
|
1073
|
+
decimal = p.decimal || locale.d;
|
1074
|
+
group = p.group || locale.g;
|
1075
|
+
valueOnError = typeof p.valueOnError === 'undefined' ? 0 : p.valueOnError;
|
1065
1076
|
|
1066
|
-
|
1067
|
-
|
1068
|
-
|
1069
|
-
|
1070
|
-
|
1071
|
-
|
1077
|
+
var formatDetails = {
|
1078
|
+
pattern: pattern,
|
1079
|
+
decimal: decimal,
|
1080
|
+
group: group,
|
1081
|
+
symbol: symbol,
|
1082
|
+
valueOnError: valueOnError,
|
1083
|
+
postFormatFunction: p.postFormatFunction
|
1084
|
+
};
|
1072
1085
|
|
1086
|
+
return formatDetails;
|
1073
1087
|
},
|
1074
1088
|
|
1075
|
-
toFixed: function(
|
1076
|
-
|
1077
|
-
return ( Math.round( Number(n) * Math.pow(10, precision) )/ Math.pow(10, precision) ).toFixed(precision);
|
1089
|
+
toFixed: function toFixed(n, precision) {
|
1090
|
+
return (Math.round(Number(n) * Math.pow(10, precision)) / Math.pow(10, precision)).toFixed(precision);
|
1078
1091
|
},
|
1079
1092
|
|
1080
|
-
getFormatter: function(p)
|
1081
|
-
{
|
1093
|
+
getFormatter: function getFormatter(p) {
|
1082
1094
|
var formatDetails = OSREC.CurrencyFormatter.getFormatDetails(p);
|
1083
|
-
|
1084
|
-
var pattern
|
1085
|
-
var decimal
|
1086
|
-
var group
|
1087
|
-
var symbol
|
1088
|
-
|
1095
|
+
|
1096
|
+
var pattern = formatDetails.pattern;
|
1097
|
+
var decimal = formatDetails.decimal;
|
1098
|
+
var group = formatDetails.group;
|
1099
|
+
var symbol = formatDetails.symbol;
|
1100
|
+
var valueOnError = formatDetails.valueOnError;
|
1101
|
+
var postFormatFunction = formatDetails.postFormatFunction;
|
1102
|
+
|
1089
1103
|
// encodePattern Function - returns a few simple characteristics of the pattern provided
|
1090
|
-
|
1091
|
-
var encodePattern = function(pattern)
|
1092
|
-
{
|
1104
|
+
|
1105
|
+
var encodePattern = function encodePattern(pattern) {
|
1093
1106
|
var numberFormatPattern = pattern.trim().match(/[#0,\.]+/)[0];
|
1094
|
-
|
1107
|
+
|
1095
1108
|
var split = numberFormatPattern.split('.');
|
1096
1109
|
var c = split[0]; // Decimal chars
|
1097
1110
|
var m = split[1]; // Decimal mantissa
|
1098
|
-
|
1099
|
-
var groups
|
1100
|
-
var groupLengths
|
1101
|
-
|
1102
|
-
|
1103
|
-
var
|
1104
|
-
|
1105
|
-
var
|
1106
|
-
|
1111
|
+
|
1112
|
+
var groups = c.split(',');
|
1113
|
+
var groupLengths = groups.map(function (g) {
|
1114
|
+
return g.length;
|
1115
|
+
});
|
1116
|
+
var zeroLength = (groups[groups.length - 1].match(/0/g) || []).length;
|
1117
|
+
var decimalPlaces = typeof m === 'undefined' ? 0 : m.length;
|
1118
|
+
var paddingSplit = pattern.split(numberFormatPattern);
|
1119
|
+
|
1120
|
+
var encodedPattern = {
|
1107
1121
|
pattern: pattern,
|
1108
1122
|
decimalPlaces: decimalPlaces,
|
1109
1123
|
frontPadding: paddingSplit[0],
|
@@ -1113,20 +1127,18 @@ OSREC.CurrencyFormatter =
|
|
1113
1127
|
};
|
1114
1128
|
|
1115
1129
|
return encodedPattern;
|
1116
|
-
}
|
1130
|
+
};
|
1117
1131
|
|
1118
1132
|
// Zero Padding helper function
|
1119
1133
|
|
1120
|
-
var pad = function(n, width)
|
1121
|
-
{
|
1134
|
+
var pad = function pad(n, width) {
|
1122
1135
|
n = n + '';
|
1123
1136
|
return n.length >= width ? n : new Array(width - n.length + 1).join('0') + n;
|
1124
|
-
}
|
1137
|
+
};
|
1125
1138
|
|
1126
1139
|
// Format function
|
1127
1140
|
|
1128
|
-
var format = function(n, f)
|
1129
|
-
{
|
1141
|
+
var format = function format(n, f) {
|
1130
1142
|
var formattedNumber = OSREC.CurrencyFormatter.toFixed(Math.abs(n), f.decimalPlaces);
|
1131
1143
|
|
1132
1144
|
var splitNumber = formattedNumber.split(".");
|
@@ -1139,15 +1151,15 @@ OSREC.CurrencyFormatter =
|
|
1139
1151
|
|
1140
1152
|
var groupIndex = maxGroupIndex;
|
1141
1153
|
|
1142
|
-
if(maxGroupIndex > 0)
|
1143
|
-
|
1144
|
-
|
1145
|
-
|
1146
|
-
|
1154
|
+
if (maxGroupIndex > 0) {
|
1155
|
+
while (cursor > 0) {
|
1156
|
+
if (groupIndex < 1) {
|
1157
|
+
groupIndex = 1;
|
1158
|
+
} // Always reset to the last group length (useful for big numbers)
|
1147
1159
|
|
1148
1160
|
var currentGroupLength = f.groupLengths[groupIndex];
|
1149
1161
|
|
1150
|
-
var start = cursor-currentGroupLength;
|
1162
|
+
var start = cursor - currentGroupLength;
|
1151
1163
|
|
1152
1164
|
segment = splitNumber[0].substring(start, cursor) + f.group + segment;
|
1153
1165
|
|
@@ -1155,20 +1167,19 @@ OSREC.CurrencyFormatter =
|
|
1155
1167
|
|
1156
1168
|
--groupIndex;
|
1157
1169
|
}
|
1158
|
-
|
1159
|
-
segment = segment.substring(0, segment.length-1);
|
1160
|
-
}
|
1161
|
-
else
|
1162
|
-
{
|
1170
|
+
|
1171
|
+
segment = segment.substring(0, segment.length - 1);
|
1172
|
+
} else {
|
1163
1173
|
segment = splitNumber[0];
|
1164
1174
|
}
|
1165
1175
|
|
1166
|
-
if(segment.length < f.zeroLength) {
|
1176
|
+
if (segment.length < f.zeroLength) {
|
1177
|
+
segment = pad(segment, f.zeroLength);
|
1178
|
+
}
|
1167
1179
|
|
1168
|
-
var formattedNumber = f.frontPadding + segment + (
|
1180
|
+
var formattedNumber = f.frontPadding + segment + (typeof splitNumber[1] === 'undefined' ? '' : f.decimal + splitNumber[1]) + f.backPadding;
|
1169
1181
|
|
1170
1182
|
return formattedNumber.replace(/\!/g, symbol);
|
1171
|
-
|
1172
1183
|
};
|
1173
1184
|
|
1174
1185
|
// Use encode function to work out pattern
|
@@ -1189,92 +1200,83 @@ OSREC.CurrencyFormatter =
|
|
1189
1200
|
|
1190
1201
|
var zero = typeof patternArray[2] === 'undefined' ? format(0, positiveFormat) : patternArray[2];
|
1191
1202
|
|
1192
|
-
return function(n)
|
1193
|
-
|
1203
|
+
return function (n) {
|
1204
|
+
if (isNaN(n)) {
|
1205
|
+
return valueOnError;
|
1206
|
+
}
|
1194
1207
|
var formattedNumber;
|
1195
1208
|
n = Number(n);
|
1196
|
-
if(n > 0) {
|
1197
|
-
|
1198
|
-
else
|
1199
|
-
|
1209
|
+
if (n > 0) {
|
1210
|
+
formattedNumber = format(n, positiveFormat);
|
1211
|
+
} else if (n == 0) {
|
1212
|
+
formattedNumber = zero.replace('!', symbol);
|
1213
|
+
} else {
|
1214
|
+
formattedNumber = format(n, negativeFormat);
|
1215
|
+
}
|
1216
|
+
return typeof postFormatFunction === 'function' ? postFormatFunction(n, formattedNumber) : formattedNumber;
|
1200
1217
|
};
|
1201
|
-
|
1202
1218
|
},
|
1203
1219
|
|
1204
|
-
formatAll: function(p)
|
1205
|
-
{
|
1220
|
+
formatAll: function formatAll(p) {
|
1206
1221
|
var formatter = OSREC.CurrencyFormatter.getFormatter(p);
|
1207
1222
|
|
1208
1223
|
var matches = document.querySelectorAll(p.selector);
|
1209
1224
|
|
1210
|
-
for (var i = 0; i < matches.length; ++i)
|
1211
|
-
{
|
1225
|
+
for (var i = 0; i < matches.length; ++i) {
|
1212
1226
|
matches[i].innerHTML = formatter(matches[i].textContent);
|
1213
1227
|
}
|
1214
1228
|
},
|
1215
1229
|
|
1216
|
-
formatEach: function(selector)
|
1217
|
-
|
1218
|
-
var formatters = {}
|
1230
|
+
formatEach: function formatEach(selector) {
|
1231
|
+
var formatters = {};
|
1219
1232
|
|
1220
1233
|
var matches = document.querySelectorAll(selector);
|
1221
1234
|
|
1222
|
-
for (var i = 0; i < matches.length; ++i)
|
1223
|
-
|
1224
|
-
try
|
1225
|
-
{
|
1235
|
+
for (var i = 0; i < matches.length; ++i) {
|
1236
|
+
try {
|
1226
1237
|
|
1227
1238
|
var ccy = matches[i].getAttribute("data-ccy");
|
1228
1239
|
|
1229
|
-
if (typeof formatters[ccy] === 'undefined')
|
1230
|
-
|
1231
|
-
formatters[ccy] = OSREC.CurrencyFormatter.getFormatter({currency: ccy});
|
1240
|
+
if (typeof formatters[ccy] === 'undefined') {
|
1241
|
+
formatters[ccy] = OSREC.CurrencyFormatter.getFormatter({ currency: ccy });
|
1232
1242
|
}
|
1233
1243
|
|
1234
1244
|
var formatter = formatters[ccy];
|
1235
1245
|
|
1236
1246
|
matches[i].innerHTML = formatter(matches[i].textContent);
|
1237
|
-
}
|
1238
|
-
catch (e)
|
1239
|
-
{
|
1247
|
+
} catch (e) {
|
1240
1248
|
console.log(e);
|
1241
1249
|
}
|
1242
1250
|
}
|
1243
1251
|
},
|
1244
1252
|
|
1245
|
-
format: function(n, p)
|
1246
|
-
{
|
1253
|
+
format: function format(n, p) {
|
1247
1254
|
var formatterFunction = OSREC.CurrencyFormatter.getFormatter(p);
|
1248
1255
|
|
1249
1256
|
return formatterFunction(n);
|
1250
1257
|
},
|
1251
|
-
|
1252
|
-
parse: function(str, p)
|
1253
|
-
{
|
1258
|
+
|
1259
|
+
parse: function parse(str, p) {
|
1254
1260
|
var decimal = OSREC.CurrencyFormatter.getFormatDetails(p).decimal;
|
1255
1261
|
var mult = str.indexOf('-') >= 0 ? -1 : 1;
|
1256
|
-
return Math.abs(Number(str.replace(new RegExp(
|
1262
|
+
return Math.abs(Number(str.replace(new RegExp('[^0-9' + decimal + ']', 'g'), '').replace(decimal, '.'))) * mult;
|
1257
1263
|
}
|
1258
1264
|
};
|
1259
1265
|
|
1260
|
-
|
1261
1266
|
var hasDefine = typeof define === 'function';
|
1262
1267
|
var hasExports = typeof module !== 'undefined' && module.exports;
|
1263
|
-
var root =
|
1268
|
+
var root = typeof window === 'undefined' ? global : window;
|
1264
1269
|
|
1265
|
-
if (hasDefine)
|
1266
|
-
{
|
1270
|
+
if (hasDefine) {
|
1267
1271
|
// AMD Module
|
1268
|
-
define([], function() {
|
1269
|
-
|
1270
|
-
|
1271
|
-
{
|
1272
|
+
define([], function () {
|
1273
|
+
return OSREC.CurrencyFormatter;
|
1274
|
+
});
|
1275
|
+
} else if (hasExports) {
|
1272
1276
|
// Node.js Module
|
1273
|
-
|
1274
|
-
}
|
1275
|
-
else
|
1276
|
-
{
|
1277
|
+
module.exports = OSREC.CurrencyFormatter;
|
1278
|
+
} else {
|
1277
1279
|
// Assign to the global object
|
1278
1280
|
// This makes sure that the object really is assigned to the global scope
|
1279
|
-
|
1280
|
-
}
|
1281
|
+
root.OSREC = OSREC;
|
1282
|
+
}
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: currencyFormatter-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- tanvir hasan
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-07-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -51,6 +51,7 @@ files:
|
|
51
51
|
- ".gitmodules"
|
52
52
|
- ".rspec"
|
53
53
|
- ".travis.yml"
|
54
|
+
- CHANGELOG.md
|
54
55
|
- CODE_OF_CONDUCT.md
|
55
56
|
- CurrencyFormatter-rails.gemspec
|
56
57
|
- Gemfile
|