define(['jquery','underscore'],function($,_){'use strict';var globalPriceFormat={requiredPrecision:2,integerRequired:1,decimalSymbol:',',groupSymbol:',',groupLength:','};function stringPad(string,times){return new Array(times+1).join(string);} function formatPriceLocale(amount,format,isShowSign){var s='',precision,pattern,locale,r;format=_.extend(globalPriceFormat,format);precision=isNaN(format.requiredPrecision=Math.abs(format.requiredPrecision))?2:format.requiredPrecision;pattern=format.pattern||'%s';locale=window.LOCALE||'en-US';if(isShowSign===undefined||isShowSign===true){s=amount<0?'-':isShowSign?'+':'';}else if(isShowSign===false){s='';} pattern=pattern.indexOf('{sign}')<0?s+pattern:pattern.replace('{sign}',s);if(amount%1===0)precision=0;amount=Number(Math.round(Math.abs(+amount||0)+'e+'+precision)+('e-'+precision));r=amount.toLocaleString(locale,{minimumFractionDigits:precision});return pattern.replace('%s',r).replace(/^\s\s*/,'').replace(/\s\s*$/,'');} function formatPrice(amount,format,isShowSign){var s='',precision,integerRequired,decimalSymbol,groupSymbol,groupLength,pattern,i,pad,j,re,r,am;format=_.extend(globalPriceFormat,format);var string="window.checkoutConfig.checkoutUrl";var substring="checkout";if(string.indexOf(substring)!==-1&&window.checkoutConfig!=undefined&&window.checkoutConfig.quoteData!=undefined&&window.checkoutConfig.quoteData.subtotal!=amount){precision=2;}else{precision=0;} integerRequired=isNaN(format.integerRequired=Math.abs(format.integerRequired))?1:format.integerRequired;decimalSymbol=format.decimalSymbol===undefined?',':format.decimalSymbol;groupSymbol=format.groupSymbol===undefined?'.':format.groupSymbol;groupLength=format.groupLength===undefined?3:format.groupLength;pattern=format.pattern||'%s';if(amount%1===0)precision=0;if(isShowSign===undefined||isShowSign===true){s=amount<0?'-':isShowSign?'+':'';}else if(isShowSign===false){s='';} pattern=pattern.indexOf('{sign}')<0?s+pattern:pattern.replace('{sign}',s);i=parseInt(amount=Number(Math.round(Math.abs(+amount||0)+'e+'+precision)+('e-'+precision)),10)+'';pad=i.lengthgroupLength?i.length%groupLength:0;re=new RegExp('(\\d{'+groupLength+'})(?=\\d)','g');am=Number(Math.round(Math.abs(amount-i)+'e+'+precision)+('e-'+precision));r=(j?i.substr(0,j)+groupSymbol:'')+ i.substr(j).replace(re,'$1'+groupSymbol)+ (precision?decimalSymbol+am.toFixed(precision).replace(/-/,0).slice(2):'');return pattern.replace('%s',r).replace(/^\s\s*/,'').replace(/\s\s*$/,'');} function objectDeepClone(obj){return JSON.parse(JSON.stringify(obj));} function findOptionId(element){var re,id,name;if(!element){return id;} name=$(element).attr('name');if(name.indexOf('[')!==-1){re=/\[([^\]]+)?\]/;}else{re=/_([^\]]+)?_/;} id=re.exec(name)&&re.exec(name)[1];if(id){return id;}} return{formatPriceLocale:formatPriceLocale,formatPrice:formatPrice,deepClone:objectDeepClone,strPad:stringPad,findOptionId:findOptionId};});