globalize-rpk 1.7.0 → 1.7.1
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/globalize/currency.js +590 -0
- package/globalize/date.js +3139 -0
- package/globalize/globalize-runtime.js +326 -0
- package/globalize/globalize.js +507 -0
- package/globalize/message.js +2076 -0
- package/globalize/number.js +1727 -0
- package/globalize/plural.js +376 -0
- package/globalize/relative-time.js +203 -0
- package/globalize/unit.js +301 -0
- package/node-main.js +27 -0
- package/package.json +3 -26
- package/CONTRIBUTING.md +0 -5
- package/README.md +0 -818
- package/doc/api/core/constructor.md +0 -28
- package/doc/api/core/load.md +0 -96
- package/doc/api/core/locale.md +0 -43
- package/doc/api/currency/currency-formatter.md +0 -196
- package/doc/api/currency/currency-to-parts-formatter.md +0 -117
- package/doc/api/date/date-formatter.md +0 -203
- package/doc/api/date/date-parser.md +0 -60
- package/doc/api/date/date-to-parts-formatter.md +0 -176
- package/doc/api/date/load-iana-time-zone.md +0 -29
- package/doc/api/message/load-messages.md +0 -105
- package/doc/api/message/message-formatter.md +0 -208
- package/doc/api/number/number-formatter.md +0 -202
- package/doc/api/number/number-parser.md +0 -130
- package/doc/api/number/number-to-parts-formatter.md +0 -140
- package/doc/api/plural/plural-generator.md +0 -84
- package/doc/api/relative-time/relative-time-formatter.md +0 -60
- package/doc/api/unit/unit-formatter.md +0 -72
- package/doc/blog-post/2017-07-xx-1.3.0-announcement.md +0 -177
- package/doc/cldr.md +0 -114
- package/doc/error/e-default-locale-not-defined.md +0 -9
- package/doc/error/e-invalid-cldr.md +0 -14
- package/doc/error/e-invalid-par-type.md +0 -12
- package/doc/error/e-invalid-par-value.md +0 -11
- package/doc/error/e-missing-cldr.md +0 -11
- package/doc/error/e-missing-parameter.md +0 -10
- package/doc/error/e-missing-plural-module.md +0 -9
- package/doc/error/e-par-missing-key.md +0 -11
- package/doc/error/e-par-out-of-range.md +0 -13
- package/doc/error/e-unsupported.md +0 -10
- package/doc/migrating-from-0.x.md +0 -64
- package/examples/amd-bower/.bowerrc +0 -7
- package/examples/amd-bower/README.md +0 -65
- package/examples/amd-bower/bower.json +0 -13
- package/examples/amd-bower/index.html +0 -46
- package/examples/amd-bower/main.js +0 -141
- package/examples/amd-bower/messages/en.json +0 -12
- package/examples/amd-bower/package.json +0 -14
- package/examples/app-npm-webpack/README.md +0 -74
- package/examples/app-npm-webpack/app/index.js +0 -89
- package/examples/app-npm-webpack/index-template.html +0 -71
- package/examples/app-npm-webpack/messages/ar.json +0 -25
- package/examples/app-npm-webpack/messages/de.json +0 -21
- package/examples/app-npm-webpack/messages/en.json +0 -21
- package/examples/app-npm-webpack/messages/es.json +0 -21
- package/examples/app-npm-webpack/messages/pt.json +0 -21
- package/examples/app-npm-webpack/messages/ru.json +0 -23
- package/examples/app-npm-webpack/messages/zh.json +0 -20
- package/examples/app-npm-webpack/package.json +0 -17
- package/examples/app-npm-webpack/webpack-config.js +0 -63
- package/examples/globalize-compiler/README.md +0 -45
- package/examples/globalize-compiler/app.js +0 -58
- package/examples/globalize-compiler/development.html +0 -121
- package/examples/globalize-compiler/messages.json +0 -12
- package/examples/globalize-compiler/package.json +0 -15
- package/examples/globalize-compiler/production.html +0 -75
- package/examples/node-npm/README.md +0 -57
- package/examples/node-npm/main.js +0 -65
- package/examples/node-npm/messages/en.json +0 -12
- package/examples/node-npm/package.json +0 -10
- package/examples/plain-javascript/README.md +0 -81
- package/examples/plain-javascript/index.html +0 -445
@@ -0,0 +1,590 @@
|
|
1
|
+
/*!
|
2
|
+
* Globalize v1.7.0
|
3
|
+
*
|
4
|
+
* https://github.com/globalizejs/globalize
|
5
|
+
*
|
6
|
+
* Copyright OpenJS Foundation and other contributors
|
7
|
+
* Released under the MIT license
|
8
|
+
* https://jquery.org/license
|
9
|
+
*
|
10
|
+
* Date: 2021-08-02T11:53Z
|
11
|
+
*/
|
12
|
+
(function( root, factory ) {
|
13
|
+
|
14
|
+
// UMD returnExports
|
15
|
+
if ( typeof define === "function" && define.amd ) {
|
16
|
+
|
17
|
+
// AMD
|
18
|
+
define([
|
19
|
+
"cldr",
|
20
|
+
"../globalize",
|
21
|
+
"./number",
|
22
|
+
"cldr/event",
|
23
|
+
"cldr/supplemental"
|
24
|
+
], factory );
|
25
|
+
} else if ( typeof exports === "object" ) {
|
26
|
+
|
27
|
+
// Node, CommonJS
|
28
|
+
module.exports = factory( require( "cldrjs" ), require( "../globalize" ) );
|
29
|
+
} else {
|
30
|
+
|
31
|
+
// Global
|
32
|
+
factory( root.Cldr, root.Globalize );
|
33
|
+
}
|
34
|
+
}(this, function( Cldr, Globalize ) {
|
35
|
+
|
36
|
+
var alwaysArray = Globalize._alwaysArray,
|
37
|
+
createError = Globalize._createError,
|
38
|
+
formatMessageToParts = Globalize._formatMessageToParts,
|
39
|
+
numberNumberingSystem = Globalize._numberNumberingSystem,
|
40
|
+
numberPattern = Globalize._numberPattern,
|
41
|
+
partsJoin = Globalize._partsJoin,
|
42
|
+
partsPush = Globalize._partsPush,
|
43
|
+
runtimeBind = Globalize._runtimeBind,
|
44
|
+
stringPad = Globalize._stringPad,
|
45
|
+
validateCldr = Globalize._validateCldr,
|
46
|
+
validateDefaultLocale = Globalize._validateDefaultLocale,
|
47
|
+
validateParameterPresence = Globalize._validateParameterPresence,
|
48
|
+
validateParameterType = Globalize._validateParameterType,
|
49
|
+
validateParameterTypeNumber = Globalize._validateParameterTypeNumber,
|
50
|
+
validateParameterTypePlainObject = Globalize._validateParameterTypePlainObject;
|
51
|
+
|
52
|
+
|
53
|
+
var createErrorPluralModulePresence = function() {
|
54
|
+
return createError( "E_MISSING_PLURAL_MODULE", "Plural module not loaded." );
|
55
|
+
};
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
|
60
|
+
var validateParameterTypeCurrency = function( value, name ) {
|
61
|
+
validateParameterType(
|
62
|
+
value,
|
63
|
+
name,
|
64
|
+
value === undefined || typeof value === "string" && ( /^[A-Za-z]{3}$/ ).test( value ),
|
65
|
+
"3-letter currency code string as defined by ISO 4217"
|
66
|
+
);
|
67
|
+
};
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
|
72
|
+
var currencyFormatterFn = function( currencyToPartsFormatter ) {
|
73
|
+
return function currencyFormatter( value ) {
|
74
|
+
return partsJoin( currencyToPartsFormatter( value ));
|
75
|
+
};
|
76
|
+
};
|
77
|
+
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
/**
|
82
|
+
* supplementalOverride( currency, pattern, cldr )
|
83
|
+
*
|
84
|
+
* Return pattern with fraction digits overriden by supplemental currency data.
|
85
|
+
*/
|
86
|
+
var currencySupplementalOverride = function( currency, pattern, cldr ) {
|
87
|
+
var digits,
|
88
|
+
fraction = "",
|
89
|
+
fractionData = cldr.supplemental([ "currencyData/fractions", currency ]) ||
|
90
|
+
cldr.supplemental( "currencyData/fractions/DEFAULT" );
|
91
|
+
|
92
|
+
digits = +fractionData._digits;
|
93
|
+
|
94
|
+
if ( digits ) {
|
95
|
+
fraction = "." + stringPad( "0", digits ).slice( 0, -1 ) + fractionData._rounding;
|
96
|
+
}
|
97
|
+
|
98
|
+
return pattern.replace( /\.(#+|0*[0-9]|0+[0-9]?)/g, fraction );
|
99
|
+
};
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
|
104
|
+
var objectFilter = function( object, testRe ) {
|
105
|
+
var key,
|
106
|
+
copy = {};
|
107
|
+
|
108
|
+
for ( key in object ) {
|
109
|
+
if ( testRe.test( key ) ) {
|
110
|
+
copy[ key ] = object[ key ];
|
111
|
+
}
|
112
|
+
}
|
113
|
+
|
114
|
+
return copy;
|
115
|
+
};
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
|
120
|
+
var currencyUnitPatterns = function( cldr ) {
|
121
|
+
return objectFilter( cldr.main([
|
122
|
+
"numbers",
|
123
|
+
"currencyFormats-numberSystem-" + numberNumberingSystem( cldr )
|
124
|
+
]), /^unitPattern/ );
|
125
|
+
};
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
|
130
|
+
/**
|
131
|
+
* nameProperties( currency, cldr )
|
132
|
+
*
|
133
|
+
* Return number pattern with the appropriate currency code in as literal.
|
134
|
+
*/
|
135
|
+
var currencyNameProperties = function( currency, cldr ) {
|
136
|
+
var pattern = numberPattern( "decimal", cldr );
|
137
|
+
|
138
|
+
// The number of decimal places and the rounding for each currency is not locale-specific. Those
|
139
|
+
// values overridden by Supplemental Currency Data.
|
140
|
+
pattern = currencySupplementalOverride( currency, pattern, cldr );
|
141
|
+
|
142
|
+
return {
|
143
|
+
displayNames: objectFilter( cldr.main([
|
144
|
+
"numbers/currencies",
|
145
|
+
currency
|
146
|
+
]), /^displayName/ ),
|
147
|
+
pattern: pattern,
|
148
|
+
unitPatterns: currencyUnitPatterns( cldr )
|
149
|
+
};
|
150
|
+
};
|
151
|
+
|
152
|
+
|
153
|
+
|
154
|
+
|
155
|
+
/**
|
156
|
+
* Unicode regular expression for: everything except symbols from the category S
|
157
|
+
*
|
158
|
+
* Generated by:
|
159
|
+
*
|
160
|
+
* var s = regenerate()
|
161
|
+
* .addRange( 0x0, 0x10FFFF )
|
162
|
+
* .remove( require( "@unicode/unicode-13.0.0/General_Category/Math_Symbol/symbols" ) )
|
163
|
+
* .remove( require( "@unicode/unicode-13.0.0/General_Category/Currency_Symbol/symbols" ) )
|
164
|
+
* .remove( require( "@unicode/unicode-13.0.0/General_Category/Modifier_Symbol/symbols" ) )
|
165
|
+
* .remove( require( "@unicode/unicode-13.0.0/General_Category/Other_Symbol/symbols" ) )
|
166
|
+
*
|
167
|
+
* https://github.com/mathiasbynens/regenerate
|
168
|
+
* https://github.com/node-unicode/unicode-13.0.0
|
169
|
+
* http://www.unicode.org/reports/tr44/#General_Category_Values
|
170
|
+
*/
|
171
|
+
var regexpNotS = /[\0-#%-\*,-;\?-\]_a-\{\}\x7F-\xA1\xA7\xAA\xAB\xAD\xB2\xB3\xB5-\xB7\xB9-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0300-\u0374\u0376-\u0383\u0386-\u03F5\u03F7-\u0481\u0483-\u058C\u0590-\u0605\u0609\u060A\u060C\u060D\u0610-\u06DD\u06DF-\u06E8\u06EA-\u06FC\u06FF-\u07F5\u07F7-\u07FD\u0800-\u09F1\u09F4-\u09F9\u09FC-\u0AF0\u0AF2-\u0B6F\u0B71-\u0BF2\u0BFB-\u0C7E\u0C80-\u0D4E\u0D50-\u0D78\u0D7A-\u0E3E\u0E40-\u0F00\u0F04-\u0F12\u0F14\u0F18\u0F19\u0F20-\u0F33\u0F35\u0F37\u0F39-\u0FBD\u0FC6\u0FCD\u0FD0-\u0FD4\u0FD9-\u109D\u10A0-\u138F\u139A-\u166C\u166E-\u17DA\u17DC-\u193F\u1941-\u19DD\u1A00-\u1B60\u1B6B-\u1B73\u1B7D-\u1FBC\u1FBE\u1FC2-\u1FCC\u1FD0-\u1FDC\u1FE0-\u1FEC\u1FF0-\u1FFC\u1FFF-\u2043\u2045-\u2051\u2053-\u2079\u207D-\u2089\u208D-\u209F\u20C0-\u20FF\u2102\u2107\u210A-\u2113\u2115\u2119-\u211D\u2124\u2126\u2128\u212A-\u212D\u212F-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2150-\u2189\u218C-\u218F\u2308-\u230B\u2329\u232A\u2427-\u243F\u244B-\u249B\u24EA-\u24FF\u2768-\u2793\u27C5\u27C6\u27E6-\u27EF\u2983-\u2998\u29D8-\u29DB\u29FC\u29FD\u2B74\u2B75\u2B96\u2C00-\u2CE4\u2CEB-\u2E4F\u2E52-\u2E7F\u2E9A\u2EF4-\u2EFF\u2FD6-\u2FEF\u2FFC-\u3003\u3005-\u3011\u3014-\u301F\u3021-\u3035\u3038-\u303D\u3040-\u309A\u309D-\u318F\u3192-\u3195\u31A0-\u31BF\u31E4-\u31FF\u321F-\u3229\u3248-\u324F\u3251-\u325F\u3280-\u3289\u32B1-\u32BF\u3400-\u4DBF\u4E00-\uA48F\uA4C7-\uA6FF\uA717-\uA71F\uA722-\uA788\uA78B-\uA827\uA82C-\uA835\uA83A-\uAA76\uAA7A-\uAB5A\uAB5C-\uAB69\uAB6C-\uD7FF\uE000-\uFB28\uFB2A-\uFBB1\uFBC2-\uFDFB\uFDFE-\uFE61\uFE63\uFE67\uFE68\uFE6A-\uFF03\uFF05-\uFF0A\uFF0C-\uFF1B\uFF1F-\uFF3D\uFF3F\uFF41-\uFF5B\uFF5D\uFF5F-\uFFDF\uFFE7\uFFEF-\uFFFB\uFFFE\uFFFF]|\uD800[\uDC00-\uDD36\uDD40-\uDD78\uDD8A\uDD8B\uDD8F\uDD9D-\uDD9F\uDDA1-\uDDCF\uDDFD-\uDFFF]|[\uD801\uD803\uD804\uD806\uD808-\uD819\uD81B-\uD82E\uD830-\uD833\uD837\uD839\uD83A\uD83F-\uDBFF][\uDC00-\uDFFF]|\uD802[\uDC00-\uDC76\uDC79-\uDEC7\uDEC9-\uDFFF]|\uD805[\uDC00-\uDF3E\uDF40-\uDFFF]|\uD807[\uDC00-\uDFD4\uDFF2-\uDFFF]|\uD81A[\uDC00-\uDF3B\uDF40-\uDF44\uDF46-\uDFFF]|\uD82F[\uDC00-\uDC9B\uDC9D-\uDFFF]|\uD834[\uDCF6-\uDCFF\uDD27\uDD28\uDD65-\uDD69\uDD6D-\uDD82\uDD85-\uDD8B\uDDAA-\uDDAD\uDDE9-\uDDFF\uDE42-\uDE44\uDE46-\uDEFF\uDF57-\uDFFF]|\uD835[\uDC00-\uDEC0\uDEC2-\uDEDA\uDEDC-\uDEFA\uDEFC-\uDF14\uDF16-\uDF34\uDF36-\uDF4E\uDF50-\uDF6E\uDF70-\uDF88\uDF8A-\uDFA8\uDFAA-\uDFC2\uDFC4-\uDFFF]|\uD836[\uDE00-\uDE36\uDE3B-\uDE6C\uDE75\uDE84\uDE87-\uDFFF]|\uD838[\uDC00-\uDD4E\uDD50-\uDEFE\uDF00-\uDFFF]|\uD83B[\uDC00-\uDCAB\uDCAD-\uDCAF\uDCB1-\uDD2D\uDD2F-\uDEEF\uDEF2-\uDFFF]|\uD83C[\uDC2C-\uDC2F\uDC94-\uDC9F\uDCAF\uDCB0\uDCC0\uDCD0\uDCF6-\uDD0C\uDDAE-\uDDE5\uDE03-\uDE0F\uDE3C-\uDE3F\uDE49-\uDE4F\uDE52-\uDE5F\uDE66-\uDEFF]|\uD83D[\uDED8-\uDEDF\uDEED-\uDEEF\uDEFD-\uDEFF\uDF74-\uDF7F\uDFD9-\uDFDF\uDFEC-\uDFFF]|\uD83E[\uDC0C-\uDC0F\uDC48-\uDC4F\uDC5A-\uDC5F\uDC88-\uDC8F\uDCAE\uDCAF\uDCB2-\uDCFF\uDD79\uDDCC\uDE54-\uDE5F\uDE6E\uDE6F\uDE75-\uDE77\uDE7B-\uDE7F\uDE87-\uDE8F\uDEA9-\uDEAF\uDEB7-\uDEBF\uDEC3-\uDECF\uDED7-\uDEFF\uDF93\uDFCB-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]/;
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
|
176
|
+
/**
|
177
|
+
* Unicode regular expression for: everything except symbols from categories S and Z
|
178
|
+
*
|
179
|
+
* Generated by:
|
180
|
+
*
|
181
|
+
* var s = regenerate()
|
182
|
+
* .addRange( 0x0, 0x10FFFF )
|
183
|
+
* .remove( require( "@unicode/unicode-13.0.0/General_Category/Math_Symbol/symbols" ) )
|
184
|
+
* .remove( require( "@unicode/unicode-13.0.0/General_Category/Currency_Symbol/symbols" ) )
|
185
|
+
* .remove( require( "@unicode/unicode-13.0.0/General_Category/Modifier_Symbol/symbols" ) )
|
186
|
+
* .remove( require( "@unicode/unicode-13.0.0/General_Category/Other_Symbol/symbols" ) )
|
187
|
+
* .remove( require( "@unicode/unicode-13.0.0/General_Category/Space_Separator/symbols" ) )
|
188
|
+
* .remove( require( "@unicode/unicode-13.0.0/General_Category/Line_Separator/symbols" ) )
|
189
|
+
* .remove( require( "@unicode/unicode-13.0.0/General_Category/Paragraph_Separator/symbols" ) );
|
190
|
+
*
|
191
|
+
* https://github.com/mathiasbynens/regenerate
|
192
|
+
* https://github.com/node-unicode/unicode-13.0.0
|
193
|
+
* http://www.unicode.org/reports/tr44/#General_Category_Values
|
194
|
+
*/
|
195
|
+
var regexpNotSAndZ = /[\0-\x1F!-#%-\*,-;\?-\]_a-\{\}\x7F-\x9F\xA1\xA7\xAA\xAB\xAD\xB2\xB3\xB5-\xB7\xB9-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0300-\u0374\u0376-\u0383\u0386-\u03F5\u03F7-\u0481\u0483-\u058C\u0590-\u0605\u0609\u060A\u060C\u060D\u0610-\u06DD\u06DF-\u06E8\u06EA-\u06FC\u06FF-\u07F5\u07F7-\u07FD\u0800-\u09F1\u09F4-\u09F9\u09FC-\u0AF0\u0AF2-\u0B6F\u0B71-\u0BF2\u0BFB-\u0C7E\u0C80-\u0D4E\u0D50-\u0D78\u0D7A-\u0E3E\u0E40-\u0F00\u0F04-\u0F12\u0F14\u0F18\u0F19\u0F20-\u0F33\u0F35\u0F37\u0F39-\u0FBD\u0FC6\u0FCD\u0FD0-\u0FD4\u0FD9-\u109D\u10A0-\u138F\u139A-\u166C\u166E-\u167F\u1681-\u17DA\u17DC-\u193F\u1941-\u19DD\u1A00-\u1B60\u1B6B-\u1B73\u1B7D-\u1FBC\u1FBE\u1FC2-\u1FCC\u1FD0-\u1FDC\u1FE0-\u1FEC\u1FF0-\u1FFC\u1FFF\u200B-\u2027\u202A-\u202E\u2030-\u2043\u2045-\u2051\u2053-\u205E\u2060-\u2079\u207D-\u2089\u208D-\u209F\u20C0-\u20FF\u2102\u2107\u210A-\u2113\u2115\u2119-\u211D\u2124\u2126\u2128\u212A-\u212D\u212F-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2150-\u2189\u218C-\u218F\u2308-\u230B\u2329\u232A\u2427-\u243F\u244B-\u249B\u24EA-\u24FF\u2768-\u2793\u27C5\u27C6\u27E6-\u27EF\u2983-\u2998\u29D8-\u29DB\u29FC\u29FD\u2B74\u2B75\u2B96\u2C00-\u2CE4\u2CEB-\u2E4F\u2E52-\u2E7F\u2E9A\u2EF4-\u2EFF\u2FD6-\u2FEF\u2FFC-\u2FFF\u3001-\u3003\u3005-\u3011\u3014-\u301F\u3021-\u3035\u3038-\u303D\u3040-\u309A\u309D-\u318F\u3192-\u3195\u31A0-\u31BF\u31E4-\u31FF\u321F-\u3229\u3248-\u324F\u3251-\u325F\u3280-\u3289\u32B1-\u32BF\u3400-\u4DBF\u4E00-\uA48F\uA4C7-\uA6FF\uA717-\uA71F\uA722-\uA788\uA78B-\uA827\uA82C-\uA835\uA83A-\uAA76\uAA7A-\uAB5A\uAB5C-\uAB69\uAB6C-\uD7FF\uE000-\uFB28\uFB2A-\uFBB1\uFBC2-\uFDFB\uFDFE-\uFE61\uFE63\uFE67\uFE68\uFE6A-\uFF03\uFF05-\uFF0A\uFF0C-\uFF1B\uFF1F-\uFF3D\uFF3F\uFF41-\uFF5B\uFF5D\uFF5F-\uFFDF\uFFE7\uFFEF-\uFFFB\uFFFE\uFFFF]|\uD800[\uDC00-\uDD36\uDD40-\uDD78\uDD8A\uDD8B\uDD8F\uDD9D-\uDD9F\uDDA1-\uDDCF\uDDFD-\uDFFF]|[\uD801\uD803\uD804\uD806\uD808-\uD819\uD81B-\uD82E\uD830-\uD833\uD837\uD839\uD83A\uD83F-\uDBFF][\uDC00-\uDFFF]|\uD802[\uDC00-\uDC76\uDC79-\uDEC7\uDEC9-\uDFFF]|\uD805[\uDC00-\uDF3E\uDF40-\uDFFF]|\uD807[\uDC00-\uDFD4\uDFF2-\uDFFF]|\uD81A[\uDC00-\uDF3B\uDF40-\uDF44\uDF46-\uDFFF]|\uD82F[\uDC00-\uDC9B\uDC9D-\uDFFF]|\uD834[\uDCF6-\uDCFF\uDD27\uDD28\uDD65-\uDD69\uDD6D-\uDD82\uDD85-\uDD8B\uDDAA-\uDDAD\uDDE9-\uDDFF\uDE42-\uDE44\uDE46-\uDEFF\uDF57-\uDFFF]|\uD835[\uDC00-\uDEC0\uDEC2-\uDEDA\uDEDC-\uDEFA\uDEFC-\uDF14\uDF16-\uDF34\uDF36-\uDF4E\uDF50-\uDF6E\uDF70-\uDF88\uDF8A-\uDFA8\uDFAA-\uDFC2\uDFC4-\uDFFF]|\uD836[\uDE00-\uDE36\uDE3B-\uDE6C\uDE75\uDE84\uDE87-\uDFFF]|\uD838[\uDC00-\uDD4E\uDD50-\uDEFE\uDF00-\uDFFF]|\uD83B[\uDC00-\uDCAB\uDCAD-\uDCAF\uDCB1-\uDD2D\uDD2F-\uDEEF\uDEF2-\uDFFF]|\uD83C[\uDC2C-\uDC2F\uDC94-\uDC9F\uDCAF\uDCB0\uDCC0\uDCD0\uDCF6-\uDD0C\uDDAE-\uDDE5\uDE03-\uDE0F\uDE3C-\uDE3F\uDE49-\uDE4F\uDE52-\uDE5F\uDE66-\uDEFF]|\uD83D[\uDED8-\uDEDF\uDEED-\uDEEF\uDEFD-\uDEFF\uDF74-\uDF7F\uDFD9-\uDFDF\uDFEC-\uDFFF]|\uD83E[\uDC0C-\uDC0F\uDC48-\uDC4F\uDC5A-\uDC5F\uDC88-\uDC8F\uDCAE\uDCAF\uDCB2-\uDCFF\uDD79\uDDCC\uDE54-\uDE5F\uDE6E\uDE6F\uDE75-\uDE77\uDE7B-\uDE7F\uDE87-\uDE8F\uDEA9-\uDEAF\uDEB7-\uDEBF\uDEC3-\uDECF\uDED7-\uDEFF\uDF93\uDFCB-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]/;
|
196
|
+
|
197
|
+
|
198
|
+
|
199
|
+
|
200
|
+
/**
|
201
|
+
* symbolProperties( currency, cldr )
|
202
|
+
*
|
203
|
+
* Return pattern replacing `¤` with the appropriate currency symbol literal.
|
204
|
+
*/
|
205
|
+
var currencySymbolProperties = function( currency, cldr, options ) {
|
206
|
+
var currencySpacing, pattern, symbol, symbolEntries,
|
207
|
+
regexp = {
|
208
|
+
"[:digit:]": /\d/,
|
209
|
+
"[:^S:]": regexpNotS,
|
210
|
+
"[[:^S:]&[:^Z:]]": regexpNotSAndZ
|
211
|
+
};
|
212
|
+
|
213
|
+
if ( options.style === "code" ) {
|
214
|
+
symbol = currency;
|
215
|
+
} else {
|
216
|
+
symbolEntries = [ "symbol" ];
|
217
|
+
|
218
|
+
// If options.symbolForm === "narrow" was passed, prepend it.
|
219
|
+
if ( options.symbolForm === "narrow" ) {
|
220
|
+
symbolEntries.unshift( "symbol-alt-narrow" );
|
221
|
+
}
|
222
|
+
|
223
|
+
symbolEntries.some(function( symbolEntry ) {
|
224
|
+
return symbol = cldr.main([
|
225
|
+
"numbers/currencies",
|
226
|
+
currency,
|
227
|
+
symbolEntry
|
228
|
+
]);
|
229
|
+
});
|
230
|
+
}
|
231
|
+
|
232
|
+
currencySpacing = [ "beforeCurrency", "afterCurrency" ].map(function( position ) {
|
233
|
+
return cldr.main([
|
234
|
+
"numbers",
|
235
|
+
"currencyFormats-numberSystem-" + numberNumberingSystem( cldr ),
|
236
|
+
"currencySpacing",
|
237
|
+
position
|
238
|
+
]);
|
239
|
+
});
|
240
|
+
|
241
|
+
pattern = cldr.main([
|
242
|
+
"numbers",
|
243
|
+
"currencyFormats-numberSystem-" + numberNumberingSystem( cldr ),
|
244
|
+
options.style === "accounting" ? "accounting" : "standard"
|
245
|
+
]);
|
246
|
+
|
247
|
+
pattern =
|
248
|
+
|
249
|
+
// The number of decimal places and the rounding for each currency is not locale-specific.
|
250
|
+
// Those values are overridden by Supplemental Currency Data.
|
251
|
+
currencySupplementalOverride( currency, pattern, cldr )
|
252
|
+
|
253
|
+
// Replace "¤" (\u00A4) with the appropriate symbol literal.
|
254
|
+
.split( ";" ).map(function( pattern ) {
|
255
|
+
|
256
|
+
return pattern.split( "\u00A4" ).map(function( part, i ) {
|
257
|
+
var currencyMatch = regexp[ currencySpacing[ i ].currencyMatch ],
|
258
|
+
surroundingMatch = regexp[ currencySpacing[ i ].surroundingMatch ],
|
259
|
+
insertBetween = "";
|
260
|
+
|
261
|
+
// For currencyMatch and surroundingMatch definitions, read [1].
|
262
|
+
// When i === 0, beforeCurrency is being handled. Otherwise, afterCurrency.
|
263
|
+
// 1: http://www.unicode.org/reports/tr35/tr35-numbers.html#Currencies
|
264
|
+
currencyMatch = currencyMatch.test( symbol.charAt( i ? symbol.length - 1 : 0 ) );
|
265
|
+
surroundingMatch = surroundingMatch.test(
|
266
|
+
part.charAt( i ? 0 : part.length - 1 ).replace( /[#@,.]/g, "0" )
|
267
|
+
);
|
268
|
+
|
269
|
+
if ( currencyMatch && part && surroundingMatch ) {
|
270
|
+
insertBetween = currencySpacing[ i ].insertBetween;
|
271
|
+
}
|
272
|
+
|
273
|
+
return ( i ? insertBetween : "" ) + part + ( i ? "" : insertBetween );
|
274
|
+
}).join( "\u00A4" );
|
275
|
+
}).join( ";" );
|
276
|
+
|
277
|
+
return {
|
278
|
+
pattern: pattern,
|
279
|
+
symbol: symbol
|
280
|
+
};
|
281
|
+
};
|
282
|
+
|
283
|
+
|
284
|
+
|
285
|
+
|
286
|
+
/**
|
287
|
+
* nameFormat( formattedNumber, pluralForm, properties )
|
288
|
+
*
|
289
|
+
* Return the appropriate name form currency format.
|
290
|
+
*/
|
291
|
+
var currencyNameFormat = function( formattedNumber, pluralForm, properties ) {
|
292
|
+
var displayName, unitPattern,
|
293
|
+
parts = [],
|
294
|
+
displayNames = properties.displayNames || {},
|
295
|
+
unitPatterns = properties.unitPatterns;
|
296
|
+
|
297
|
+
displayName = displayNames[ "displayName-count-" + pluralForm ] ||
|
298
|
+
displayNames[ "displayName-count-other" ] ||
|
299
|
+
displayNames.displayName ||
|
300
|
+
properties.currency;
|
301
|
+
unitPattern = unitPatterns[ "unitPattern-count-" + pluralForm ] ||
|
302
|
+
unitPatterns[ "unitPattern-count-other" ];
|
303
|
+
|
304
|
+
formatMessageToParts( unitPattern, [ formattedNumber, displayName ]).forEach(function( part ) {
|
305
|
+
if ( part.type === "variable" && part.name === "0" ) {
|
306
|
+
part.value.forEach(function( part ) {
|
307
|
+
partsPush( parts, part.type, part.value );
|
308
|
+
});
|
309
|
+
} else if ( part.type === "variable" && part.name === "1" ) {
|
310
|
+
partsPush( parts, "currency", part.value );
|
311
|
+
} else {
|
312
|
+
partsPush( parts, "literal", part.value );
|
313
|
+
}
|
314
|
+
});
|
315
|
+
|
316
|
+
return parts;
|
317
|
+
};
|
318
|
+
|
319
|
+
|
320
|
+
|
321
|
+
|
322
|
+
/**
|
323
|
+
* symbolFormat( parts, symbol )
|
324
|
+
*
|
325
|
+
* Return the appropriate symbol/account form format.
|
326
|
+
*/
|
327
|
+
var currencySymbolFormat = function( parts, symbol ) {
|
328
|
+
parts.forEach(function( part ) {
|
329
|
+
if ( part.type === "currency" ) {
|
330
|
+
part.value = symbol;
|
331
|
+
}
|
332
|
+
});
|
333
|
+
return parts;
|
334
|
+
};
|
335
|
+
|
336
|
+
|
337
|
+
|
338
|
+
|
339
|
+
var currencyToPartsFormatterFn = function( numberToPartsFormatter, pluralGenerator, properties ) {
|
340
|
+
var fn;
|
341
|
+
|
342
|
+
// Return formatter when style is "name".
|
343
|
+
if ( pluralGenerator && properties ) {
|
344
|
+
fn = function currencyToPartsFormatter( value ) {
|
345
|
+
validateParameterPresence( value, "value" );
|
346
|
+
validateParameterTypeNumber( value, "value" );
|
347
|
+
return currencyNameFormat(
|
348
|
+
numberToPartsFormatter( value ),
|
349
|
+
pluralGenerator( value ),
|
350
|
+
properties
|
351
|
+
);
|
352
|
+
};
|
353
|
+
|
354
|
+
// Return formatter when style is "symbol", "accounting", or "code".
|
355
|
+
} else {
|
356
|
+
fn = function currencyToPartsFormatter( value ) {
|
357
|
+
|
358
|
+
// 1: Reusing pluralGenerator argument, but in this case it is actually `symbol`
|
359
|
+
return currencySymbolFormat( numberToPartsFormatter( value ), pluralGenerator /* 1 */ );
|
360
|
+
};
|
361
|
+
}
|
362
|
+
|
363
|
+
return fn;
|
364
|
+
};
|
365
|
+
|
366
|
+
|
367
|
+
|
368
|
+
|
369
|
+
/**
|
370
|
+
* objectOmit( object, keys )
|
371
|
+
*
|
372
|
+
* Return a copy of the object, filtered to omit the blacklisted key or array of keys.
|
373
|
+
*/
|
374
|
+
var objectOmit = function( object, keys ) {
|
375
|
+
var key,
|
376
|
+
copy = {};
|
377
|
+
|
378
|
+
keys = alwaysArray( keys );
|
379
|
+
|
380
|
+
for ( key in object ) {
|
381
|
+
if ( keys.indexOf( key ) === -1 ) {
|
382
|
+
copy[ key ] = object[ key ];
|
383
|
+
}
|
384
|
+
}
|
385
|
+
|
386
|
+
return copy;
|
387
|
+
};
|
388
|
+
|
389
|
+
|
390
|
+
|
391
|
+
|
392
|
+
function validateRequiredCldr( path, value ) {
|
393
|
+
validateCldr( path, value, {
|
394
|
+
skip: [
|
395
|
+
/numbers\/currencies\/[^/]+\/symbol-alt-/,
|
396
|
+
/supplemental\/currencyData\/fractions\/[A-Za-z]{3}$/
|
397
|
+
]
|
398
|
+
});
|
399
|
+
}
|
400
|
+
|
401
|
+
/**
|
402
|
+
* .currencyFormatter( currency [, options] )
|
403
|
+
*
|
404
|
+
* @currency [String] 3-letter currency code as defined by ISO 4217.
|
405
|
+
*
|
406
|
+
* @options [Object]:
|
407
|
+
* - style: [String] "symbol" (default), "accounting", "code" or "name".
|
408
|
+
* - see also number/format options.
|
409
|
+
*
|
410
|
+
* Return a function that formats a currency according to the given options and default/instance
|
411
|
+
* locale.
|
412
|
+
*/
|
413
|
+
Globalize.currencyFormatter =
|
414
|
+
Globalize.prototype.currencyFormatter = function( currency, options ) {
|
415
|
+
var args, currencyToPartsFormatter, returnFn;
|
416
|
+
|
417
|
+
validateParameterPresence( currency, "currency" );
|
418
|
+
validateParameterTypeCurrency( currency, "currency" );
|
419
|
+
|
420
|
+
validateParameterTypePlainObject( options, "options" );
|
421
|
+
|
422
|
+
options = options || {};
|
423
|
+
args = [ currency, options ];
|
424
|
+
|
425
|
+
currencyToPartsFormatter = this.currencyToPartsFormatter( currency, options );
|
426
|
+
returnFn = currencyFormatterFn( currencyToPartsFormatter );
|
427
|
+
runtimeBind( args, this.cldr, returnFn, [ currencyToPartsFormatter ] );
|
428
|
+
|
429
|
+
return returnFn;
|
430
|
+
};
|
431
|
+
|
432
|
+
/**
|
433
|
+
* .currencyToPartsFormatter( currency [, options] )
|
434
|
+
*
|
435
|
+
* @currency [String] 3-letter currency code as defined by ISO 4217.
|
436
|
+
*
|
437
|
+
* @options [Object]:
|
438
|
+
* - style: [String] "symbol" (default), "accounting", "code" or "name".
|
439
|
+
* - see also number/format options.
|
440
|
+
*
|
441
|
+
* Return a currency formatter function (of the form below) according to the given options and the
|
442
|
+
* default/instance locale.
|
443
|
+
*
|
444
|
+
* fn( value )
|
445
|
+
*
|
446
|
+
* @value [Number]
|
447
|
+
*
|
448
|
+
* Return a function that formats a currency to parts according to the given options
|
449
|
+
* and the default/instance locale.
|
450
|
+
*/
|
451
|
+
Globalize.currencyToPartsFormatter =
|
452
|
+
Globalize.prototype.currencyToPartsFormatter = function( currency, options ) {
|
453
|
+
var args, cldr, numberToPartsFormatter, pluralGenerator, properties, returnFn, style;
|
454
|
+
|
455
|
+
validateParameterPresence( currency, "currency" );
|
456
|
+
validateParameterTypeCurrency( currency, "currency" );
|
457
|
+
|
458
|
+
validateParameterTypePlainObject( options, "options" );
|
459
|
+
|
460
|
+
cldr = this.cldr;
|
461
|
+
options = options || {};
|
462
|
+
|
463
|
+
args = [ currency, options ];
|
464
|
+
style = options.style || "symbol";
|
465
|
+
|
466
|
+
validateDefaultLocale( cldr );
|
467
|
+
|
468
|
+
// Get properties given style ("symbol" default, "code" or "name").
|
469
|
+
cldr.on( "get", validateRequiredCldr );
|
470
|
+
try {
|
471
|
+
properties = ({
|
472
|
+
accounting: currencySymbolProperties,
|
473
|
+
code: currencySymbolProperties,
|
474
|
+
name: currencyNameProperties,
|
475
|
+
symbol: currencySymbolProperties
|
476
|
+
}[ style ] )( currency, cldr, options );
|
477
|
+
} finally {
|
478
|
+
cldr.off( "get", validateRequiredCldr );
|
479
|
+
}
|
480
|
+
|
481
|
+
// options = options minus style, plus raw pattern.
|
482
|
+
options = objectOmit( options, "style" );
|
483
|
+
options.raw = properties.pattern;
|
484
|
+
|
485
|
+
// Return formatter when style is "symbol", "accounting", or "code".
|
486
|
+
if ( style === "symbol" || style === "accounting" || style === "code" ) {
|
487
|
+
numberToPartsFormatter = this.numberToPartsFormatter( options );
|
488
|
+
|
489
|
+
returnFn = currencyToPartsFormatterFn( numberToPartsFormatter, properties.symbol );
|
490
|
+
|
491
|
+
runtimeBind( args, cldr, returnFn, [ numberToPartsFormatter, properties.symbol ] );
|
492
|
+
|
493
|
+
// Return formatter when style is "name".
|
494
|
+
} else {
|
495
|
+
numberToPartsFormatter = this.numberToPartsFormatter( options );
|
496
|
+
|
497
|
+
// Is plural module present? Yes, use its generator. Nope, use an error generator.
|
498
|
+
pluralGenerator = this.plural !== undefined ?
|
499
|
+
this.pluralGenerator() :
|
500
|
+
createErrorPluralModulePresence;
|
501
|
+
|
502
|
+
returnFn = currencyToPartsFormatterFn(
|
503
|
+
numberToPartsFormatter,
|
504
|
+
pluralGenerator,
|
505
|
+
properties
|
506
|
+
);
|
507
|
+
|
508
|
+
runtimeBind( args, cldr, returnFn, [
|
509
|
+
numberToPartsFormatter,
|
510
|
+
pluralGenerator,
|
511
|
+
properties
|
512
|
+
]);
|
513
|
+
}
|
514
|
+
|
515
|
+
return returnFn;
|
516
|
+
};
|
517
|
+
|
518
|
+
/**
|
519
|
+
* .currencyParser( currency [, options] )
|
520
|
+
*
|
521
|
+
* @currency [String] 3-letter currency code as defined by ISO 4217.
|
522
|
+
*
|
523
|
+
* @options [Object] see currencyFormatter.
|
524
|
+
*
|
525
|
+
* Return the currency parser according to the given options and the default/instance locale.
|
526
|
+
*/
|
527
|
+
Globalize.currencyParser =
|
528
|
+
Globalize.prototype.currencyParser = function( /* currency, options */ ) {
|
529
|
+
|
530
|
+
// TODO implement parser.
|
531
|
+
|
532
|
+
};
|
533
|
+
|
534
|
+
/**
|
535
|
+
* .formatCurrency( value, currency [, options] )
|
536
|
+
*
|
537
|
+
* @value [Number] number to be formatted.
|
538
|
+
*
|
539
|
+
* @currency [String] 3-letter currency code as defined by ISO 4217.
|
540
|
+
*
|
541
|
+
* @options [Object] see currencyFormatter.
|
542
|
+
*
|
543
|
+
* Format a currency according to the given options and the default/instance locale.
|
544
|
+
*/
|
545
|
+
Globalize.formatCurrency =
|
546
|
+
Globalize.prototype.formatCurrency = function( value, currency, options ) {
|
547
|
+
validateParameterPresence( value, "value" );
|
548
|
+
validateParameterTypeNumber( value, "value" );
|
549
|
+
return this.currencyFormatter( currency, options )( value );
|
550
|
+
};
|
551
|
+
|
552
|
+
/**
|
553
|
+
* .formatCurrencyToParts( value, currency [, options] )
|
554
|
+
*
|
555
|
+
* @value [Number] number to be formatted.
|
556
|
+
*
|
557
|
+
* @currency [String] 3-letter currency code as defined by ISO 4217.
|
558
|
+
*
|
559
|
+
* @options [Object] see currencyFormatter.
|
560
|
+
*
|
561
|
+
* Format a currency to parts according to the given options and the default/instance locale.
|
562
|
+
*/
|
563
|
+
Globalize.formatCurrencyToParts =
|
564
|
+
Globalize.prototype.formatCurrencyToParts = function( value, currency, options ) {
|
565
|
+
validateParameterPresence( value, "value" );
|
566
|
+
validateParameterTypeNumber( value, "value" );
|
567
|
+
return this.currencyToPartsFormatter( currency, options )( value );
|
568
|
+
};
|
569
|
+
|
570
|
+
/**
|
571
|
+
* .parseCurrency( value, currency [, options] )
|
572
|
+
*
|
573
|
+
* @value [String]
|
574
|
+
*
|
575
|
+
* @currency [String] 3-letter currency code as defined by ISO 4217.
|
576
|
+
*
|
577
|
+
* @options [Object]: See currencyFormatter.
|
578
|
+
*
|
579
|
+
* Return the parsed currency or NaN when value is invalid.
|
580
|
+
*/
|
581
|
+
Globalize.parseCurrency =
|
582
|
+
Globalize.prototype.parseCurrency = function( /* value, currency, options */ ) {
|
583
|
+
};
|
584
|
+
|
585
|
+
return Globalize;
|
586
|
+
|
587
|
+
|
588
|
+
|
589
|
+
|
590
|
+
}));
|