/* front.utils - v3.0.8 */ (function(){var Utils,utils,__bind=function(fn,me){return function(){return fn.apply(me,arguments)}},__hasProp={}.hasOwnProperty,__slice=[].slice;Utils=function(){function Utils(){this._extend=__bind(this._extend,this),this._getDecimalDigits=__bind(this._getDecimalDigits,this),this._getThousandsSeparator=__bind(this._getThousandsSeparator,this),this._getDecimalSeparator=__bind(this._getDecimalSeparator,this),this._getStartsWithCurrency=__bind(this._getStartsWithCurrency,this),this._getCurrency=__bind(this._getCurrency,this),this.unFlattenObj=__bind(this.unFlattenObj,this),this.flattenObj=__bind(this.flattenObj,this),this.mapObj=__bind(this.mapObj,this),this.hash=__bind(this.hash,this),this.spacesToHyphens=__bind(this.spacesToHyphens,this),this.sanitize=__bind(this.sanitize,this),this.plainChars=__bind(this.plainChars,this),this.maskInfo=__bind(this.maskInfo,this),this.maskString=__bind(this.maskString,this),this.capitalizeSentence=__bind(this.capitalizeSentence,this),this.capitalize=__bind(this.capitalize,this),this.capitalizeWord=__bind(this.capitalizeWord,this),this.dateFromISO8601=__bind(this.dateFromISO8601,this),this.urlParams=__bind(this.urlParams,this),this.getCookieValue=__bind(this.getCookieValue,this),this.readCookie=__bind(this.readCookie,this),this.pad=__bind(this.pad,this),this.formatCurrency=__bind(this.formatCurrency,this)}return Utils.prototype.formatCurrency=function(value,options){var decimalPart,defaults,opts,wholePart,_ref;return defaults={decimalSeparator:this._getDecimalSeparator(),thousandsSeparator:this._getThousandsSeparator(),absolute:!1,decimalPlaces:this._getDecimalDigits()},opts=this._extend(defaults,options),opts.absolute&&value<0&&(value=-value),value=value.toFixed(opts.decimalPlaces),_ref=value.split("."),wholePart=_ref[0],decimalPart=_ref[1],wholePart=wholePart.replace(/\B(?=(\d{3})+(?!\d))/g,opts.thousandsSeparator),opts.decimalPlaces>0?wholePart+opts.decimalSeparator+decimalPart:wholePart},Utils.prototype.intAsCurrency=function(value,options){var currencySymbol,startsWithCurrency;return currencySymbol=options&&options.currencySymbol?options.currencySymbol:this._getCurrency(),startsWithCurrency=options&&options.currencySymbol?options.currencySymbol:this._getStartsWithCurrency(),startsWithCurrency?currencySymbol+this.formatCurrency(value/100,options):this.formatCurrency(value/100,options)+" "+currencySymbol},Utils.prototype.pad=function(str,max,options){var defaults,opts,toadd;return defaults={char:"0",position:"left"},opts=this._extend(defaults,options),opts.char=opts.char.charAt(0),str+="",toadd=Array(max-str.length+1).join(opts.char),"right"===opts.position?str+toadd:toadd+str},Utils.prototype.readCookie=function(name){var ARRcookies,key,pair,value,_i,_len;for(ARRcookies=document.cookie.split(";"),_i=0,_len=ARRcookies.length;_i<_len;_i++)if(pair=ARRcookies[_i],key=pair.substr(0,pair.indexOf("=")).replace(/^\s+|\s+$/g,""),value=pair.substr(pair.indexOf("=")+1),key===name)return unescape(value)},Utils.prototype.getCookieValue=function(cookie,name){var key,subcookie,subcookies,value,_i,_len;for(subcookies=cookie.split("&"),_i=0,_len=subcookies.length;_i<_len;_i++)if(subcookie=subcookies[_i],key=subcookie.substr(0,subcookie.indexOf("=")),value=subcookie.substr(subcookie.indexOf("=")+1),key===name)return unescape(value)},Utils.prototype.urlParams=function(){var decode,match,params,plus,query,search;for(params={},search=/([^&=]+)=?([^&]*)/g,plus=/\+/g,decode=function(s){try{return decodeURIComponent(s.replace(plus," "))}catch(_error){return s.replace(plus," ")}},query=window.location.search.substring(1);match=search.exec(query);)params[decode(match[1])]=decode(match[2]);return params},Utils.prototype.dateFromISO8601=function(isostr){var part1,parts;return parts=isostr.match(/\d+/g),part1=parts[1]-1,new Date(parts[0],part1,parts[2],parts[3],parts[4],parts[5])},Utils.prototype.capitalizeWord=function(word){return null==word&&(word=""),word.charAt(0).toUpperCase()+word.slice(1)},Utils.prototype.capitalize=function(word){return null==word&&(word=""),this.capitalizeWord(word)},Utils.prototype.capitalizeSentence=function(sentence){var newWords,oldWords,word;return null==sentence&&(sentence=""),oldWords=sentence.toLowerCase().split(" "),newWords=function(){var _i,_len,_results;for(_results=[],_i=0,_len=oldWords.length;_i<_len;_i++)word=oldWords[_i],_results.push(this.capitalizeWord(word));return _results}.call(this),newWords.join(" ")},Utils.prototype.maskString=function(str,mask,fixedChars){var applyMask,argString,digitMask,fixedCharsRegex,letterMask,maskString;return null==fixedChars&&(fixedChars="[(),.:/ -]"),argString="string"==typeof str?str:String(str),maskString=(null!=mask?mask.mask:void 0)||mask,fixedCharsRegex=new RegExp(fixedChars),digitMask="9",letterMask="A",applyMask=function(valueArray,maskArray,fixed){var i,maskedValueArray,noMatchDigit,noMatchLetter,_i,_len;for(maskedValueArray=valueArray.slice(0),i=_i=0,_len=maskArray.length;_i<_len&&(maskArray[i],maskedValueArray[i]&&maskArray[i]);i=++_i){if(noMatchDigit=maskArray[i]===digitMask&&!/\d/.test(maskedValueArray[i]),noMatchLetter=maskArray[i].toUpperCase()===letterMask&&!/[a-zA-Z\u00C0-\u017F]/.test(maskedValueArray[i]),noMatchDigit||noMatchLetter)return valueArray;if(fixed.test(maskArray[i])){if(maskArray[i]===maskedValueArray[i])continue;maskedValueArray.splice(i,0,maskArray[i])}}return maskedValueArray},applyMask(argString.split(""),maskString.split(""),fixedCharsRegex).join("")},Utils.prototype.maskInfo=function(info){var maskRegex,maskText;return maskRegex=/\*/g,maskText='*',info?info.replace(maskRegex,maskText):info},Utils.prototype.plainChars=function(str){var plain,regex,specialChars;if(null!=str)return specialChars="ąàáäâãåæćęèéëêìíïîłńòóöôõøśùúüûñçżź",plain="aaaaaaaaceeeeeiiiilnoooooosuuuunczz",regex=new RegExp("["+specialChars+"]","g"),str+="",str.replace(regex,function(char){return plain.charAt(specialChars.indexOf(char))})},Utils.prototype.sanitize=function(str){var s;return s=this.plainChars(str.replace(/\s/g,"")).replace(/\/|\\/g,"-").replace(/\(|\)|\'|\"/g,"").toLowerCase().replace(/\,/g,"V").replace(/\./g,"P").replace(/\:/g,"D"),s.charAt(0).toUpperCase()+s.slice(1)},Utils.prototype.spacesToHyphens=function(str){return str.replace(/\ /g,"-")},Utils.prototype.hash=function(str){var char,charcode,hashed,_i,_len;for(hashed=0,_i=0,_len=str.length;_i<_len;_i++)char=str[_i],charcode=char.charCodeAt(0),hashed=(hashed<<5)-hashed+charcode,hashed&=hashed;return hashed},Utils.prototype.mapObj=function(obj,f){var k,obj2,v;obj2={};for(k in obj)__hasProp.call(obj,k)&&(v=obj[k],obj2[k]=f(k,v));return obj2},Utils.prototype.flattenObj=function(obj,target,prefix){var _ref;if(null==("undefined"!=typeof window&&null!==window&&null!=(_ref=window._)?_ref.reduce:void 0))throw"This function requires Underscore";return prefix=prefix||"",_.reduce(obj,function(_this){return function(result,value,key){return _.isObject(value)?_this.flattenObj(value,result,prefix+key+"."):result[prefix+key]=value,result}}(this),target||{})},Utils.prototype.unFlattenObj=function(obj){var _ref;if(null==("undefined"!=typeof window&&null!==window&&null!=(_ref=window._)?_ref.reduce:void 0))throw"This function requires Underscore";return _.reduce(obj,function(_this){return function(result,value,keys){var current,limit,partitions;return current=result,partitions=keys.split("."),limit=partitions.length-1,_.each(partitions,function(key,index){return current=current[key]=index===limit?value:current[key]||{}}),result}}(),{})},Utils.prototype.padStr=function(str,limit,padding){return(padding+str).split("").reverse().slice(0,limit).reverse().join("")},Utils.prototype.dateFormat=function(date){return"string"==typeof date&&(date=new Date(date)),this.padStr(date.getDate(),2,"00")+"/"+this.padStr(date.getMonth()+1,2,"00")+"/"+date.getFullYear()},Utils.prototype.dateFormatUS=function(date){return"string"==typeof date&&(date=new Date(date)),date.getMonth()+1+"/"+this.padStr(date.getDate(),2,"00")+"/"+date.getFullYear()},Utils.prototype._getCurrency=function(){var _ref,_ref1;return(null!=(_ref=window.vtex)&&null!=(_ref1=_ref.i18n)&&"function"==typeof _ref1.getCurrency?_ref1.getCurrency():void 0)||"R$ "},Utils.prototype._getStartsWithCurrency=function(){var startsWithCurrency,_ref,_ref1,_ref2,_ref3;return null==(_ref=window.vtex)||null==(_ref1=_ref.i18n)||!_ref1.getStartsWithCurrency||(null==(startsWithCurrency=null!=(_ref2=window.vtex)&&null!=(_ref3=_ref2.i18n)?_ref3.getStartsWithCurrency():void 0)||startsWithCurrency)},Utils.prototype._getDecimalSeparator=function(){var _ref,_ref1;return(null!=(_ref=window.vtex)&&null!=(_ref1=_ref.i18n)&&"function"==typeof _ref1.getDecimalSeparator?_ref1.getDecimalSeparator():void 0)||","},Utils.prototype._getThousandsSeparator=function(){var _ref,_ref1;return(null!=(_ref=window.vtex)&&null!=(_ref1=_ref.i18n)&&"function"==typeof _ref1.getThousandsSeparator?_ref1.getThousandsSeparator():void 0)||"."},Utils.prototype._getDecimalDigits=function(){var _ref,_ref1,_ref2,_ref3;return null!=(null!=(_ref=window.vtex)&&null!=(_ref1=_ref.i18n)?_ref1.getDecimalDigits:void 0)?null!=(_ref2=window.vtex)&&null!=(_ref3=_ref2.i18n)?_ref3.getDecimalDigits():void 0:2},Utils.prototype._extend=function(){var obj,prop,source,sources,_i,_len;for(obj=arguments[0],sources=2<=arguments.length?__slice.call(arguments,1):[],_i=0,_len=sources.length;_i<_len;_i++)if(source=sources[_i])for(prop in source)obj[prop]=source[prop];return obj},Utils}(),utils=new Utils,null!=window._?null!=window._.mixin?window._.mixin(utils):utils._extend(window._,utils):(window._=utils,window._.extend=utils._extend)}).call(this); //# sourceMappingURL=underscore-extensions.js.map