-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjslinq.min.js
1 lines (1 loc) · 4.13 KB
/
jslinq.min.js
1
(function(a,i,g,j){var c,d,e,f,b,h;a.fn=a.prototype;if(a.each===b)a.fn.each=function(d,b){b=b||g;var c=this,e=c.length,a=0;for(a;a<e;a++)d.call(b,c[a],a)};if(a.where===b)a.fn.where=a.fn.all=function(a,d){var e=this,f=[],i;d=d||g;if(a===b)return e;i=c(a);if(i=="[String]"){var j=h(a);e.each(function(a){j.call(d,a)===true&&f.push(a)})}else e.each(function(b){a.call(d,b)===true&&f.push(b)});return f};if(a.select===b)a.fn.select=function(d,a){var c=this,e=[];a=a||g;if(d===b)return c;c.each(function(b){e.push(d.call(a,b))});return e};if(a.take===b)a.fn.take=function(a){var d=this,e=d.length;if(a===b)return d;if(c(a)!=="[Number]")throw"count must be a number";return a>e?d:d.slice(0,a)};if(a.skip===b)a.fn.skip=function(a){var d=this,e=d.length;if(a===b)return d;if(c(a)!=="[Number]")throw"count must be a number";return a>e?d.slice(a-e):d.slice(a)};if(a.first===b||a.single===b)a.fn.first=a.fn.single=function(a,c){var b=this;return!a?b[0]:b.where(a,c)[0]};if(a.count===b)a.fn.count=function(a,d){var c=this;return a===b?this.length:c.where(a,d).length};if(a.any===b)a.fn.any=function(a,d){var c=this;return a===b?this.length>0:c.length<=0?false:c.where(a,d).length>0};if(a.toHash===b||a.toDictionary===b)a.fn.toHash=a.fn.toDictionary=function(c){var a=this,d={};if(c&&a[0][c]===b)throw"key is only valid for arrays of Object";a.each(function(e,b){if(!c)d[b]=a[b];else d[a[b][c]]=a[b]});return d};if(a.orderBy===b||a.order===b)a.fn.orderBy=a.fn.order=function(g){var a=this,h,i;h=g===b?c(a[0]):c(a[0][g]);if(g!==b&&h!=="[Object]"&&a[0][g]===b)throw"cannot use prop with an Array of primitive types (String, Date, Number, Bool)";return g===b?h==="[String]"?a.sort(e):a.sort(d):h==="[String]"?a.sort(f(e,g)):a.sort(f(d,g))};if(a.sum===b)a.fn.sum=function(d){var a=this,e,f=0;e=d===b?c(a[0]):c(a[0][d]);if(e!=="[Number]")throw"array values must be a Number";a.each(function(g,c){var e=d===b?a[c]:a[c][d];f+=e});return f};if(a.average===b||a.mean===b)a.fn.average=a.fn.mean=function(d){var a=this,f=a.length,e;e=d===b?c(a[0]):c(a[0][d]);if(e!=="[Number]")throw"array values must be a Number";return a.sum(d)/f};if(a.max===b)a.fn.max=function(d){var a=this,e,f;e=d===b?c(a[0]):c(a[0][d]);if(e!=="[Number]")throw"array values must be a Number";f=d===b?a:a.select(function(a){return a[d]});return Math.max.apply(Math,f)};if(a.min===b)a.fn.min=function(d){var a=this,e,f;e=d===b?c(a[0]):c(a[0][d]);if(e!=="[Number]")throw"array values must be a Number";f=d===b?a:a.select(function(a){return a[d]});return Math.min.apply(Math,f)};if(a.unique===b||a.distinct===b)a.fn.unique=a.fn.distinct=function(){var b=this,d=[],e=b.length,a=0;for(a;a<e;a++){for(var c=a+1;c<e;c++)if(b[a]===b[c])c=++a;d.push(b[a])}return d};if(a.union===b)a.fn.union=function(){var d=this,b=[].concat(d),c=arguments.length,a=0;if(!c)throw"arguments must be Arrays";for(a;a<c;a++)b=b.concat(arguments[a]);return b.unique()};if(a.intersect===b)a.fn.intersect=function(){var a=this,d,c,g=0,h=0,f=arguments.length;if(!f)throw"arguments must be Arrays";while(g<arguments.length){f=a.length;d=[];c=arguments[g];h=c.length;for(var b=0;b<f;b++)for(var e=0;e<h;e++)a[b]===c[e]&&d.push(a[b]);a=d;g++}return a.unique()};if(a.shuffle===b)a.fn.shuffle=function(){var c=this,a=[],b;c.each(function(d,c){b=Math.floor(Math.random()*(c+1));a[c]=a[b];a[b]=d});return a};if(!j.params)j.prototype.params=function(d){var a=this,g=i.prototype.toString.call(d).replace("object ",""),b=0,f=arguments.length,c;if(g==="[Object]"&&f===1)for(var e in d){c=new RegExp("\\{"+e+"\\}","g");a=a.replace(c,d[e])}else for(;b<f;b++){c=new RegExp("\\{"+b+"\\}","gi");a=a.replace(c,arguments[b])}return a};f=function(a,b){return function(c,d){return a(c,d,b)}};c=function(a){return i.prototype.toString.call(a).replace("object ","")};d=function(c,d,a){return a===b?c-d:c[a]-d[a]};e=function(e,f,a){var c,d;c=a===b?e:e[a];d=a===b?f:f[a];return c.localeCompare(d)};h=function(d){var a=d.match(/[\(]?(\w)[\)]?\s*=>\s*(.*)/),c=[],b="";a&&a.length>0&&a.shift();if(a&&a.length>0)b=a.pop();if(a&&a.length>0)c=a.pop().replace(/^\s*|\s(?=\s)|\s*$|,/g,"").split(" ");a=(!/\s*return\s+/.test(b)?"return ":"")+b;c.push(a);try{return Function.apply({},c)}catch(e){return null}}})(this.Array,this.Object,this,this.String)