From b89a7ee8b956c96a1dcee995ea840feddc5d4b27 Mon Sep 17 00:00:00 2001 From: Pierre Frisch Date: Thu, 22 Dec 2011 07:25:50 -0800 Subject: First commit of Ninja to ninja-internal Signed-off-by: Valerio Virgillito --- .../montage/core/converter/currency-converter.js | 77 ++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100755 node_modules/montage/core/converter/currency-converter.js (limited to 'node_modules/montage/core/converter/currency-converter.js') diff --git a/node_modules/montage/core/converter/currency-converter.js b/node_modules/montage/core/converter/currency-converter.js new file mode 100755 index 00000000..bba81dc1 --- /dev/null +++ b/node_modules/montage/core/converter/currency-converter.js @@ -0,0 +1,77 @@ +/* + This file contains proprietary software owned by Motorola Mobility, Inc.
+ No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.
+ (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. +
*/ +/** + @module montage/core/converter/currency-converter + @requires montage/core/core + @requires montage/core/converter/converter + @requires montage/core/converter/number-converter +*/ +var Montage = require("montage").Montage; +var Converter = require('core/converter/converter'); +var numericValueToString = require("core/converter/number-converter").numericValueToString; +var NumberConverter = require("core/converter/number-converter").NumberConverter; +/** + Formats a number as a human-readable currency value. + @function module:montage/core/converter/currency-converter.#formatCurrency + @param {Property} value + @param {String} currency + @param {Number} decimals + @param {String} useParensForNegative + @returns stringValue +*/ +var formatCurrency = function(value, currency, decimals, useParensForNegative) { + var stringValue = numericValueToString(value, decimals); + currency = currency || '$'; + if ((value < 0) && useParensForNegative) { + stringValue = '(' + stringValue.substring(1, stringValue.length) + ')'; + } + + stringValue = stringValue + ' ' + currency; + return stringValue; +}; +/** + @class module:montage/core/converter/currency-converter.CurrencyConverter + @classdesc Formats a value as a currency. + @extends module:montage/core/converter/number-converter.NumberConverter + */ +exports.CurrencyConverter = Montage.create(NumberConverter, /** @lends module:montage/core/converter.CurrencyConverter# */ { + + /** + @type {Property} + @default {String} '$' + */ + currency: { + value: '$' + }, + + /** + @type {Property} + @default {Number} 2 + */ + decimals: { + value: 2 + }, + + /** + @type {Property} + @default {Boolean} false + */ + useParensForNegative: { + value: false + }, + + /** + @function + @param {String} v + @returns {string} The formatted currency value. + */ + convert: { + value: function(v) { + return formatCurrency(v, this.currency, this.decimals, this.useParensForNegative); + } + } + +}); -- cgit v1.2.3