META-INF.resources.bower_components.globalize.src.number.format-properties.js Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jwebmp-globalize Show documentation
Show all versions of jwebmp-globalize Show documentation
The JWebSwing implementation for a full Globalization
The newest version!
define([
"./numbering-system-digits-map",
"./pattern-properties",
"./symbol",
"./symbol/map",
"./symbol/name",
"../util/number/round"
], function (numberNumberingSystemDigitsMap, numberPatternProperties, numberSymbol, numberSymbolMap,
numberSymbolName, numberRound) {
/**
* formatProperties( pattern, cldr [, options] )
*
* @pattern [String] raw pattern for numbers.
*
* @cldr [Cldr instance].
*
* @options [Object]:
* - minimumIntegerDigits [Number]
* - minimumFractionDigits, maximumFractionDigits [Number]
* - minimumSignificantDigits, maximumSignificantDigits [Number]
* - round [String] "ceil", "floor", "round" (default), or "truncate".
* - useGrouping [Boolean] default true.
*
* Return the processed properties that will be used in number/format.
* ref: http://www.unicode.org/reports/tr35/tr35-numbers.html
*/
return function (pattern, cldr, options) {
var negativePattern, negativePrefix, negativeProperties, negativeSuffix, positivePattern,
roundFn, properties;
function getOptions(attribute, propertyIndex) {
if (attribute in options) {
properties[propertyIndex] = options[attribute];
}
}
options = options || {};
pattern = pattern.split(";");
positivePattern = pattern[0];
negativePattern = pattern[1] || "-" + positivePattern;
negativeProperties = numberPatternProperties(negativePattern);
negativePrefix = negativeProperties[0];
negativeSuffix = negativeProperties[10];
// Have runtime code to refer to numberRound() instead of including it explicitly.
roundFn = numberRound(options.round);
roundFn.generatorString = function () {
return "numberRound(" + (options.round ? "\"" + options.round + "\"" : "") + ")";
};
properties = numberPatternProperties(positivePattern).concat([
positivePattern,
negativePrefix + positivePattern + negativeSuffix,
negativePrefix,
negativeSuffix,
roundFn,
numberSymbol("infinity", cldr),
numberSymbol("nan", cldr),
numberSymbolMap(cldr),
numberNumberingSystemDigitsMap(cldr)
]);
getOptions("minimumIntegerDigits", 2);
getOptions("minimumFractionDigits", 3);
getOptions("maximumFractionDigits", 4);
getOptions("minimumSignificantDigits", 5);
getOptions("maximumSignificantDigits", 6);
// Grouping separators
if (options.useGrouping === false) {
properties[8] = null;
}
// Normalize number of digits if only one of either minimumFractionDigits or
// maximumFractionDigits is passed in as an option
if ("minimumFractionDigits" in options && !("maximumFractionDigits" in options)) {
// maximumFractionDigits = Math.max( minimumFractionDigits, maximumFractionDigits );
properties[4] = Math.max(properties[3], properties[4]);
} else if (!("minimumFractionDigits" in options) &&
"maximumFractionDigits" in options) {
// minimumFractionDigits = Math.min( minimumFractionDigits, maximumFractionDigits );
properties[3] = Math.min(properties[3], properties[4]);
}
// Return:
// 0-10: see number/pattern-properties.
// 11: @positivePattern [String] Positive pattern.
// 12: @negativePattern [String] Negative pattern.
// 13: @negativePrefix [String] Negative prefix.
// 14: @negativeSuffix [String] Negative suffix.
// 15: @round [Function] Round function.
// 16: @infinitySymbol [String] Infinity symbol.
// 17: @nanSymbol [String] NaN symbol.
// 18: @symbolMap [Object] A bunch of other symbols.
// 19: @nuDigitsMap [Array] Digits map if numbering system is different than `latn`.
return properties;
};
});