UNPKG

jquery-formula

Version:
8 lines (6 loc) 19.7 kB
//================================================================================ // [jquery-formula] // version: 2.0.12 // update: 2017.06.16 //================================================================================ String.prototype.toFormulaDecimal=function(){var a=this.split(".");return a[0].replace(/[^\d.]*/gi,"").replace(/\B(?=(\d{3})+(?!\d))/g,",")+(void 0!==a[1]?"."+a[1].replace(/[^\d.]*/gi,""):"")},String.prototype.toFormulaString=function(a){var b=parseInt(this);return 106===b?"x":(187===b||61===b)&&!0===a||107===b?"+":189===b||173===b||109===b?"-":190===b||110===b?".":191===b||111===b?"/":String.fromCharCode(b)},function(a){a.fn.formula=function(b){var c={id:"formula",cursorAnimTime:160,cursorDelayTime:500,strings:{formula:"Formula",validationError:"Validation Error",validationPassed:"Passed"},import:{item:null},export:{filter:function(a){return a},item:function(a){return"undefined"!==a.data("value")&&null!==a.data("value")?a.data("value"):a.text()}}},d=arguments;return a.extend(c,b),this.each(function(){var e=a(this);e.data("formula",this),this.init=function(){var b=this,d=!1,f=!1,g=null;b.container=a(b).addClass(b.opt.id+"-container"),b.container.wrap('<div class="'+b.opt.id+'-wrapper"></div>'),b.alert=a('<div class="'+b.opt.id+'-alert">'+c.strings.formula+"</div>"),b.alert.insertBefore(b.container),b.text=a('<textarea id="'+b.opt.id+'-text" name="'+b.opt.id+'-text" class="'+b.opt.id+'-text"></textarea>'),b.text.insertAfter(b.container).focus(),b.text.bind("blur",function(){null!==b.cursor&&(b.cursor.remove(),b.destroyDrag())}),b.text.unbind("dblclick."+b.opt.id+"Handler").bind("dblclick."+b.opt.id+"Handler",function(a){b.selectAll()}),b.text.unbind("mousedown."+b.opt.id+"Handler").bind("mousedown."+b.opt.id+"Handler",function(a){d=!0,g={x:a.offsetX,y:a.offsetY}}),b.text.unbind("mouseup."+b.opt.id+"Handler").bind("mouseup."+b.opt.id+"Handler",function(a){d=!1,!0===f?f=!1:b.click({x:a.offsetX,y:a.offsetY})});var h;b.text.unbind("mousemove."+b.opt.id+"Handler").bind("mousemove."+b.opt.id+"Handler",function(c){if(!1===d)return!0;if(Math.abs(g.x-c.offsetX)<=5&&Math.abs(g.y-c.offsetY)<=5)return!0;if(b.container.hasClass("formula-active")&&b.click({x:c.offsetX,y:c.offsetY}),f=!0,b.container.find("."+b.opt.id+"-drag").length>0){var e=0;b.destroyDrag(),b.click({x:c.offsetX,y:c.offsetY}),e=b.cursor.index(),$drag=a('<div class="'+b.opt.id+'-drag"></div>');var i=0,j=0;if(h>e?(j=h,i=e,$drag.insertBefore(b.cursor)):(i=h,j=e,$drag.insertAfter(b.cursor)),i===j)return!0;b.container.children(':not(".'+b.opt.id+'-cursor")').filter(':gt("'+i+'")').filter(':lt("'+(j-i)+'")').add(b.container.children(':not(".'+b.opt.id+'-cursor")').eq(i)).each(function(){a(this).appendTo($drag)}),h>e?$drag.insertAfter(b.cursor):$drag.insertBefore(b.cursor)}else b.destroyDrag(),b.click({x:c.offsetX,y:c.offsetY}),h=b.cursor.index(),$drag=a('<div class="'+b.opt.id+'-drag"></div>'),$drag.insertAfter(b.cursor)}),b.text.unbind("keydown."+b.opt.id+"Handler").bind("keydown."+b.opt.id+"Handler",function(c){c.preventDefault();var d,f,g,h,i,j;if(null!==b.cursor&&b.cursor.length>0){var k=c.which;if(116===k||82===k&&c.ctrlKey)location.reload();else if(65===k&&c.ctrlKey)b.selectAll();else if(k>=96&&k<=105)k-=48;else{if(8===k)return d=b.container.find("."+b.opt.id+"-drag"),d.length>0?(b.cursor.insertBefore(d),d.remove()):b.cursor.length>0&&b.cursor.prev().length>0&&(f=b.cursor.prev(),f.hasClass(b.opt.id+"-unit")&&f.text().length>1?(j=f.text(),b.setDecimal(f,j.substring(0,j.length-1).toFormulaDecimal())):f.remove()),b.syntaxCheck(),e.triggerHandler("formula.input",b.getFormula()),!1;if(46===k)return d=b.container.find("."+b.opt.id+"-drag"),d.length>0?(b.cursor.insertAfter(d),d.remove()):b.cursor.length>0&&b.cursor.next().length>0&&(g=b.cursor.next(),g.hasClass(b.opt.id+"-unit")&&g.text().length>1?(j=g.text(),b.setDecimal(g,j.substring(1,j.length).toFormulaDecimal())):g.remove()),b.syntaxCheck(),e.triggerHandler("formula.input",b.getFormula()),!1;if(k>=37&&k<=40)return 37===k?b.cursor.length>0&&b.cursor.prev().length>0?c.shiftKey?(d=b.container.find("."+b.opt.id+"-drag"),d.length<1?(d=a('<div class="'+b.opt.id+'-drag"></div>'),d.insertAfter(b.cursor)):!1===d.data("active")&&(b.destroyDrag(),d=a('<div class="'+b.opt.id+'-drag"></div>'),d.insertAfter(b.cursor)),d.data("active",!0),f=b.cursor.prev(),f.hasClass(b.opt.id+"-drag")?(i=d.children("*"),i.length<1?d.remove():(i.last().insertAfter(d),b.cursor.insertAfter(d))):b.cursor.prev().prependTo(d)):(b.destroyDrag(),b.cursor.insertBefore(b.cursor.prev())):b.destroyDrag():38===k?(b.cursor.prev().length>0||b.cursor.next().length>0)&&({x:parseFloat(b.container.css("padding-left").replace(/[^\d.]/gi,"")),y:parseFloat(b.container.css("padding-top").replace(/[^\d.]/gi,""))},h=b.cursor.prev(),h.length<0&&(h=b.cursor.next()),b.click({x:b.cursor.position().left+h.outerWidth(),y:b.cursor.position().top-h.outerHeight()/2})):39===k?b.cursor.length>0&&b.cursor.next().length>0?c.shiftKey?(d=b.container.find("."+b.opt.id+"-drag"),d.length<1?(d=a('<div class="'+b.opt.id+'-drag"></div>'),d.insertBefore(b.cursor)):!1===d.data("active")&&(b.destroyDrag(),d=a('<div class="'+b.opt.id+'-drag"></div>'),d.insertBefore(b.cursor)),d.data("active",!0),g=b.cursor.next(),g.hasClass(b.opt.id+"-drag")?(i=d.children("*"),i.length<1?d.remove():(i.first().insertBefore(d),b.cursor.insertBefore(d))):b.cursor.next().appendTo(d)):(b.destroyDrag(),b.cursor.insertAfter(b.cursor.next())):b.destroyDrag():40===k&&(b.cursor.prev().length>0||b.cursor.next().length>0)&&({x:parseFloat(b.container.css("padding-left").replace(/[^\d.]/gi,"")),y:parseFloat(b.container.css("padding-top").replace(/[^\d.]/gi,""))},h=b.cursor.prev(),h.length<0&&(h=b.cursor.next()),b.click({x:b.cursor.position().left+h.outerWidth(),y:b.cursor.position().top+1.5*h.outerHeight()})),!1;if(35===k||36===k)if(35===k)b.cursor.length>0&&b.container.children(":last").length>0&&(c.shiftKey?(d=b.container.find("."+b.opt.id+"-drag"),d.length<1?(d=a('<div class="'+b.opt.id+'-drag"></div>'),d.insertBefore(b.cursor)):!1===d.data("active")&&(b.destroyDrag(),d=a('<div class="'+b.opt.id+'-drag"></div>'),d.insertBefore(b.cursor)),d.data("active",!0),b.cursor.nextAll().appendTo(d)):(b.destroyDrag(),b.cursor.insertAfter(b.container.children(":last"))));else{if(36!==k)return!1;b.cursor.length>0&&b.container.children(":first").length>0&&(c.shiftKey?(d=b.container.find("."+b.opt.id+"-drag"),d.length<1?(d=a('<div class="'+b.opt.id+'-drag"></div>'),d.insertAfter(b.cursor)):!1===d.data("active")&&(b.destroyDrag(),d=a('<div class="'+b.opt.id+'-drag"></div>'),d.insertAfter(b.cursor)),d.data("active",!0),b.cursor.prevAll().each(function(){a(this).prependTo(d)})):(b.destroyDrag(),b.cursor.insertBefore(b.container.children(":first"))))}else if(!1==(k>=48&&k<=57)&&!0==(88!==k&&187!==k&&189!==k&&190!==k&&191!==k))return!1}b.keydown(k.toString().toFormulaString(c.shiftKey),c.shiftKey),b.syntaxCheck()}})},this.syntaxCheck=function(a){var b=this,c=b.getFormula().data;if(void 0!==c){return!0===new FormulaParser(c).status?(b.alert.text(b.opt.strings.validationPassed).addClass(b.opt.id+"-alert-good").removeClass(b.opt.id+"-alert-error"),"function"==typeof a&&a(!0),!0):(b.alert.text(b.opt.strings.validationError).removeClass(b.opt.id+"-alert-good").addClass(b.opt.id+"-alert-error"),"function"==typeof a&&a(!1),!1)}},this.destroyDrag=function(){var b=this,c=b.container.find("."+b.opt.id+"-drag");c.children("*").each(function(){a(this).insertBefore(c)}),c.remove(),e.triggerHandler("formula.input",b.getFormula())},this.selectAll=function(){var b=this;b.destroyDrag(),$drag=a('<div class="'+b.opt.id+'-drag"></div>'),$drag.prependTo(b.container),b.container.children(':not(".'+b.opt.id+'-cursor")').each(function(){a(this).appendTo($drag)})},this.click=function(b){var c=this;c.container.find("."+c.opt.id+"-cursor").remove();var d=a('<div class="'+c.opt.id+'-cursor"></div>'),e=null,f=null;b=b||{x:0,y:0},d.appendTo(c.container),c.cursor=d;var g={x:c.container.offset().left,y:c.container.offset().top},h={x:parseFloat(c.container.css("padding-left").replace(/[^\d.]/gi,"")),y:parseFloat(c.container.css("padding-top").replace(/[^\d.]/gi,""))},i=[];c.container.children('*:not(".'+c.opt.id+'-cursor")').each(function(){var b=a(this);i.push({x:b.offset().left-g.x+h.x,y:b.offset().top-g.y,e:b})});var j=null,k=0,l=1e4;for(f in i)e=i[f],e.y<=b.y&&e.y>=.5*k&&e.x<=b.x&&(e.y>=k&&(k=e.y),b.x-e.x<=l&&(l=b.x-e.x,j=e.e));if(null===j){k=0,l=1e4;for(f in i)e=i[f],e.y>=.5*k&&e.x<=b.x&&(e.y>=k&&(k=e.y),b.x-e.x<l&&(l=b.x-e.x,j=e.e))}i.length>0&&null!==j&&k+i[0].e.outerHeight()>=b.y?c.cursor.insertAfter(j):i.length>0&&b.x>i[0].x?c.cursor.appendTo(c.container):c.cursor.prependTo(c.container);var m=function(){setTimeout(function(){d.hasClass("inactive")?(d.removeClass("inactive"),d.stop().animate({opacity:1},c.opt.cursorAnimTime)):(d.addClass("inactive"),d.stop().animate({opacity:0},c.opt.cursorAnimTime)),d.length>0&&m()},c.opt.cursorDelayTime)};m(),c.destroyDrag()},this.keydown=function(b,c){var d=this,e={0:")",1:"!",2:"@",3:"#",4:"$",5:"%",6:"^",7:"&",8:"x",9:"("};c&&b>=0&&b<=9&&(b=e[b]),b=a.trim(b),d.insertChar.call(d,b)},this.insert=function(b,c){var d=this;(null===d.cursor||d.cursor.length<1||"object"==typeof c)&&d.click(c),"string"==typeof b&&(b=a(b)),b.addClass(d.opt.id+"-item"),b.insertBefore(d.cursor),d.text.focus(),d.syntaxCheck(),e.triggerHandler("formula.input",d.getFormula())},this.insertChar=function(b){var c=this;if(b>=0&&b<=9||-1!=a.inArray(b.toLowerCase(),c.permitedKey)){if(b>=0&&b<=9||"."===b){var d=a('<div class="'+c.opt.id+"-item "+c.opt.id+'-unit">'+b+"</div>"),f=null,g="",h=!1;$drag=c.container.find("."+c.opt.id+"-drag"),$drag.length>0&&(c.cursor.insertBefore($drag),$drag.remove()),null!==c.cursor&&c.cursor.length>0?c.cursor.before(d):c.container.append(d);var i=d.prev(),j=d.next();i.length>0&&i.hasClass(c.opt.id+"-cursor")&&(i=i.prev()),j.length>0&&j.hasClass(c.opt.id+"-cursor")&&(j=j.next()),i.length>0&&i.hasClass(c.opt.id+"-unit")?(h=!0,f=i,f.append(d[0].innerHTML)):j.length>0&&j.hasClass(c.opt.id+"-unit")&&(h=!0,f=j,f.prepend(d[0].innerHTML)),!0===h&&(g=f.text().toFormulaDecimal(),c.setDecimal(f,g),d.remove())}else if(""!==b){var k=a('<div class="'+c.opt.id+"-item "+c.opt.id+'-operator">'+b.toLowerCase()+"</div>");null!==c.cursor&&c.cursor.length>0?c.cursor.before(k):c.container.append(k),"("!==b&&")"!==b||k.addClass(c.opt.id+"-bracket")}e.triggerHandler("formula.input",c.getFormula())}},this.insertFormula=function(a){var b=this,c=0;if("string"==typeof a){var d=a.split("");for(c in d)b.insertChar.call(b,d[c])}else for(c in a){var f=a[c];if("object"!=typeof f){var g=f.toString().split("");for(var h in g)b.insertChar.call(b,g[h])}else if("function"==typeof b.opt.import.item){var i=b.opt.import.item.call(b,f);void 0!==i&&null!==i&&b.insert(i)}}b.syntaxCheck(),e.triggerHandler("formula.input",b.getFormula())},this.empty=function(){var a=this;return a.container.find(':not(".'+a.opt.id+'-cursor")').remove(),e.triggerHandler("formula.input",a.getFormula()),a.container},this.setDecimal=function(b,c){var d=this;if(""!==c){b.empty();var e=c.split(".");if(a('<span class="'+d.opt.id+"-prefix "+d.opt.id+'-decimal-highlight">'+e[0]+"</span>").appendTo(b),void 0!==e[1]){a('<span class="'+d.opt.id+"-surfix "+d.opt.id+'-decimal-highlight">.'+e[1]+"</span>").appendTo(b)}}},this.setFormula=function(a){var b=this;b.empty();try{var c=null;c="object"!=typeof a?JSON.parse(a):a;var d=new FormulaParser(c);!0===d.status&&b.insertFormula.call(b,d.data)}catch(a){console.trace(a.stack)}},this.getFormula=function(b){var c,d=this,e=[],f=null;return"function"==typeof d.opt.export.filter?(d.container.find(".formula-item").each(function(){var b=a(this),c={};if(c.value=b.data("value")?b.data("value"):b.text(),b.hasClass(d.opt.id+"-unit"))c.type="unit",c.value=c.value.toFormulaDecimal();else if(b.hasClass(d.opt.id+"-custom"))if(c.type="item",void 0!==d.opt.export&&"function"==typeof d.opt.export.item)try{c.value=d.opt.export.item.call(d,b)}catch(a){c.value="0"}else c.value="0";else b.hasClass(d.opt.id+"-operator")&&(c="x"===c.value?"*":c.value);e.push(c)}),e=e,f=new FormulaParser(Object.assign([],e)),f.data=d.opt.export.filter(f.data),c={data:e,filterData:f}):(d.container.find(".formula-item").each(function(){var b=a(this),c=b.data("value")?b.data("value"):b.text();if(b.hasClass(d.opt.id+"-unit"))c=c.toFormulaDecimal();else if(b.hasClass(d.opt.id+"-operator")&&"x"===c)c="*";else if(b.hasClass(d.opt.id+"-custom"))if(void 0!==d.opt.export&&"function"==typeof d.opt.export.item)try{c=d.opt.export.call(d,b)}catch(a){c="0"}else c="0";e.push(c)}),c={data:e.join(" "),filterData:f}),"function"==typeof b&&b(c),c},d.length<1||"object"==typeof d[0]?(this.alert=null,this.text=null,this.container=null,this.cursor=null,this.opt=c,this.permitedKey=[0,1,2,3,4,5,6,7,8,9,0,"x","*","/",".","+","-","%","^","(",")"],a.extend(b,c),this.init.call(this)):this[b].apply(this,Array.prototype.slice.call(d,1))})},a.fn.formula.getVersion=function(){return"2.0.12"}}(jQuery);var FormulaParser=function(){function a(a){var b;this.formula=a,this.OperandToken={},this.OperandToken.Addition=["+"],this.OperandToken.Subtraction=["-"],this.OperandToken.Multiplication=["x","*"],this.OperandToken.Division=["/"],this.OperandToken.Mod=["%"],this.OperandToken.Pow=["^"],this.OperandToken.Bracket=["(",")","[","]","{","}"],this.OperandPriority=[],this.OperandPriority[0]=[].concat(this.OperandToken.Mod,this.OperandToken.Pow),this.OperandPriority[1]=[].concat(this.OperandToken.Multiplication,this.OperandToken.Division),this.OperandPriority[2]=[].concat(this.OperandToken.Addition,this.OperandToken.Subtraction),this.Operators=[];for(b in this.OperandToken){var c=this.OperandToken[b];this.Operators=this.Operators.concat(c)}this.Units=[].concat(this.Operators,this.OperandToken.Bracket),this.Parsers=["Initializer","LayerParser","SyntaxParser","FilterParser","StringParser"],this.ParserMap={};for(b in this.Parsers){var d=this.Parsers[b];this.ParserMap[d]=d}return this.Message={},this.Message[1]="Formula must has characters than {0} times",this.Message[2]="'{0}' operator is not supported.",this.Message[3]="Left side operand is not valid.",this.Message[4]="Right side operand is not valid.",this.Message[5]="Bracket must be opened.",this.Message[6]="Bracket must be closed.",this.Message[32]="Operator's key must be in data.",this.Message[33]="Left operand's key must be in data.",this.Message[34]="Right operand's key must be in data.",this.Message[160]="Formula expression is null or undefined.",this.init()}return a.getVersion=function(){return"2.0.11"},a.prototype.inArray=function(a,b){for(var c in b)if(b[c]===a)return c;return-1},a.prototype.isOperand=function(a){return"object"==typeof a||this.isNumeric(a)},a.prototype.getOperatorPriority=function(a){if(-1===this.inArray(a,this.Operators))return-1;for(var b=-1,c=0;c<this.OperandPriority.length;c++)if(-1!==this.inArray(a,this.OperandPriority[c])){b=c;break}return b},a.prototype.isNumeric=function(a){return/\d+(\.\d*)?|\.\d+/.test(a)},a.prototype.stringToArray=function(a){for(var b=[],c=a.split(""),d=c.length,e=0;e<d;e++){var f=c[e];-1===this.inArray(f,this.Units)&&!0!==this.isOperand(f)||(e>0&&!0===this.isOperand(f)&&!0===this.isOperand(b[b.length-1])?b[b.length-1]+=f.toString():b.push(f))}return b},a.prototype.log=function(a,b,c){var d,e,f=this.Message[a];for(d in c)e=c[d],f=f.replace(new RegExp("\\{"+d+"\\}","g"),e);var g={status:0===a,code:a,msg:f};if(void 0!==b&&null!==b)for(d in b)"function"!=typeof(e=b[d])&&(g[d]=e);return g},a.prototype.layerParser=function(a,b,c){var d=0,e=[],f=[],g=this.ParserMap.LayerParser,h=a.length;if(c=c||0,"object"==typeof a&&1===a.length)return{status:!0,data:a[0],length:1};for(var i=0;i<a.length;i++){var j=a[i];if("("===j)d++,e[d]=i+1;else if(")"===j){if(d<1)return this.log(5,{stack:g,col:e.length>0?e[e.length-1]:0});if(1===d){var k=[];f[d]=i-1;for(var l=e[d];l<=f[d];l++)k.push(a[l]);var m=this.search(k,b+e[d]+1,c+1);if(!1===m.status)return m;var n=m.length;"object"==typeof m.data&&"object"!=typeof m.data[0]&&1===m.data.length&&(m.data=m.data[0]),a.splice(e[d]-1,n+2,m.data),i-=n+1}d--}}return d>0?this.log(6,{stack:g,col:a.length||-1}):{status:!0,depth:c,length:h||-1}},a.prototype.syntaxParser=function(a,b,c,d,e){this.currentParser=this.ParserMap.SyntaxParser,a=a||[],b=b||0,c=c||0;var f=b;if(void 0===a[0]||null===a[0]||"object"!=typeof a[0][0]||void 0!==a[0].operator&&null!==a[0].operator||(a[0]=a[0][0]),a.length<3)return"object"==typeof a&&1===a.length?a[0]:this.log(1,{stack:this.currentParser,col:b+("object"==typeof a[0]?a[0].length:0)+1},[3]);if(void 0!==a.length&&a.length>1)for(var g=0;g<a.length;g++){f=g+b;var h=a[g];if(-1===this.inArray(h,this.Operators)&&!1===this.isOperand(h))return this.log(2,{stack:this.currentParser,col:f},[h]);if(-1!==this.inArray(h,e)){if(!1===this.isOperand(a[g-1]))return this.log(3,{stack:this.currentParser,col:f-1});if(!1===this.isOperand(a[g+1]))return this.log(4,{stack:this.currentParser,col:f+1});"object"==typeof a[g-1]&&1===a[g-1].length&&(a[g-1]=a[g-1][0]),"object"==typeof a[g+1]&&1===a[g+1].length&&(a[g+1]=a[g+1][0]),a.splice(g-1,3,{operator:h,operand1:a[g-1],operand2:a[g+1],length:d}),"object"==typeof a[g-1][0]&&(a[g-1]=a[g-1][0]),g--}}return{status:!0,data:a}},a.prototype.filterParser=function(a){return"object"==typeof a.operand1&&this.filterParser(a.operand1),"object"==typeof a.operand2&&this.filterParser(a.operand2),void 0!==a.length&&delete a.length,"object"==typeof a&&1===a.length&&(a=a[0]),a},a.prototype.stringParser=function(a,b,c){this.currentParser=this.ParserMap.StringParser;var d=this,e=[];if(b=b||0,c=c||0,void 0!==a.value&&null!==a.value)return{status:!0,data:"unit"===a.value.type?a.value.unit:a.value};if(void 0===a.operator||null===a.operator)return this.log(32,{stack:this.currentParser,col:c,depth:b});if(void 0===a.operand1||null===a.operand1)return this.log(33,{stack:this.currentParser,col:c,depth:b});if(void 0===a.operand2||null===a.operand2)return this.log(34,{stack:this.currentParser,col:c,depth:b});for(var f=["operand1","operator","operand2"],g=0;g<f.length;g++){var h=f[g];if("object"==typeof a[h]){var i=d.stringParser(a[h],b+1,c+g);if(!1===i.status)return i;e=e.concat(i.data),void 0!==a.operator&&null!==a.operator&&void 0!==i.operator&&null!==i.operator&&this.getOperatorPriority(a.operator)<this.getOperatorPriority(i.operator)&&-1!==this.getOperatorPriority(a.operator)&&(e.splice([e.length-3],0,"("),e.splice([e.length],0,")"))}else e.push(a[h])}return{status:!0,data:e,operator:b>0?a.operator:void 0}},a.prototype.search=function(a,b,c){var d=this;b=b||0,c=c||0,"string"==typeof a&&c<1&&(a=this.stringToArray(a));for(var e=null,f=this.OperandPriority.length+1,g=0,h=function(){return 0===c&&(a=d.filterParser(a)),{status:!0,data:a,length:0===c?void 0:g,depth:0===c?void 0:c}},i=0;i<f;i++){if(null!==e&&void 0!==e.data&&1===e.data.length)return h.call();if(0===i?(e=this.layerParser(a,b,c),g=e.length):e=this.syntaxParser(a,b,c,g,this.OperandPriority[i-1]),!1===e.status)return e;if(i+1===f)return h.call()}},a.prototype.collapse=function(a,b){var c=null;return b=b||0,c=this.stringParser(a,b),{status:!0,data:c.data}},a.prototype.init=function(){return void 0===this.formula||null===this.formula?this.log(160,{stack:this.Parsers.Initializer,col:0}):"string"==typeof this.formula||"object"==typeof this.formula&&(void 0===this.formula.operator||null===this.formula.operator)?this.search(this.formula):"object"==typeof this.formula&&void 0!==this.formula.operator&&null!==this.formula.operator?this.collapse(this.formula):void console.error("Unkown type formula",this.formula)},a}();