cie-calculator
Version:
Easily generate CIE References
2 lines (1 loc) • 42 kB
JavaScript
!function(f){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=f();else if("function"==typeof define&&define.amd)define([],f);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).CIECalculator=f()}}(function(){var define,module,exports;return function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){return o(e[i][1][r]||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}({1:[function(require,module,exports){"use strict";var CIEStrategy=require("./cie_strategy.js").CIEStrategy,cieUtils=new(require("./cie_utils.js").CIEUtils),Alg00=function(){};Alg00.prototype=new CIEStrategy,Alg00.prototype={execute:function(input){if(!cieUtils.validateInput(input,{reference:{length:{min:1,max:19}}})){var error=new Error("Longitud invalida");throw error.status="422",error}for(var acc=0,tmpInput=input.reference.split("").reverse().join(""),i=0;i<input.reference.length;i++)acc+=cieUtils.sequentialAdd(parseInt(tmpInput[i],10)*((i+1)%2!=0?2:1));return input.reference+(cieUtils.nearestMultipleOf(acc,10)-acc)%10}},module.exports.Alg00=Alg00},{"./cie_strategy.js":15,"./cie_utils.js":16}],2:[function(require,module,exports){"use strict";var CIEStrategy=require("./cie_strategy.js").CIEStrategy,cieUtils=new(require("./cie_utils.js").CIEUtils),Alg02=function(){};Alg02.prototype=new CIEStrategy,Alg02.prototype={execute:function(input){if(!cieUtils.validateInput(input,{reference:{length:{min:6,max:19}}}))throw new Error("Longitud invalida");for(var acc=0,reference=parseInput(input).reverse(),i=0;i<reference.length;i++){var m=(i+1)%2!=0?2:1;acc+=cieUtils.sequentialAdd(parseInt(reference[i],10)*m)}return input.reference.toUpperCase()+(cieUtils.nearestMultipleOf(acc,10)-acc)}},module.exports.Alg02=Alg02;var parseInput=function(input){return cieUtils.replaceCharWithNum(input.reference.toUpperCase(),{A:1,B:2,C:3,D:4,E:5,F:6,G:7,H:8,I:9,J:1,K:2,L:3,M:4,N:5,O:6,P:7,Q:8,R:9,S:1,T:2,U:3,V:4,W:5,X:6,Y:7,Z:8,1:1,2:2,3:3,4:4,5:5,6:6,7:7,8:8,9:9,0:0})}},{"./cie_strategy.js":15,"./cie_utils.js":16}],3:[function(require,module,exports){"use strict";var _=require("underscore"),CIEStrategy=require("./cie_strategy.js").CIEStrategy,cieUtils=new(require("./cie_utils.js").CIEUtils),Alg03=function(){};Alg03.prototype=new CIEStrategy,Alg03.prototype={execute:function(input){if(!cieUtils.validateInput(input,{reference:{length:{min:1,max:19}}}))throw new Error("Longitud invalida");for(var acc=0,reference=parseInput(input),i=0;i<reference.length;i++)acc+=parseInt(reference[i],10)*(i+2);return input.reference+(7-acc%7)}},module.exports.Alg03=Alg03;var parseInput=function(input){return _.last(input.reference,6).reverse()}},{"./cie_strategy.js":15,"./cie_utils.js":16,underscore:18}],4:[function(require,module,exports){"use strict";var _=require("underscore"),CIEStrategy=require("./cie_strategy.js").CIEStrategy,cieUtils=new(require("./cie_utils.js").CIEUtils),Alg04=function(){};Alg04.prototype=new CIEStrategy,Alg04.prototype={execute:function(input){if(!cieUtils.validateInput(input,{reference:{length:{min:1,max:18}}}))throw new Error("Longitud invalida");var reference=parseInput(input),acc=cieUtils.weightedReduce(reference,[11,13,17,19,23])-11*reference[0];return input.reference+cieUtils.pad((acc+330)%97+1,2)}},module.exports.Alg04=Alg04;var parseInput=function(input){return _.toArray(input.reference).reverse()}},{"./cie_strategy.js":15,"./cie_utils.js":16,underscore:18}],5:[function(require,module,exports){"use strict";var _=require("underscore"),CIEStrategy=require("./cie_strategy.js").CIEStrategy,cieUtils=new(require("./cie_utils.js").CIEUtils),Alg06=function(){};Alg06.prototype=new CIEStrategy,Alg06.prototype={execute:function(input){if(!cieUtils.validateInput(input,{reference:{length:{min:1,max:18}},branch:{length:{min:1,max:8}},account:{length:{min:1,max:8}}}))throw new Error("Longitud invalida");var reference=parseInput(input),acc=cieUtils.weightedReduce(reference,[37,31,29,23,19,17,13,11]);return input.reference+(99-acc%97)}},module.exports.Alg06=Alg06;var parseInput=function(input){var paddedBranch=_.toArray(cieUtils.pad(input.branch,8)),paddedAccount=_.toArray(cieUtils.pad(input.account,8)),paddedReference=_.last(cieUtils.pad(input.reference,8),8);return paddedBranch.concat(paddedAccount,paddedReference).reverse()}},{"./cie_strategy.js":15,"./cie_utils.js":16,underscore:18}],6:[function(require,module,exports){"use strict";var _=require("underscore"),CIEStrategy=require("./cie_strategy.js").CIEStrategy,cieUtils=new(require("./cie_utils.js").CIEUtils),Alg10=function(){};Alg10.prototype=new CIEStrategy,Alg10.prototype={execute:function(input){if(!cieUtils.validateInput(input,{reference:{length:{min:1,max:12}},date:{length:{min:8,max:8}},amount:{length:{min:1,max:12}}}))throw new Error("Longitud invalida");var condensedInput=parseInput(input),acc=cieUtils.weightedReduce(condensedInput.reference,[11,13,17,19,23]);return input.reference+condensedInput.date+condensedInput.amount+"2"+cieUtils.pad(acc%97+1,2)}},module.exports.Alg10=Alg10;var parseInput=function(input){var paddedDate=cieUtils.pad(372*(input.date.substr(4,4)-2014)+31*(input.date.substr(2,2)-1)+(input.date.substr(0,2)-1),4),paddedAmount=cieUtils.weightedReduce(_.without(_.toArray(input.amount),".").reverse(),[7,3,1])%10;return{reference:_.toArray(input.reference+paddedDate+paddedAmount+"2").reverse(),amount:paddedAmount,date:paddedDate}}},{"./cie_strategy.js":15,"./cie_utils.js":16,underscore:18}],7:[function(require,module,exports){"use strict";var _=require("underscore"),CIEStrategy=require("./cie_strategy.js").CIEStrategy,cieUtils=new(require("./cie_utils.js").CIEUtils),Alg21=function(){};Alg21.prototype=new CIEStrategy,Alg21.prototype={execute:function(input){if(!cieUtils.validateInput(input,{reference:{length:{min:1,max:20}},date:{length:{min:8,max:8}},amount:{length:{min:1,max:15}}}))throw new Error("Longitud invalida");var condensedInput=parseInput(input),acc_2=(cieUtils.weightedReduce(_.toArray(condensedInput.reference).reverse(),[11,13,17,19,23])%97+1)%10;return condensedInput.reference+acc_2}},module.exports.Alg21=Alg21;var parseInput=function(input){var year,month_multiplier=31;switch(input.date.substr(2,2)){case 4:case 6:case 9:case 11:month_multiplier=30;break;case 2:year=input.date.substr(4,4),console.log("year",year),month_multiplier=29===new Date(year,1,29).getDate()?29:28}var paddedDate=cieUtils.pad(360*(input.date.substr(4,4)-2014)+(input.date.substr(2,2)-1)*month_multiplier+(input.date.substr(0,2)-1),4),paddedAmount1=cieUtils.weightedReduce(_.without(_.toArray(input.amount),".").reverse(),[1,2,3,7,11,13,17])%10,paddedAmount2=cieUtils.weightedReduce(_.without(_.toArray(input.amount),".").reverse(),[2,3,7,11,13,17,1])%10,paddedAmount3=cieUtils.weightedReduce(_.without(_.toArray(input.amount),".").reverse(),[3,7,11,13,17,1,2])%10;return{reference:input.reference+paddedDate+paddedAmount1+paddedAmount2+paddedAmount3,amount:""+paddedAmount1+paddedAmount2+paddedAmount3,date:paddedDate}}},{"./cie_strategy.js":15,"./cie_utils.js":16,underscore:18}],8:[function(require,module,exports){"use strict";var CIEStrategy=require("./cie_strategy.js").CIEStrategy,cieUtils=new(require("./cie_utils.js").CIEUtils),Alg35=function(){};Alg35.prototype=new CIEStrategy,Alg35.prototype={execute:function(input){if(!cieUtils.validateInput(input,{reference:{length:{min:1,max:19}}}))throw new Error("Longitud invalida");var acc=cieUtils.sequentialWeightedReduce(parseInput(input),[4,3,8]);return input.reference.toUpperCase()+(cieUtils.nearestMultipleOf(acc,10)-acc)%10}},module.exports.Alg35=Alg35;var parseInput=function(input){return cieUtils.replaceCharWithNum(input.reference.toUpperCase(),{A:1,B:2,C:3,D:4,E:5,F:6,G:7,H:8,I:9,J:10,K:11,L:12,M:13,N:14,O:15,P:16,Q:17,R:18,S:19,T:20,U:21,V:22,W:23,X:24,Y:25,Z:26,1:1,2:2,3:3,4:4,5:5,6:6,7:7,8:8,9:9,0:0})}},{"./cie_strategy.js":15,"./cie_utils.js":16}],9:[function(require,module,exports){"use strict";var _=require("underscore"),CIEStrategy=require("./cie_strategy.js").CIEStrategy,cieUtils=new(require("./cie_utils.js").CIEUtils),Alg36=function(){};Alg36.prototype=new CIEStrategy,Alg36.prototype={execute:function(input){if(!cieUtils.validateInput(input,{reference:{length:{min:1,max:19}}}))throw new Error("Longitud invalida");var acc=cieUtils.sequentialWeightedReduce(parseInput(input),[2,1]);return input.reference.toUpperCase()+(cieUtils.nearestMultipleOf(acc,10)-acc)%10}},module.exports.Alg36=Alg36;var parseInput=function(input){return _.toArray(cieUtils.replaceCharWithNum(input.reference.toUpperCase(),{A:1,B:2,C:3,D:4,E:5,F:6,G:7,H:8,I:9,J:1,K:2,L:3,M:4,N:5,O:6,P:7,Q:8,R:9,S:1,T:2,U:3,V:4,W:5,X:6,Y:7,Z:8,1:1,2:2,3:3,4:4,5:5,6:6,7:7,8:8,9:9,0:0})).reverse()}},{"./cie_strategy.js":15,"./cie_utils.js":16,underscore:18}],10:[function(require,module,exports){"use strict";var _=require("underscore"),CIEStrategy=require("./cie_strategy.js").CIEStrategy,cieUtils=new(require("./cie_utils.js").CIEUtils),Alg37=function(){};Alg37.prototype=new CIEStrategy,Alg37.prototype={execute:function(input){if(!cieUtils.validateInput(input,{reference:{length:{min:1,max:19}}}))throw new Error("Longitud invalida");var reference=parseInput(input),acc=cieUtils.weightedReduce(reference,[11,13,17,19,23]);return input.reference.toUpperCase()+cieUtils.pad((acc+330-11*reference[0])%97+1,2)}},module.exports.Alg37=Alg37;var parseInput=function(input){return _.toArray(cieUtils.replaceCharWithNum(input.reference.toUpperCase(),{A:1,B:2,C:3,D:4,E:5,F:6,G:7,H:8,I:9,J:1,K:2,L:3,M:4,N:5,O:6,P:7,Q:8,R:9,S:1,T:2,U:3,V:4,W:5,X:6,Y:7,Z:8,1:1,2:2,3:3,4:4,5:5,6:6,7:7,8:8,9:9,0:0})).reverse()}},{"./cie_strategy.js":15,"./cie_utils.js":16,underscore:18}],11:[function(require,module,exports){"use strict";var _=require("underscore"),CIEStrategy=require("./cie_strategy.js").CIEStrategy,cieUtils=new(require("./cie_utils.js").CIEUtils),Alg62=function(){};Alg62.prototype=new CIEStrategy,Alg62.prototype={execute:function(input){if(!cieUtils.validateInput(input,{reference:{length:{min:1,max:10}},date:{length:{min:8,max:8}},amount:{length:{min:1,max:12}}}))throw new Error("Longitud invalida");var condensedInput=parseInput(input);return input.reference+condensedInput.date+condensedInput.amount+"2"}},module.exports.Alg62=Alg62;var parseInput=function(input){var paddedDate=cieUtils.pad(372*(input.date.substr(4,4)-1988)+31*(input.date.substr(2,2)-1)+(input.date.substr(0,2)-1),4),expandedAmount=fooAmount(_.without(_.toArray(input.amount),".")),reducedAmount=weightedReduceWithMult(_.toArray(expandedAmount).reverse(),[7,3,1]);return{reference:_.toArray(input.reference+paddedDate+reducedAmount+"2").reverse(),amount:reducedAmount,date:paddedDate}},fooAmount=function(amount){return _.reduce(amount,function(memo,num){return memo+(memo.length<8?num+(parseInt(num)+1)+"":num)},"")},weightedReduceWithMult=function(input,weights,debug){for(var acc=0,acc2="",i=0;i<input.length;i++)debug&&console.log("input: "+input[i]+" w: "+weights[i%weights.length]+" = "+parseInt(input[i]*weights[i%weights.length])),acc+=parseInt(input[i]*weights[i%weights.length]),acc=cieUtils.sequentialAdd(acc),parseInt(i)%3==2&&(acc2+=acc%10);return acc2}},{"./cie_strategy.js":15,"./cie_utils.js":16,underscore:18}],12:[function(require,module,exports){"use strict";var _=require("underscore"),CIEStrategy=require("./cie_strategy.js").CIEStrategy,cieUtils=new(require("./cie_utils.js").CIEUtils),Alg77=function(){};Alg77.prototype=new CIEStrategy,Alg77.prototype={execute:function(input){if(!cieUtils.validateInput(input,{reference:{length:{min:1,max:12}},date:{length:{min:8,max:8}},amount:{length:{min:1,max:12}}}))throw new Error("Longitud invalida");var condensedInput=parseInput(input),acc=cieUtils.weightedReduce(condensedInput.reference,[11,13,17,19,23]);return input.reference+condensedInput.date+condensedInput.amount+"2"+cieUtils.pad(acc%97+1,2)}},module.exports.Alg77=Alg77;var parseInput=function(input){var paddedDate=cieUtils.pad(372*(input.date.substr(4,4)-2013)+31*(input.date.substr(2,2)-1)+(input.date.substr(0,2)-1),4),paddedAmount=cieUtils.weightedReduce(_.without(_.toArray(input.amount),".").reverse(),[7,3,1])%10;return{reference:_.toArray(input.reference+paddedDate+paddedAmount+"2").reverse(),amount:paddedAmount,date:paddedDate}}},{"./cie_strategy.js":15,"./cie_utils.js":16,underscore:18}],13:[function(require,module,exports){"use strict";var _=require("underscore"),CIEStrategy=require("./cie_strategy.js").CIEStrategy,cieUtils=new(require("./cie_utils.js").CIEUtils),Alg82=function(){};Alg82.prototype=new CIEStrategy,Alg82.prototype={execute:function(input){if(!cieUtils.validateInput(input,{reference:{length:{min:15,max:42}},date:{length:{min:8,max:8}},amount:{length:{min:1,max:12}},digit:{length:{min:1,max:1}}}))throw new Error("Longitud invalida");var condensedInput=parseInput(input),acc=cieUtils.weightedReduce(condensedInput.reference,[11,13,17,19,23]);return input.reference+condensedInput.date+condensedInput.amount+input.digit+cieUtils.pad(acc%97+1,2)}},module.exports.Alg82=Alg82;var parseInput=function(input){var numOnlyReference=cieUtils.replaceCharWithNum(input.reference.toUpperCase(),{A:1,B:2,C:3,D:4,E:5,F:6,G:7,H:8,I:9,J:1,K:2,L:3,M:4,N:5,O:6,P:7,Q:8,R:9,S:2,T:3,U:4,V:5,W:6,X:7,Y:8,Z:9,1:1,2:2,3:3,4:4,5:5,6:6,7:7,8:8,9:9,0:0}).join(""),paddedDate=cieUtils.pad(372*(input.date.substr(4,4)-2014)+31*(input.date.substr(2,2)-1)+(input.date.substr(0,2)-1),4),paddedAmount=cieUtils.weightedReduce(_.without(_.toArray(input.amount),".").reverse(),[7,3,1])%10;return{reference:_.toArray(numOnlyReference+paddedDate+paddedAmount+input.digit).reverse(),amount:paddedAmount,date:paddedDate}}},{"./cie_strategy.js":15,"./cie_utils.js":16,underscore:18}],14:[function(require,module,exports){"use strict";var CIECalculator=function(){this.strategy=""};CIECalculator.prototype={setStrategy:function(strategy){this.strategy=strategy},execute:function(reference){return this.strategy.execute(reference)}},module.exports.CIECalculator=CIECalculator},{}],15:[function(require,module,exports){"use strict";var CIEStrategy=function(){};CIEStrategy.prototype={execute:function(){throw new Error("CIEStrategy#execute needs to be overridden.")}},module.exports.CIEStrategy=CIEStrategy},{}],16:[function(require,module,exports){"use strict";var _=require("underscore"),CIEUtils=function(){};CIEUtils.prototype={nearestMultipleOf:function(val,base){return val%10==0?val:(Math.floor(val/base)+1)*base},sequentialAdd:function(input){return _.reduce(input.toString(),function(memo,num){return memo+parseInt(num)},0)},replaceCharWithNum:function(input,charToNum){return _.map(input,function(x){return charToNum[x]})},pad:function(n,width,z){return z=z||"0",(n+="").length>=width?n:new Array(width-n.length+1).join(z)+n},validateLength:function(field,min,max){return field.length>=min&&field.length<=max},weightedReduce:function(input,weights,debug){for(var acc=0,i=0;i<input.length;i++)debug&&console.log("input: "+input[i]+" w: "+weights[i%weights.length]+" = "+parseInt(input[i]*weights[i%weights.length])),acc+=parseInt(input[i]*weights[i%weights.length]);return acc},sequentialWeightedReduce:function(input,weights,debug){for(var acc=0,i=0;i<input.length;i++){debug&&console.log("input: "+input[i]+" w: "+weights[i%weights.length]+" = "+CIEUtils.prototype.sequentialAdd(parseInt(input[i]*weights[i%weights.length])));for(var tmp=CIEUtils.prototype.sequentialAdd(parseInt(input[i]*weights[i%weights.length]));1!==tmp.toString().length;)tmp=CIEUtils.prototype.sequentialAdd(tmp);acc+=tmp}return acc},validateInput:function(input,validationRules){return function(input,validationRules){return _.reduce(_.keys(validationRules),function(memo,k){return memo&&CIEUtils.prototype.validateLength(input[k],validationRules[k].length.min,validationRules[k].length.max)},!0)}(input,validationRules)}},module.exports.CIEUtils=CIEUtils},{underscore:18}],17:[function(require,module,exports){"use strict";var CIECalculator=require("./lib/strategies/cie_calculator.js").CIECalculator,Alg00=require("./lib/strategies/alg00.js").Alg00,Alg02=require("./lib/strategies/alg02.js").Alg02,Alg03=require("./lib/strategies/alg03.js").Alg03,Alg04=require("./lib/strategies/alg04.js").Alg04,Alg06=require("./lib/strategies/alg06.js").Alg06,Alg10=require("./lib/strategies/alg10.js").Alg10,Alg21=require("./lib/strategies/alg21.js").Alg21,Alg35=require("./lib/strategies/alg35.js").Alg35,Alg36=require("./lib/strategies/alg36.js").Alg36,Alg37=require("./lib/strategies/alg37.js").Alg37,Alg62=require("./lib/strategies/alg62.js").Alg62,Alg77=require("./lib/strategies/alg77.js").Alg77,Alg82=require("./lib/strategies/alg82.js").Alg82;module.exports=function(params){var calculator=new CIECalculator;return calculator.setStrategy(eval("new Alg"+params.alg+"()")),calculator.execute(params)}},{"./lib/strategies/alg00.js":1,"./lib/strategies/alg02.js":2,"./lib/strategies/alg03.js":3,"./lib/strategies/alg04.js":4,"./lib/strategies/alg06.js":5,"./lib/strategies/alg10.js":6,"./lib/strategies/alg21.js":7,"./lib/strategies/alg35.js":8,"./lib/strategies/alg36.js":9,"./lib/strategies/alg37.js":10,"./lib/strategies/alg62.js":11,"./lib/strategies/alg77.js":12,"./lib/strategies/alg82.js":13,"./lib/strategies/cie_calculator.js":14}],18:[function(require,module,exports){(function(){var root=this,previousUnderscore=root._,ArrayProto=Array.prototype,ObjProto=Object.prototype,FuncProto=Function.prototype,push=ArrayProto.push,slice=ArrayProto.slice,toString=ObjProto.toString,hasOwnProperty=ObjProto.hasOwnProperty,nativeIsArray=Array.isArray,nativeKeys=Object.keys,nativeBind=FuncProto.bind,nativeCreate=Object.create,Ctor=function(){},_=function(obj){return obj instanceof _?obj:this instanceof _?void(this._wrapped=obj):new _(obj)};void 0!==exports?(void 0!==module&&module.exports&&(exports=module.exports=_),exports._=_):root._=_,_.VERSION="1.8.3";var optimizeCb=function(func,context,argCount){if(void 0===context)return func;switch(null==argCount?3:argCount){case 1:return function(value){return func.call(context,value)};case 2:return function(value,other){return func.call(context,value,other)};case 3:return function(value,index,collection){return func.call(context,value,index,collection)};case 4:return function(accumulator,value,index,collection){return func.call(context,accumulator,value,index,collection)}}return function(){return func.apply(context,arguments)}},cb=function(value,context,argCount){return null==value?_.identity:_.isFunction(value)?optimizeCb(value,context,argCount):_.isObject(value)?_.matcher(value):_.property(value)};_.iteratee=function(value,context){return cb(value,context,1/0)};var createAssigner=function(keysFunc,undefinedOnly){return function(obj){var length=arguments.length;if(length<2||null==obj)return obj;for(var index=1;index<length;index++)for(var source=arguments[index],keys=keysFunc(source),l=keys.length,i=0;i<l;i++){var key=keys[i];undefinedOnly&&void 0!==obj[key]||(obj[key]=source[key])}return obj}},baseCreate=function(prototype){if(!_.isObject(prototype))return{};if(nativeCreate)return nativeCreate(prototype);Ctor.prototype=prototype;var result=new Ctor;return Ctor.prototype=null,result},property=function(key){return function(obj){return null==obj?void 0:obj[key]}},MAX_ARRAY_INDEX=Math.pow(2,53)-1,getLength=property("length"),isArrayLike=function(collection){var length=getLength(collection);return"number"==typeof length&&0<=length&&length<=MAX_ARRAY_INDEX};function createReduce(dir){return function(obj,iteratee,memo,context){iteratee=optimizeCb(iteratee,context,4);var keys=!isArrayLike(obj)&&_.keys(obj),length=(keys||obj).length,index=0<dir?0:length-1;return arguments.length<3&&(memo=obj[keys?keys[index]:index],index+=dir),function(obj,iteratee,memo,keys,index,length){for(;0<=index&&index<length;index+=dir){var currentKey=keys?keys[index]:index;memo=iteratee(memo,obj[currentKey],currentKey,obj)}return memo}(obj,iteratee,memo,keys,index,length)}}_.each=_.forEach=function(obj,iteratee,context){var i,length;if(iteratee=optimizeCb(iteratee,context),isArrayLike(obj))for(i=0,length=obj.length;i<length;i++)iteratee(obj[i],i,obj);else{var keys=_.keys(obj);for(i=0,length=keys.length;i<length;i++)iteratee(obj[keys[i]],keys[i],obj)}return obj},_.map=_.collect=function(obj,iteratee,context){iteratee=cb(iteratee,context);for(var keys=!isArrayLike(obj)&&_.keys(obj),length=(keys||obj).length,results=Array(length),index=0;index<length;index++){var currentKey=keys?keys[index]:index;results[index]=iteratee(obj[currentKey],currentKey,obj)}return results},_.reduce=_.foldl=_.inject=createReduce(1),_.reduceRight=_.foldr=createReduce(-1),_.find=_.detect=function(obj,predicate,context){var key;if(void 0!==(key=isArrayLike(obj)?_.findIndex(obj,predicate,context):_.findKey(obj,predicate,context))&&-1!==key)return obj[key]},_.filter=_.select=function(obj,predicate,context){var results=[];return predicate=cb(predicate,context),_.each(obj,function(value,index,list){predicate(value,index,list)&&results.push(value)}),results},_.reject=function(obj,predicate,context){return _.filter(obj,_.negate(cb(predicate)),context)},_.every=_.all=function(obj,predicate,context){predicate=cb(predicate,context);for(var keys=!isArrayLike(obj)&&_.keys(obj),length=(keys||obj).length,index=0;index<length;index++){var currentKey=keys?keys[index]:index;if(!predicate(obj[currentKey],currentKey,obj))return!1}return!0},_.some=_.any=function(obj,predicate,context){predicate=cb(predicate,context);for(var keys=!isArrayLike(obj)&&_.keys(obj),length=(keys||obj).length,index=0;index<length;index++){var currentKey=keys?keys[index]:index;if(predicate(obj[currentKey],currentKey,obj))return!0}return!1},_.contains=_.includes=_.include=function(obj,item,fromIndex,guard){return isArrayLike(obj)||(obj=_.values(obj)),("number"!=typeof fromIndex||guard)&&(fromIndex=0),0<=_.indexOf(obj,item,fromIndex)},_.invoke=function(obj,method){var args=slice.call(arguments,2),isFunc=_.isFunction(method);return _.map(obj,function(value){var func=isFunc?method:value[method];return null==func?func:func.apply(value,args)})},_.pluck=function(obj,key){return _.map(obj,_.property(key))},_.where=function(obj,attrs){return _.filter(obj,_.matcher(attrs))},_.findWhere=function(obj,attrs){return _.find(obj,_.matcher(attrs))},_.max=function(obj,iteratee,context){var value,computed,result=-1/0,lastComputed=-1/0;if(null==iteratee&&null!=obj)for(var i=0,length=(obj=isArrayLike(obj)?obj:_.values(obj)).length;i<length;i++)value=obj[i],result<value&&(result=value);else iteratee=cb(iteratee,context),_.each(obj,function(value,index,list){computed=iteratee(value,index,list),(lastComputed<computed||computed===-1/0&&result===-1/0)&&(result=value,lastComputed=computed)});return result},_.min=function(obj,iteratee,context){var value,computed,result=1/0,lastComputed=1/0;if(null==iteratee&&null!=obj)for(var i=0,length=(obj=isArrayLike(obj)?obj:_.values(obj)).length;i<length;i++)(value=obj[i])<result&&(result=value);else iteratee=cb(iteratee,context),_.each(obj,function(value,index,list){((computed=iteratee(value,index,list))<lastComputed||computed===1/0&&result===1/0)&&(result=value,lastComputed=computed)});return result},_.shuffle=function(obj){for(var rand,set=isArrayLike(obj)?obj:_.values(obj),length=set.length,shuffled=Array(length),index=0;index<length;index++)(rand=_.random(0,index))!==index&&(shuffled[index]=shuffled[rand]),shuffled[rand]=set[index];return shuffled},_.sample=function(obj,n,guard){return null==n||guard?(isArrayLike(obj)||(obj=_.values(obj)),obj[_.random(obj.length-1)]):_.shuffle(obj).slice(0,Math.max(0,n))},_.sortBy=function(obj,iteratee,context){return iteratee=cb(iteratee,context),_.pluck(_.map(obj,function(value,index,list){return{value:value,index:index,criteria:iteratee(value,index,list)}}).sort(function(left,right){var a=left.criteria,b=right.criteria;if(a!==b){if(b<a||void 0===a)return 1;if(a<b||void 0===b)return-1}return left.index-right.index}),"value")};var group=function(behavior){return function(obj,iteratee,context){var result={};return iteratee=cb(iteratee,context),_.each(obj,function(value,index){var key=iteratee(value,index,obj);behavior(result,value,key)}),result}};_.groupBy=group(function(result,value,key){_.has(result,key)?result[key].push(value):result[key]=[value]}),_.indexBy=group(function(result,value,key){result[key]=value}),_.countBy=group(function(result,value,key){_.has(result,key)?result[key]++:result[key]=1}),_.toArray=function(obj){return obj?_.isArray(obj)?slice.call(obj):isArrayLike(obj)?_.map(obj,_.identity):_.values(obj):[]},_.size=function(obj){return null==obj?0:isArrayLike(obj)?obj.length:_.keys(obj).length},_.partition=function(obj,predicate,context){predicate=cb(predicate,context);var pass=[],fail=[];return _.each(obj,function(value,key,obj){(predicate(value,key,obj)?pass:fail).push(value)}),[pass,fail]},_.first=_.head=_.take=function(array,n,guard){if(null!=array)return null==n||guard?array[0]:_.initial(array,array.length-n)},_.initial=function(array,n,guard){return slice.call(array,0,Math.max(0,array.length-(null==n||guard?1:n)))},_.last=function(array,n,guard){if(null!=array)return null==n||guard?array[array.length-1]:_.rest(array,Math.max(0,array.length-n))},_.rest=_.tail=_.drop=function(array,n,guard){return slice.call(array,null==n||guard?1:n)},_.compact=function(array){return _.filter(array,_.identity)};var flatten=function(input,shallow,strict,startIndex){for(var output=[],idx=0,i=startIndex||0,length=getLength(input);i<length;i++){var value=input[i];if(isArrayLike(value)&&(_.isArray(value)||_.isArguments(value))){shallow||(value=flatten(value,shallow,strict));var j=0,len=value.length;for(output.length+=len;j<len;)output[idx++]=value[j++]}else strict||(output[idx++]=value)}return output};function createPredicateIndexFinder(dir){return function(array,predicate,context){predicate=cb(predicate,context);for(var length=getLength(array),index=0<dir?0:length-1;0<=index&&index<length;index+=dir)if(predicate(array[index],index,array))return index;return-1}}function createIndexFinder(dir,predicateFind,sortedIndex){return function(array,item,idx){var i=0,length=getLength(array);if("number"==typeof idx)0<dir?i=0<=idx?idx:Math.max(idx+length,i):length=0<=idx?Math.min(idx+1,length):idx+length+1;else if(sortedIndex&&idx&&length)return array[idx=sortedIndex(array,item)]===item?idx:-1;if(item!=item)return 0<=(idx=predicateFind(slice.call(array,i,length),_.isNaN))?idx+i:-1;for(idx=0<dir?i:length-1;0<=idx&&idx<length;idx+=dir)if(array[idx]===item)return idx;return-1}}_.flatten=function(array,shallow){return flatten(array,shallow,!1)},_.without=function(array){return _.difference(array,slice.call(arguments,1))},_.uniq=_.unique=function(array,isSorted,iteratee,context){_.isBoolean(isSorted)||(context=iteratee,iteratee=isSorted,isSorted=!1),null!=iteratee&&(iteratee=cb(iteratee,context));for(var result=[],seen=[],i=0,length=getLength(array);i<length;i++){var value=array[i],computed=iteratee?iteratee(value,i,array):value;isSorted?(i&&seen===computed||result.push(value),seen=computed):iteratee?_.contains(seen,computed)||(seen.push(computed),result.push(value)):_.contains(result,value)||result.push(value)}return result},_.union=function(){return _.uniq(flatten(arguments,!0,!0))},_.intersection=function(array){for(var result=[],argsLength=arguments.length,i=0,length=getLength(array);i<length;i++){var item=array[i];if(!_.contains(result,item)){for(var j=1;j<argsLength&&_.contains(arguments[j],item);j++);j===argsLength&&result.push(item)}}return result},_.difference=function(array){var rest=flatten(arguments,!0,!0,1);return _.filter(array,function(value){return!_.contains(rest,value)})},_.zip=function(){return _.unzip(arguments)},_.unzip=function(array){for(var length=array&&_.max(array,getLength).length||0,result=Array(length),index=0;index<length;index++)result[index]=_.pluck(array,index);return result},_.object=function(list,values){for(var result={},i=0,length=getLength(list);i<length;i++)values?result[list[i]]=values[i]:result[list[i][0]]=list[i][1];return result},_.findIndex=createPredicateIndexFinder(1),_.findLastIndex=createPredicateIndexFinder(-1),_.sortedIndex=function(array,obj,iteratee,context){for(var value=(iteratee=cb(iteratee,context,1))(obj),low=0,high=getLength(array);low<high;){var mid=Math.floor((low+high)/2);iteratee(array[mid])<value?low=mid+1:high=mid}return low},_.indexOf=createIndexFinder(1,_.findIndex,_.sortedIndex),_.lastIndexOf=createIndexFinder(-1,_.findLastIndex),_.range=function(start,stop,step){null==stop&&(stop=start||0,start=0),step=step||1;for(var length=Math.max(Math.ceil((stop-start)/step),0),range=Array(length),idx=0;idx<length;idx++,start+=step)range[idx]=start;return range};var executeBound=function(sourceFunc,boundFunc,context,callingContext,args){if(!(callingContext instanceof boundFunc))return sourceFunc.apply(context,args);var self=baseCreate(sourceFunc.prototype),result=sourceFunc.apply(self,args);return _.isObject(result)?result:self};_.bind=function(func,context){if(nativeBind&&func.bind===nativeBind)return nativeBind.apply(func,slice.call(arguments,1));if(!_.isFunction(func))throw new TypeError("Bind must be called on a function");var args=slice.call(arguments,2),bound=function(){return executeBound(func,bound,context,this,args.concat(slice.call(arguments)))};return bound},_.partial=function(func){var boundArgs=slice.call(arguments,1),bound=function(){for(var position=0,length=boundArgs.length,args=Array(length),i=0;i<length;i++)args[i]=boundArgs[i]===_?arguments[position++]:boundArgs[i];for(;position<arguments.length;)args.push(arguments[position++]);return executeBound(func,bound,this,this,args)};return bound},_.bindAll=function(obj){var i,key,length=arguments.length;if(length<=1)throw new Error("bindAll must be passed function names");for(i=1;i<length;i++)obj[key=arguments[i]]=_.bind(obj[key],obj);return obj},_.memoize=function(func,hasher){var memoize=function(key){var cache=memoize.cache,address=""+(hasher?hasher.apply(this,arguments):key);return _.has(cache,address)||(cache[address]=func.apply(this,arguments)),cache[address]};return memoize.cache={},memoize},_.delay=function(func,wait){var args=slice.call(arguments,2);return setTimeout(function(){return func.apply(null,args)},wait)},_.defer=_.partial(_.delay,_,1),_.throttle=function(func,wait,options){var context,args,result,timeout=null,previous=0;options||(options={});var later=function(){previous=!1===options.leading?0:_.now(),timeout=null,result=func.apply(context,args),timeout||(context=args=null)};return function(){var now=_.now();previous||!1!==options.leading||(previous=now);var remaining=wait-(now-previous);return context=this,args=arguments,remaining<=0||wait<remaining?(timeout&&(clearTimeout(timeout),timeout=null),previous=now,result=func.apply(context,args),timeout||(context=args=null)):timeout||!1===options.trailing||(timeout=setTimeout(later,remaining)),result}},_.debounce=function(func,wait,immediate){var timeout,args,context,timestamp,result,later=function(){var last=_.now()-timestamp;last<wait&&0<=last?timeout=setTimeout(later,wait-last):(timeout=null,immediate||(result=func.apply(context,args),timeout||(context=args=null)))};return function(){context=this,args=arguments,timestamp=_.now();var callNow=immediate&&!timeout;return timeout||(timeout=setTimeout(later,wait)),callNow&&(result=func.apply(context,args),context=args=null),result}},_.wrap=function(func,wrapper){return _.partial(wrapper,func)},_.negate=function(predicate){return function(){return!predicate.apply(this,arguments)}},_.compose=function(){var args=arguments,start=args.length-1;return function(){for(var i=start,result=args[start].apply(this,arguments);i--;)result=args[i].call(this,result);return result}},_.after=function(times,func){return function(){if(--times<1)return func.apply(this,arguments)}},_.before=function(times,func){var memo;return function(){return 0<--times&&(memo=func.apply(this,arguments)),times<=1&&(func=null),memo}},_.once=_.partial(_.before,2);var hasEnumBug=!{toString:null}.propertyIsEnumerable("toString"),nonEnumerableProps=["valueOf","isPrototypeOf","toString","propertyIsEnumerable","hasOwnProperty","toLocaleString"];function collectNonEnumProps(obj,keys){var nonEnumIdx=nonEnumerableProps.length,constructor=obj.constructor,proto=_.isFunction(constructor)&&constructor.prototype||ObjProto,prop="constructor";for(_.has(obj,prop)&&!_.contains(keys,prop)&&keys.push(prop);nonEnumIdx--;)(prop=nonEnumerableProps[nonEnumIdx])in obj&&obj[prop]!==proto[prop]&&!_.contains(keys,prop)&&keys.push(prop)}_.keys=function(obj){if(!_.isObject(obj))return[];if(nativeKeys)return nativeKeys(obj);var keys=[];for(var key in obj)_.has(obj,key)&&keys.push(key);return hasEnumBug&&collectNonEnumProps(obj,keys),keys},_.allKeys=function(obj){if(!_.isObject(obj))return[];var keys=[];for(var key in obj)keys.push(key);return hasEnumBug&&collectNonEnumProps(obj,keys),keys},_.values=function(obj){for(var keys=_.keys(obj),length=keys.length,values=Array(length),i=0;i<length;i++)values[i]=obj[keys[i]];return values},_.mapObject=function(obj,iteratee,context){iteratee=cb(iteratee,context);for(var currentKey,keys=_.keys(obj),length=keys.length,results={},index=0;index<length;index++)results[currentKey=keys[index]]=iteratee(obj[currentKey],currentKey,obj);return results},_.pairs=function(obj){for(var keys=_.keys(obj),length=keys.length,pairs=Array(length),i=0;i<length;i++)pairs[i]=[keys[i],obj[keys[i]]];return pairs},_.invert=function(obj){for(var result={},keys=_.keys(obj),i=0,length=keys.length;i<length;i++)result[obj[keys[i]]]=keys[i];return result},_.functions=_.methods=function(obj){var names=[];for(var key in obj)_.isFunction(obj[key])&&names.push(key);return names.sort()},_.extend=createAssigner(_.allKeys),_.extendOwn=_.assign=createAssigner(_.keys),_.findKey=function(obj,predicate,context){predicate=cb(predicate,context);for(var key,keys=_.keys(obj),i=0,length=keys.length;i<length;i++)if(predicate(obj[key=keys[i]],key,obj))return key},_.pick=function(object,oiteratee,context){var iteratee,keys,result={},obj=object;if(null==obj)return result;_.isFunction(oiteratee)?(keys=_.allKeys(obj),iteratee=optimizeCb(oiteratee,context)):(keys=flatten(arguments,!1,!1,1),iteratee=function(value,key,obj){return key in obj},obj=Object(obj));for(var i=0,length=keys.length;i<length;i++){var key=keys[i],value=obj[key];iteratee(value,key,obj)&&(result[key]=value)}return result},_.omit=function(obj,iteratee,context){if(_.isFunction(iteratee))iteratee=_.negate(iteratee);else{var keys=_.map(flatten(arguments,!1,!1,1),String);iteratee=function(value,key){return!_.contains(keys,key)}}return _.pick(obj,iteratee,context)},_.defaults=createAssigner(_.allKeys,!0),_.create=function(prototype,props){var result=baseCreate(prototype);return props&&_.extendOwn(result,props),result},_.clone=function(obj){return _.isObject(obj)?_.isArray(obj)?obj.slice():_.extend({},obj):obj},_.tap=function(obj,interceptor){return interceptor(obj),obj},_.isMatch=function(object,attrs){var keys=_.keys(attrs),length=keys.length;if(null==object)return!length;for(var obj=Object(object),i=0;i<length;i++){var key=keys[i];if(attrs[key]!==obj[key]||!(key in obj))return!1}return!0};var eq=function(a,b,aStack,bStack){if(a===b)return 0!==a||1/a==1/b;if(null==a||null==b)return a===b;a instanceof _&&(a=a._wrapped),b instanceof _&&(b=b._wrapped);var className=toString.call(a);if(className!==toString.call(b))return!1;switch(className){case"[object RegExp]":case"[object String]":return""+a==""+b;case"[object Number]":return+a!=+a?+b!=+b:0==+a?1/+a==1/b:+a==+b;case"[object Date]":case"[object Boolean]":return+a==+b}var areArrays="[object Array]"===className;if(!areArrays){if("object"!=typeof a||"object"!=typeof b)return!1;var aCtor=a.constructor,bCtor=b.constructor;if(aCtor!==bCtor&&!(_.isFunction(aCtor)&&aCtor instanceof aCtor&&_.isFunction(bCtor)&&bCtor instanceof bCtor)&&"constructor"in a&&"constructor"in b)return!1}bStack=bStack||[];for(var length=(aStack=aStack||[]).length;length--;)if(aStack[length]===a)return bStack[length]===b;if(aStack.push(a),bStack.push(b),areArrays){if((length=a.length)!==b.length)return!1;for(;length--;)if(!eq(a[length],b[length],aStack,bStack))return!1}else{var key,keys=_.keys(a);if(length=keys.length,_.keys(b).length!==length)return!1;for(;length--;)if(key=keys[length],!_.has(b,key)||!eq(a[key],b[key],aStack,bStack))return!1}return aStack.pop(),bStack.pop(),!0};_.isEqual=function(a,b){return eq(a,b)},_.isEmpty=function(obj){return null==obj||(isArrayLike(obj)&&(_.isArray(obj)||_.isString(obj)||_.isArguments(obj))?0===obj.length:0===_.keys(obj).length)},_.isElement=function(obj){return!(!obj||1!==obj.nodeType)},_.isArray=nativeIsArray||function(obj){return"[object Array]"===toString.call(obj)},_.isObject=function(obj){var type=typeof obj;return"function"===type||"object"===type&&!!obj},_.each(["Arguments","Function","String","Number","Date","RegExp","Error"],function(name){_["is"+name]=function(obj){return toString.call(obj)==="[object "+name+"]"}}),_.isArguments(arguments)||(_.isArguments=function(obj){return _.has(obj,"callee")}),"function"!=typeof/./&&"object"!=typeof Int8Array&&(_.isFunction=function(obj){return"function"==typeof obj||!1}),_.isFinite=function(obj){return isFinite(obj)&&!isNaN(parseFloat(obj))},_.isNaN=function(obj){return _.isNumber(obj)&&obj!==+obj},_.isBoolean=function(obj){return!0===obj||!1===obj||"[object Boolean]"===toString.call(obj)},_.isNull=function(obj){return null===obj},_.isUndefined=function(obj){return void 0===obj},_.has=function(obj,key){return null!=obj&&hasOwnProperty.call(obj,key)},_.noConflict=function(){return root._=previousUnderscore,this},_.identity=function(value){return value},_.constant=function(value){return function(){return value}},_.noop=function(){},_.property=property,_.propertyOf=function(obj){return null==obj?function(){}:function(key){return obj[key]}},_.matcher=_.matches=function(attrs){return attrs=_.extendOwn({},attrs),function(obj){return _.isMatch(obj,attrs)}},_.times=function(n,iteratee,context){var accum=Array(Math.max(0,n));iteratee=optimizeCb(iteratee,context,1);for(var i=0;i<n;i++)accum[i]=iteratee(i);return accum},_.random=function(min,max){return null==max&&(max=min,min=0),min+Math.floor(Math.random()*(max-min+1))},_.now=Date.now||function(){return(new Date).getTime()};var escapeMap={"&":"&","<":"<",">":">",'"':""","'":"'","`":"`"},unescapeMap=_.invert(escapeMap),createEscaper=function(map){var escaper=function(match){return map[match]},source="(?:"+_.keys(map).join("|")+")",testRegexp=RegExp(source),replaceRegexp=RegExp(source,"g");return function(string){return string=null==string?"":""+string,testRegexp.test(string)?string.replace(replaceRegexp,escaper):string}};_.escape=createEscaper(escapeMap),_.unescape=createEscaper(unescapeMap),_.result=function(object,property,fallback){var value=null==object?void 0:object[property];return void 0===value&&(value=fallback),_.isFunction(value)?value.call(object):value};var idCounter=0;_.uniqueId=function(prefix){var id=++idCounter+"";return prefix?prefix+id:id},_.templateSettings={evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,escape:/<%-([\s\S]+?)%>/g};var noMatch=/(.)^/,escapes={"'":"'","\\":"\\","\r":"r","\n":"n","\u2028":"u2028","\u2029":"u2029"},escaper=/\\|'|\r|\n|\u2028|\u2029/g,escapeChar=function(match){return"\\"+escapes[match]};_.template=function(text,settings,oldSettings){!settings&&oldSettings&&(settings=oldSettings),settings=_.defaults({},settings,_.templateSettings);var matcher=RegExp([(settings.escape||noMatch).source,(settings.interpolate||noMatch).source,(settings.evaluate||noMatch).source].join("|")+"|$","g"),index=0,source="__p+='";text.replace(matcher,function(match,escape,interpolate,evaluate,offset){return source+=text.slice(index,offset).replace(escaper,escapeChar),index=offset+match.length,escape?source+="'+\n((__t=("+escape+"))==null?'':_.escape(__t))+\n'":interpolate?source+="'+\n((__t=("+interpolate+"))==null?'':__t)+\n'":evaluate&&(source+="';\n"+evaluate+"\n__p+='"),match}),source+="';\n",settings.variable||(source="with(obj||{}){\n"+source+"}\n"),source="var __t,__p='',__j=Array.prototype.join,print=function(){__p+=__j.call(arguments,'');};\n"+source+"return __p;\n";try{var render=new Function(settings.variable||"obj","_",source)}catch(e){throw e.source=source,e}var template=function(data){return render.call(this,data,_)},argument=settings.variable||"obj";return template.source="function("+argument+"){\n"+source+"}",template},_.chain=function(obj){var instance=_(obj);return instance._chain=!0,instance};var result=function(instance,obj){return instance._chain?_(obj).chain():obj};_.mixin=function(obj){_.each(_.functions(obj),function(name){var func=_[name]=obj[name];_.prototype[name]=function(){var args=[this._wrapped];return push.apply(args,arguments),result(this,func.apply(_,args))}})},_.mixin(_),_.each(["pop","push","reverse","shift","sort","splice","unshift"],function(name){var method=ArrayProto[name];_.prototype[name]=function(){var obj=this._wrapped;return method.apply(obj,arguments),"shift"!==name&&"splice"!==name||0!==obj.length||delete obj[0],result(this,obj)}}),_.each(["concat","join","slice"],function(name){var method=ArrayProto[name];_.prototype[name]=function(){return result(this,method.apply(this._wrapped,arguments))}}),_.prototype.value=function(){return this._wrapped},_.prototype.valueOf=_.prototype.toJSON=_.prototype.value,_.prototype.toString=function(){return""+this._wrapped},"function"==typeof define&&define.amd&&define("underscore",[],function(){return _})}).call(this)},{}]},{},[17])(17)});