|
1 | 1 | /* jshint node:true */
|
2 | 2 |
|
| 3 | +function replaceSpecialChars (ptn) { |
| 4 | + // Matches CLDR number patterns, e.g. #,##0.00, #,##,##0.00, #,##0.##, etc. |
| 5 | + var numPtn = /#(?:[\.,]#+)*0(?:[,\.][0#]+)*/; |
| 6 | + |
| 7 | + return ptn |
| 8 | + .replace(numPtn, '{number}') |
| 9 | + .replace('+', '{plusSign}') |
| 10 | + .replace('-', '{minusSign}') |
| 11 | + .replace('%', '{percentSign}') |
| 12 | + .replace('¤', '{currency}'); |
| 13 | +} |
| 14 | + |
3 | 15 | /**
|
4 | 16 | * Parses a CLDR number formatting string into the object specified in ECMA-402
|
5 | 17 | * Returns an object with positivePattern and negativePattern properties
|
6 | 18 | */
|
7 | 19 | function createNumberFormats (ptn) {
|
8 | 20 | var patterns = ptn.split(';'),
|
9 | 21 |
|
10 |
| - // Matches CLDR number patterns, e.g. #,##0.00, #,##,##0.00, #,##0.##, etc. |
11 |
| - numPtn = /#(?:[\.,]#+)*0(?:[,\.][0#]+)*/, |
12 | 22 | ret = {
|
13 |
| - positivePattern: patterns[0].replace(numPtn, '{number}').replace('¤', '{currency}') |
| 23 | + positivePattern: replaceSpecialChars(patterns[0]) |
14 | 24 | };
|
15 | 25 |
|
16 | 26 | // Negative patterns aren't always specified, in those cases use '-' + positivePattern
|
17 |
| - ret.negativePattern = patterns[1] ? patterns[1].replace(numPtn, '{number}').replace('¤', '{currency}') |
18 |
| - : '-' + ret.positivePattern; |
| 27 | + ret.negativePattern = patterns[1] ? |
| 28 | + replaceSpecialChars(patterns[1]) : |
| 29 | + '{minusSign}' + ret.positivePattern; |
19 | 30 |
|
20 | 31 | return ret;
|
21 | 32 | }
|
@@ -108,11 +119,13 @@ module.exports = function (locale, data) {
|
108 | 119 |
|
109 | 120 | // Currently, Intl 402 only uses these symbols for numbers
|
110 | 121 | ret.number.symbols[key.split('-').pop()] = {
|
111 |
| - decimal: sym.decimal, |
112 |
| - group: sym.group, |
113 |
| - nan: sym.nan, |
114 |
| - percent: sym.percentSign, |
115 |
| - infinity:sym.infinity |
| 122 | + decimal: sym.decimal, |
| 123 | + group: sym.group, |
| 124 | + nan: sym.nan, |
| 125 | + plusSign: sym.plusSign, |
| 126 | + minusSign: sym.minusSign, |
| 127 | + percentSign: sym.percentSign, |
| 128 | + infinity: sym.infinity |
116 | 129 | };
|
117 | 130 | });
|
118 | 131 |
|
|
0 commit comments