]>
git.wh0rd.org - tt-rss.git/blob - lib/dojo/currency.js.uncompressed.js
1 define("dojo/currency", [
4 /*===== "./_base/declare", =====*/
6 "./i18n", "./i18n!./cldr/nls/currency",
8 ], function(darray
, lang
, /*===== declare, =====*/ dnumber
, i18n
, nlsCurrency
, cldrMonetary
){
15 // localized formatting and parsing routines for currencies
17 // extends dojo.number to provide culturally-appropriate formatting of values
18 // in various world currencies, including use of a currency symbol. The currencies are specified
19 // by a three-letter international symbol in all uppercase, and support for the currencies is
20 // provided by the data in `dojo.cldr`. The scripts generating dojo.cldr specify which
21 // currency support is included. A fixed number of decimal places is determined based
22 // on the currency type and is not determined by the 'pattern' argument. The fractional
23 // portion is optional, by default, and variable length decimals are not supported.
25 lang
.setObject("dojo.currency", currency
);
27 currency
._mixInDefaults = function(options
){
28 options
= options
|| {};
29 options
.type
= "currency";
31 // Get locale-dependent currency data, like the symbol
32 var bundle
= i18n
.getLocalization("dojo.cldr", "currency", options
.locale
) || {};
34 // Mixin locale-independent currency data, like # of places
35 var iso
= options
.currency
;
36 var data
= cldrMonetary
.getData(iso
);
38 darray
.forEach(["displayName","symbol","group","decimal"], function(prop
){
39 data
[prop
] = bundle
[iso
+"_"+prop
];
42 data
.fractional
= [true, false];
44 // Mixin with provided options
45 return lang
.mixin(data
, options
);
49 currency.__FormatOptions = declare([dnumber.__FormatOptions], {
51 // Should not be set. Value is assumed to be "currency".
53 // localized currency symbol. The default will be looked up in table of supported currencies in `dojo.cldr`
54 // A [ISO4217](http://en.wikipedia.org/wiki/ISO_4217) currency code will be used if not found.
56 // an [ISO4217](http://en.wikipedia.org/wiki/ISO_4217) currency code, a three letter sequence like "USD".
57 // For use with dojo.currency only.
59 // number of decimal places to show. Default is defined based on which currency is used.
67 currency
.format = function(/*Number*/ value
, /*__FormatOptions?*/ options
){
69 // Format a Number as a currency, using locale-specific settings
72 // Create a string from a Number using a known, localized pattern.
73 // [Formatting patterns](http://www.unicode.org/reports/tr35/#Number_Elements)
74 // appropriate to the locale are chosen from the [CLDR](http://unicode.org/cldr)
75 // as well as the appropriate symbols and delimiters and number of decimal places.
78 // the number to be formatted.
80 return dnumber
.format(value
, currency
._mixInDefaults(options
));
83 currency
.regexp = function(/*dnumber.__RegexpOptions?*/ options
){
86 // Builds the regular needed to parse a currency value
89 // Returns regular expression with positive and negative match, group and decimal separators
90 // Note: the options.places default, the number of decimal places to accept, is defined by the currency type.
91 return dnumber
.regexp(currency
._mixInDefaults(options
)); // String
95 var __ParseOptions = currency.__ParseOptions = declare(dnumber.__ParseOptions, {
97 // Should not be set. Value is assumed to be currency.
99 // an [ISO4217](http://en.wikipedia.org/wiki/ISO_4217) currency code, a three letter sequence like "USD".
100 // For use with dojo.currency only.
102 // localized currency symbol. The default will be looked up in table of supported currencies in `dojo.cldr`
103 // A [ISO4217](http://en.wikipedia.org/wiki/ISO_4217) currency code will be used if not found.
105 // fixed number of decimal places to accept. The default is determined based on which currency is used.
106 // fractional: Boolean|Array?
107 // Whether to include the fractional portion, where the number of decimal places are implied by the currency
108 // or explicit 'places' parameter. The value [true,false] makes the fractional portion optional.
109 // By default for currencies, it the fractional portion is optional.
113 currency
.parse = function(/*String*/ expression
, /*__ParseOptions?*/ options
){
116 // Convert a properly formatted currency string to a primitive Number,
117 // using locale-specific settings.
119 // Create a Number from a string using a known, localized pattern.
120 // [Formatting patterns](http://www.unicode.org/reports/tr35/#Number_Format_Patterns)
121 // are chosen appropriate to the locale, as well as the appropriate symbols and delimiters
122 // and number of decimal places.
124 // A string representation of a currency value
126 return dnumber
.parse(expression
, currency
._mixInDefaults(options
));