-
Notifications
You must be signed in to change notification settings - Fork 604
/
currency.js
119 lines (91 loc) · 2.86 KB
/
currency.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/**
* Globalize Runtime v1.2.2
*
* http://github.com/jquery/globalize
*
* Copyright jQuery Foundation and other contributors
* Released under the MIT license
* http://jquery.org/license
*
* Date: 2016-12-31T15:52Z
*/
/*!
* Globalize Runtime v1.2.2 2016-12-31T15:52Z Released under the MIT license
* http://git.io/TrdQbw
*/
(function( root, factory ) {
// UMD returnExports
if ( typeof define === "function" && define.amd ) {
// AMD
define([
"../globalize-runtime",
"./number"
], factory );
} else if ( typeof exports === "object" ) {
// Node, CommonJS
module.exports = factory(
require( "../globalize-runtime" ),
require( "./number" )
);
} else {
// Extend global
factory( root.Globalize );
}
}(this, function( Globalize ) {
var formatMessage = Globalize._formatMessage,
runtimeKey = Globalize._runtimeKey,
validateParameterPresence = Globalize._validateParameterPresence,
validateParameterTypeNumber = Globalize._validateParameterTypeNumber;
/**
* nameFormat( formattedNumber, pluralForm, properties )
*
* Return the appropriate name form currency format.
*/
var currencyNameFormat = function( formattedNumber, pluralForm, properties ) {
var displayName, unitPattern,
displayNames = properties.displayNames || {},
unitPatterns = properties.unitPatterns;
displayName = displayNames[ "displayName-count-" + pluralForm ] ||
displayNames[ "displayName-count-other" ] ||
displayNames.displayName ||
properties.currency;
unitPattern = unitPatterns[ "unitPattern-count-" + pluralForm ] ||
unitPatterns[ "unitPattern-count-other" ];
return formatMessage( unitPattern, [ formattedNumber, displayName ]);
};
var currencyFormatterFn = function( numberFormatter, pluralGenerator, properties ) {
var fn;
// Return formatter when style is "code" or "name".
if ( pluralGenerator && properties ) {
fn = function currencyFormatter( value ) {
validateParameterPresence( value, "value" );
validateParameterTypeNumber( value, "value" );
return currencyNameFormat(
numberFormatter( value ),
pluralGenerator( value ),
properties
);
};
// Return formatter when style is "symbol" or "accounting".
} else {
fn = function currencyFormatter( value ) {
return numberFormatter( value );
};
}
return fn;
};
Globalize._currencyFormatterFn = currencyFormatterFn;
Globalize._currencyNameFormat = currencyNameFormat;
Globalize.currencyFormatter =
Globalize.prototype.currencyFormatter = function( currency, options ) {
options = options || {};
return Globalize[ runtimeKey( "currencyFormatter", this._locale, [ currency, options ] ) ];
};
Globalize.formatCurrency =
Globalize.prototype.formatCurrency = function( value, currency, options ) {
validateParameterPresence( value, "value" );
validateParameterTypeNumber( value, "value" );
return this.currencyFormatter( currency, options )( value );
};
return Globalize;
}));