]> git.wh0rd.org - tt-rss.git/blame - lib/dojo/currency.js.uncompressed.js
update dojo to 1.7.3
[tt-rss.git] / lib / dojo / currency.js.uncompressed.js
CommitLineData
1354d172
AD
1define("dojo/currency", ["./_base/kernel", "./_base/lang", "./_base/array", "./number", "./i18n", "./i18n!./cldr/nls/currency", "./cldr/monetary"], function(dojo, lang, darray, dnumber, i18n, nlsCurrency, cldrMonetary) {
2 // module:
3 // dojo/currency
4 // summary:
5 // TODOC
6
7lang.getObject("currency", true, dojo);
8
9/*=====
10dojo.currency = {
11 // summary: localized formatting and parsing routines for currencies
12 //
13 // description: extends dojo.number to provide culturally-appropriate formatting of values
14 // in various world currencies, including use of a currency symbol. The currencies are specified
15 // by a three-letter international symbol in all uppercase, and support for the currencies is
16 // provided by the data in `dojo.cldr`. The scripts generating dojo.cldr specify which
17 // currency support is included. A fixed number of decimal places is determined based
18 // on the currency type and is not determined by the 'pattern' argument. The fractional
19 // portion is optional, by default, and variable length decimals are not supported.
20}
21=====*/
22
23dojo.currency._mixInDefaults = function(options){
24 options = options || {};
25 options.type = "currency";
26
27 // Get locale-dependent currency data, like the symbol
28 var bundle = i18n.getLocalization("dojo.cldr", "currency", options.locale) || {};
29
30 // Mixin locale-independent currency data, like # of places
31 var iso = options.currency;
32 var data = cldrMonetary.getData(iso);
33
34 darray.forEach(["displayName","symbol","group","decimal"], function(prop){
35 data[prop] = bundle[iso+"_"+prop];
36 });
37
38 data.fractional = [true, false];
39
40 // Mixin with provided options
41 return lang.mixin(data, options);
42};
43
44/*=====
45dojo.declare("dojo.currency.__FormatOptions", [dojo.number.__FormatOptions], {
46 // type: String?
47 // Should not be set. Value is assumed to be "currency".
48 // symbol: String?
49 // localized currency symbol. The default will be looked up in table of supported currencies in `dojo.cldr`
50 // A [ISO4217](http://en.wikipedia.org/wiki/ISO_4217) currency code will be used if not found.
51 // currency: String?
52 // an [ISO4217](http://en.wikipedia.org/wiki/ISO_4217) currency code, a three letter sequence like "USD".
53 // For use with dojo.currency only.
54 // places: Number?
55 // number of decimal places to show. Default is defined based on which currency is used.
56 type: "",
57 symbol: "",
58 currency: "",
59 places: ""
60});
61=====*/
62
63dojo.currency.format = function(/*Number*/value, /*dojo.currency.__FormatOptions?*/options){
64// summary:
65// Format a Number as a currency, using locale-specific settings
66//
67// description:
68// Create a string from a Number using a known, localized pattern.
69// [Formatting patterns](http://www.unicode.org/reports/tr35/#Number_Elements)
70// appropriate to the locale are chosen from the [CLDR](http://unicode.org/cldr)
71// as well as the appropriate symbols and delimiters and number of decimal places.
72//
73// value:
74// the number to be formatted.
75
76 return dnumber.format(value, dojo.currency._mixInDefaults(options));
77};
78
79dojo.currency.regexp = function(/*dojo.number.__RegexpOptions?*/options){
80//
81// summary:
82// Builds the regular needed to parse a currency value
83//
84// description:
85// Returns regular expression with positive and negative match, group and decimal separators
86// Note: the options.places default, the number of decimal places to accept, is defined by the currency type.
87 return dnumber.regexp(dojo.currency._mixInDefaults(options)); // String
88};
89
90/*=====
91dojo.declare("dojo.currency.__ParseOptions", [dojo.number.__ParseOptions], {
92 // type: String?
93 // Should not be set. Value is assumed to be currency.
94 // currency: String?
95 // an [ISO4217](http://en.wikipedia.org/wiki/ISO_4217) currency code, a three letter sequence like "USD".
96 // For use with dojo.currency only.
97 // symbol: String?
98 // localized currency symbol. The default will be looked up in table of supported currencies in `dojo.cldr`
99 // A [ISO4217](http://en.wikipedia.org/wiki/ISO_4217) currency code will be used if not found.
100 // places: Number?
101 // fixed number of decimal places to accept. The default is determined based on which currency is used.
102 // fractional: Boolean?|Array?
103 // Whether to include the fractional portion, where the number of decimal places are implied by the currency
104 // or explicit 'places' parameter. The value [true,false] makes the fractional portion optional.
105 // By default for currencies, it the fractional portion is optional.
106 type: "",
107 currency: "",
108 symbol: "",
109 places: "",
110 fractional: ""
111});
112=====*/
113
114dojo.currency.parse = function(/*String*/expression, /*dojo.currency.__ParseOptions?*/options){
115 //
116 // summary:
117 // Convert a properly formatted currency string to a primitive Number,
118 // using locale-specific settings.
119 //
120 // description:
121 // Create a Number from a string using a known, localized pattern.
122 // [Formatting patterns](http://www.unicode.org/reports/tr35/#Number_Format_Patterns)
123 // are chosen appropriate to the locale, as well as the appropriate symbols and delimiters
124 // and number of decimal places.
125 //
126 // expression: A string representation of a currency value
127
128 return dnumber.parse(expression, dojo.currency._mixInDefaults(options));
129};
130
131return dojo.currency;
132});