]> git.pond.sub.org Git - eow/blob - static/dojo-release-1.1.1/dojo/currency.js
Comment class stub
[eow] / static / dojo-release-1.1.1 / dojo / currency.js
1 if(!dojo._hasResource["dojo.currency"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
2 dojo._hasResource["dojo.currency"] = true;
3 dojo.provide("dojo.currency");
4
5 dojo.require("dojo.number");
6 dojo.require("dojo.i18n");
7 dojo.requireLocalization("dojo.cldr", "currency", null, "zh,en-ca,pt,en-us,de,ja,en,en-au,ROOT,fr,es,ko,zh-tw,it");
8 dojo.require("dojo.cldr.monetary");
9
10 /*=====
11 dojo.currency = {
12         // summary: localized formatting and parsing routines for currencies
13 }
14 =====*/
15
16 dojo.currency._mixInDefaults = function(options){
17         options = options || {};
18         options.type = "currency";
19
20         // Get locale-depenent currency data, like the symbol
21         var bundle = dojo.i18n.getLocalization("dojo.cldr", "currency", options.locale) || {};
22
23         // Mixin locale-independent currency data, like # of places
24         var iso = options.currency;
25         var data = dojo.cldr.monetary.getData(iso);
26
27         dojo.forEach(["displayName","symbol","group","decimal"], function(prop){
28                 data[prop] = bundle[iso+"_"+prop];
29         });
30
31         data.fractional = [true, false];
32
33         // Mixin with provided options
34         return dojo.mixin(data, options);
35 }
36
37 dojo.currency.format = function(/*Number*/value, /*dojo.number.__FormatOptions?*/options){
38 // summary:
39 //              Format a Number as a currency, using locale-specific settings
40 //
41 // description:
42 //              Create a string from a Number using a known, localized pattern.
43 //              [Formatting patterns](http://www.unicode.org/reports/tr35/#Number_Elements) appropriate to the locale are chosen from the [CLDR](http://unicode.org/cldr)
44 //              as well as the appropriate symbols and delimiters.
45 //
46 // value:
47 //              the number to be formatted.
48
49         return dojo.number.format(value, dojo.currency._mixInDefaults(options));
50 }
51
52 dojo.currency.regexp = function(/*dojo.number.__RegexpOptions?*/options){
53 //
54 // summary:
55 //              Builds the regular needed to parse a currency value
56 //
57 // description:
58 //              Returns regular expression with positive and negative match, group and decimal separators
59 //              Note: the options.places default, the number of decimal places to accept, is defined by the currency type.
60         return dojo.number.regexp(dojo.currency._mixInDefaults(options)); // String
61 }
62
63 /*=====
64 dojo.declare("dojo.currency.__ParseOptions", [dojo.number.__ParseOptions], {
65         //      type: String?
66         //              currency, set by default.
67         //      symbol: String?
68         //              override currency symbol. Normally, will be looked up in table of supported currencies,
69         //              and ISO currency code will be used if not found.  See dojo.i18n.cldr.nls->currency.js
70         //      places: Number?
71         //              number of decimal places to accept.  Default is defined by currency.
72         //      fractional: Boolean?|Array?
73         //              where places are implied by pattern or explicit 'places' parameter, whether to include the fractional portion.
74         //              By default for currencies, it the fractional portion is optional.
75         type: "",
76         symbol: "",
77         places: "",
78         fractional: ""
79 });
80 =====*/
81
82 dojo.currency.parse = function(/*String*/expression, /*dojo.currency.__ParseOptions?*/options){
83         //
84         // summary:
85         //              Convert a properly formatted currency string to a primitive Number,
86         //              using locale-specific settings.
87         //
88         // description:
89         //              Create a Number from a string using a known, localized pattern.
90         //              [Formatting patterns](http://www.unicode.org/reports/tr35/#Number_Format_Patterns) are chosen appropriate to the locale.
91         //
92         // expression: A string representation of a Number
93
94         return dojo.number.parse(expression, dojo.currency._mixInDefaults(options));
95 }
96
97 }