UNPKG

crowdstart-checkout

Version:

One Click Checkout for Crowdstart

55 lines (48 loc) 1.96 kB
// Generated by CoffeeScript 1.10.0 var currencySeparator, currencySigns, digitsOnlyRe, isZeroDecimal; currencySigns = require('../data/currencies').data; currencySeparator = '.'; digitsOnlyRe = new RegExp('[^\\d.-]', 'g'); isZeroDecimal = function(code) { if (code === 'bif' || code === 'clp' || code === 'djf' || code === 'gnf' || code === 'jpy' || code === 'kmf' || code === 'krw' || code === 'mga' || code === 'pyg' || code === 'rwf' || code === 'vnd' || code === 'vuv' || code === 'xaf' || code === 'xof' || code === 'xpf') { return true; } return false; }; module.exports = { renderUpdatedUICurrency: function(code, uiCurrency) { var currentCurrencySign; currentCurrencySign = currencySigns[code]; return Util.renderUICurrencyFromJSON(Util.renderJSONCurrencyFromUI(uiCurrency)); }, renderUICurrencyFromJSON: function(code, jsonCurrency) { var currentCurrencySign; currentCurrencySign = currencySigns[code]; jsonCurrency = '' + jsonCurrency; if (isZeroDecimal(code)) { return currentCurrencySign + jsonCurrency; } while (jsonCurrency.length < 3) { jsonCurrency = '0' + jsonCurrency; } return currentCurrencySign + jsonCurrency.substr(0, jsonCurrency.length - 2) + '.' + jsonCurrency.substr(-2); }, renderJSONCurrencyFromUI: function(code, uiCurrency) { var currentCurrencySign, parts; currentCurrencySign = currencySigns[code]; if (isZeroDecimal(code)) { return parseInt(('' + uiCurrency).replace(digitsOnlyRe, '').replace(currencySeparator, ''), 10); } parts = uiCurrency.split(currencySeparator); if (parts.length > 1) { parts[1] = parts[1].substr(0, 2); while (parts[1].length < 2) { parts[1] += '0'; } } else { parts[1] = '00'; } return parseInt(parseFloat(parts[0].replace(digitsOnlyRe, '')) * 100 + parseFloat(parts[1].replace(digitsOnlyRe, '')), 10); } }; //# sourceMappingURL=currency.js.map