diff --git a/bower.json b/bower.json index c171f27..e0460e5 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "mini-linq-js", - "version": "1.3.1", + "version": "1.3.2", "description": "LINQ for JavaScript library, which allows to work with arrays in a more easy way and focus on business logic.", "main": "dist/mini-linq.full.min.js", "authors": [ diff --git a/dist/mini-linq.full.min.js b/dist/mini-linq.full.min.js index 4ca9df9..be80b95 100644 --- a/dist/mini-linq.full.min.js +++ b/dist/mini-linq.full.min.js @@ -22,4 +22,4 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -!function(){var stringTrim=function(a){return"string"!=typeof a||null===a?a:String.prototype.trim?a.trim():a.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"")},expressionCache={};LINQ={utils:{parseExpression:function(a){if("function"==typeof a)return a;if(null==a||"string"!=typeof a||a.indexOf("=>")<0)throw new SyntaxError('Expression "'+a+'" is invalid');if("function"==typeof expressionCache[a])return expressionCache[a];var b,c=a.split("=>"),d=stringTrim(c[0]).replace(/[\(\)\s]/gi,""),e=stringTrim(c[1]);try{e.indexOf("return")<0&&(e="return ("+e+")"),b=new Function(d,e)}catch(f){b=new Function(d,e)}if("function"!=typeof b)throw new SyntaxError('Expression "'+a+'" is invalid');return expressionCache[a]=b,b},getType:function(a){var b=typeof a;if("object"!==b)return b;if(null===a)return"null";var c=a.constructor,d="function"==typeof c&&c.name;return"string"==typeof d&&d.length>0?d:"object"},getDefaultValue:function(type){if("string"!=typeof type)throw new TypeError("Type must be a string.");switch(type){case"boolean":return!1;case"function":return function(){};case"null":return null;case"number":return 0;case"object":return{};case"string":return"";case"symbol":return Symbol();case"undefined":return}try{var ctor="function"==typeof this[type]?this[type]:eval(type);return new ctor}catch(e){return{}}},isArray:function(a){return Array.isArray?Array.isArray(a):"[object Array]"===Object.prototype.toString.call(a)}},methods:{any:function(a){if("string"==typeof a)a=LINQ.utils.parseExpression(a);else if("function"!=typeof a)return this.length>0;if("function"==typeof Array.prototype.some)return this.some(a);for(var b=0,c=this.length;c>b;b++)if(a(this[b],b,this))return!0;return!1},all:function(a){if("string"==typeof a)a=LINQ.utils.parseExpression(a);else if("function"!=typeof a)throw new Error("Predicate is required");if("function"==typeof Array.prototype.every)return this.every(a);var b=function(){return!a.apply(this,arguments)};return!LINQ.methods.any.apply(this,[b])},where:function(a){if("string"==typeof a)a=LINQ.utils.parseExpression(a);else if("function"!=typeof a)throw new Error("Predicate is required");if("function"==typeof Array.prototype.filter)return this.filter(a);for(var b=[],c=0,d=this.length;d>c;c++)a(this[c],c,this)&&b.push(this[c]);return b},select:function(a){if("string"==typeof a)a=LINQ.utils.parseExpression(a);else if("function"!=typeof a)throw new Error("Selector is required");if("function"==typeof Array.prototype.map)return this.map(a);for(var b=[],c=0,d=this.length;d>c;c++)b.push(a(this[c],c,this));return b},selectMany:function(a){if("string"==typeof a)a=LINQ.utils.parseExpression(a);else if("function"!=typeof a)throw new Error("Selector is required");for(var b=[],c=0,d=this.length;d>c;c++){var e=a(this[c],c,this);LINQ.utils.isArray(e)&&b.push(e)}return Array.prototype.concat.apply([],b)},count:function(a){if("string"==typeof a)a=LINQ.utils.parseExpression(a);else if("function"!=typeof a)return this.length;if("function"==typeof Array.prototype.filter)return this.filter(a).length;for(var b=0,c=0,d=this.length;d>c;c++)a(this[c],c,this)&&b++;return b},orderBy:function(a,b){return"string"==typeof a?a=LINQ.utils.parseExpression(a):"function"!=typeof a&&(a=function(a){return a}),"string"==typeof b?b=LINQ.utils.parseExpression(b):"function"!=typeof b&&(b=function(a,b){return b>a?-1:a>b?1:0}),this.slice(0).sort(function(c,d){var e=a(c),f=a(d);return b(e,f)})},orderByDescending:function(a,b){"string"==typeof b?b=LINQ.utils.parseExpression(b):"function"!=typeof b&&(b=function(a,b){return b>a?-1:a>b?1:0});var c=function(){return-1*b.apply(this,arguments)};return LINQ.methods.orderBy.apply(this,[a,c])},groupBy:function(a,b){if("string"==typeof a)a=LINQ.utils.parseExpression(a);else if("function"!=typeof a)throw new Error("Key selector is required");"string"==typeof b?b=LINQ.utils.parseExpression(b):"function"!=typeof b&&(b=function(a,b){return{group:a,values:b}});for(var c={},d=0,e=this.length;e>d;d++){var f=a(this[d],d,this);c[f]||(c[f]=[]),c[f].push(this[d])}var g=[];for(var h in c)c.hasOwnProperty(h)&&g.push(b(h,c[h]));return g},distinct:function(a,b){"string"==typeof a?a=LINQ.utils.parseExpression(a):"function"!=typeof a&&(a=function(a){return a}),"string"==typeof b?b=LINQ.utils.parseExpression(b):"function"!=typeof b&&(b=function(a,b){return a===b});for(var c=[],d={},e=0,f=this.length;f>e;e++){var g=a(this[e],e,this);if(d[g]){for(var h=!0,i=0,j=d[g].length;j>i;i++)if(b(d[g][i],g)){h=!1;break}h&&(c.push(this[e]),d[g].push(g))}else d[g]=[g],c.push(this[e])}return c},firstOrDefault:function(a){if("string"==typeof a?a=LINQ.utils.parseExpression(a):"function"!=typeof a&&(a=function(){return!0}),"function"==typeof Array.prototype.find)return this.find(a)||null;for(var b=0,c=this.length;c>b;b++)if(a(this[b],b,this))return this[b];return null},lastOrDefault:function(a){"string"==typeof a?a=LINQ.utils.parseExpression(a):"function"!=typeof a&&(a=function(){return!0});for(var b=this.length-1;b>=0;b--)if(a(this[b],b,this))return this[b];return null},joinWith:function(a,b,c,d,e){if("string"==typeof b)b=LINQ.utils.parseExpression(b);else if("function"!=typeof b)throw new Error("Inner key selector is required");if("string"==typeof c)c=LINQ.utils.parseExpression(c);else if("function"!=typeof c)throw new Error("Outer key selector is required");if("string"==typeof d)d=LINQ.utils.parseExpression(d);else if("function"!=typeof d)throw new Error("Results selector is required");"string"==typeof e?e=LINQ.utils.parseExpression(e):"function"!=typeof e&&(e=function(a,b){return a===b});for(var f=[],g=0,h=this.length;h>g;g++)for(var i=c(this[g],g,this),j=0,k=a.length;k>j;j++){var l=b(a[j],j,a);e(l,i)&&f.push(d(a[j],this[g]))}return f},groupJoinWith:function(a,b,c,d,e){if("string"==typeof b)b=LINQ.utils.parseExpression(b);else if("function"!=typeof b)throw new Error("Inner key selector is required");if("string"==typeof c)c=LINQ.utils.parseExpression(c);else if("function"!=typeof c)throw new Error("Outer key selector is required");if("string"==typeof d)d=LINQ.utils.parseExpression(d);else if("function"!=typeof d)throw new Error("Results selector is required");"string"==typeof e?e=LINQ.utils.parseExpression(e):"function"!=typeof e&&(e=function(a,b){return a===b});for(var f=[],g=0,h=this.length;h>g;g++){var i=c(this[g],g,this),j=LINQ.methods.where.apply(a,[function(c,d){return innerKey=b(a[d],d,a),e(innerKey,i)}]);f.push(d(j,this[g]))}return f},contains:function(a,b){var c;if("string"==typeof b){var d=LINQ.utils.parseExpression(b);c=function(b){return d(b,a)}}else c="function"!=typeof b?function(b){return b===a}:function(c){return b(c,a)};return LINQ.methods.any.apply(this,[c])},aggregate:function(a,b){if("string"==typeof a)a=LINQ.utils.parseExpression(a);else if("function"!=typeof a)throw new Error("Aggregator function is required");if(this.length<=0)return b;var c="undefined"==typeof b?LINQ.utils.getDefaultValue(LINQ.utils.getType(this[0])):b;if("function"==typeof Array.prototype.reduce)return this.reduce(a,c);for(var d=0,e=this.length;e>d;d++)c=a(c,this[d],d,this);return c},sum:function(a,b){return"string"==typeof a?a=LINQ.utils.parseExpression(a):"function"!=typeof a&&(a=function(a){return a}),b="undefined"==typeof b?LINQ.utils.getDefaultValue(LINQ.utils.getType(a(this[0],0,this))):b,LINQ.methods.aggregate.apply(this,[function(b,c,d,e){return b+a(c,d,e)},b])},min:function(a){return"string"==typeof a?a=LINQ.utils.parseExpression(a):"function"!=typeof a&&(a=function(a){return a}),this.length<=0?void 0:LINQ.methods.aggregate.apply(this,[function(b,c,d,e){var f=a(c,d,e);return b>f?f:b},a(this[0],0,this)])},max:function(a){return"string"==typeof a?a=LINQ.utils.parseExpression(a):"function"!=typeof a&&(a=function(a){return a}),this.length<=0?void 0:LINQ.methods.aggregate.apply(this,[function(b,c,d,e){var f=a(c,d,e);return f>b?f:b},a(this[0],0,this)])},skip:function(a){if("number"!=typeof a||0>a)throw new TypeError("Count is required and should be a positive number");return this.slice(a,this.length)},take:function(a){if("number"!=typeof a||0>a)throw new TypeError("Count is required and should be a positive number");return this.slice(0,a)},ofType:function(a){if("string"!=typeof a)throw new TypeError("Type is required.");return LINQ.methods.where.apply(this,[function(b){return typeof b===a}])},union:function(a,b){return[].concat(this,a).distinct(function(a){return a},b)},except:function(a,b){"string"==typeof b?b=LINQ.utils.parseExpression(b):"function"!=typeof b&&(b=function(a,b){return a===b});for(var c=[],d=0,e=this.length;e>d;d++){for(var f=!0,g=0,h=a.length;h>g;g++)if(b(this[d],a[g])){f=!1;break}f&&c.push(this[d])}return c}}},LINQ.methods.firstOrDefault.finalize=!0,LINQ.methods.lastOrDefault.finalize=!0,LINQ.methods.count.finalize=!0,LINQ.methods.any.finalize=!0,LINQ.methods.contains.finalize=!0,LINQ.methods.all.finalize=!0,LINQ.methods.aggregate.finalize=!0,LINQ.methods.sum.finalize=!0,LINQ.methods.min.finalize=!0,LINQ.methods.max.finalize=!0;for(var key in LINQ.methods)LINQ.methods.hasOwnProperty(key)&&(Array.prototype[key]=LINQ.methods[key])}(),function(a){var b=[function(b,c){if(b.name===c.name&&"where"===c.name){var d=a.utils.parseExpression(b.args[0]),e=a.utils.parseExpression(c.args[0]);return function(c,d){return{name:b.name,args:[function(){return c.apply(this,arguments)&&d.apply(this,arguments)}],fn:a.methods[b.name]}}(d,e)}return!1},function(b,c){if(b.name===c.name&&"select"===c.name){var d=a.utils.parseExpression(b.args[0]),e=a.utils.parseExpression(c.args[0]);return function(c,d){return{name:b.name,args:[function(){return d.apply(this,[c.apply(this,arguments)])}],fn:a.methods[b.name]}}(d,e)}return!1},function(a,b){var c=["orderBy","orderByDescending"];return c.contains(a.name)&&c.contains(b.name)?b:!1},function(a,b){return"skip"==a.name&&"take"==b.name?function(a,b){return{name:"skiptake",args:[a,b],fn:function(a,b){return this.slice(a,a+b)}}}(a.args[0],b.args[0]):!1}],c=function(c){var d=this,e=c;d._modificatorQueue=[];var f=function(){for(var a=d._modificatorQueue.length,b=0;a>b;b++){var c=d._modificatorQueue[b];e=c.fn.apply(e,c.args)}return d._modificatorQueue.splice(0,a),a},g=function(){for(var a=0;ag;g++){var i=b[g],j=i(c,e);j&&(f=!0,d._modificatorQueue.splice(a+1,1),d._modificatorQueue[a]=j)}f||a++}};d.optimize=function(){return g(),d},d.toArray=function(){return e.length>100&&d._modificatorQueue.length>2&&d.optimize(),f(),a.utils.isArray(e)?e.slice(0):e}};Array.prototype.toLazy=function(){return new c(this)};for(var d in a.methods)a.methods.hasOwnProperty(d)&&(c.prototype[d]=function(b){return function(){var c=a.methods[b];return this._modificatorQueue.push({fn:a.methods[b],args:arguments,name:b}),c.finalize?this.toArray():this}}(d))}(LINQ),function(a){if("undefined"!=typeof ko&&ko.observableArray&&ko.observableArray.fn){Array.prototype.toObservableArray=function(){return ko.observableArray(this)},ko.observableArray.fn.toArray=function(){return this()};for(var b in a.methods)a.methods.hasOwnProperty(b)&&(ko.observableArray.fn[b]=function(b){return function(){return a.methods[b].apply(this(),arguments)}}(b))}}(LINQ); \ No newline at end of file +!function(){var stringTrim=function(a){return"string"!=typeof a||null===a?a:String.prototype.trim?a.trim():a.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"")},expressionCache={},LINQ={utils:{parseExpression:function(a){if("function"==typeof a)return a;if(null==a||"string"!=typeof a||a.indexOf("=>")<0)throw new SyntaxError('Expression "'+a+'" is invalid');if("function"==typeof expressionCache[a])return expressionCache[a];var b,c=a.split("=>"),d=stringTrim(c[0]).replace(/[\(\)\s]/gi,""),e=stringTrim(c[1]);try{e.indexOf("return")<0&&(e="return ("+e+")"),b=new Function(d,e)}catch(f){b=new Function(d,e)}if("function"!=typeof b)throw new SyntaxError('Expression "'+a+'" is invalid');return expressionCache[a]=b,b},getType:function(a){var b=typeof a;if("object"!==b)return b;if(null===a)return"null";var c=a.constructor,d="function"==typeof c&&c.name;return"string"==typeof d&&d.length>0?d:"object"},getDefaultValue:function(type){if("string"!=typeof type)throw new TypeError("Type must be a string.");switch(type){case"boolean":return!1;case"function":return function(){};case"null":return null;case"number":return 0;case"object":return{};case"string":return"";case"symbol":return Symbol();case"undefined":return}try{var ctor="function"==typeof this[type]?this[type]:eval(type);return new ctor}catch(e){return{}}},isArray:function(a){return Array.isArray?Array.isArray(a):"[object Array]"===Object.prototype.toString.call(a)}},methods:{any:function(a){if("string"==typeof a)a=LINQ.utils.parseExpression(a);else if("function"!=typeof a)return this.length>0;if("function"==typeof Array.prototype.some)return this.some(a);for(var b=0,c=this.length;bb?1:0}),this.slice(0).sort(function(c,d){var e=a(c),f=a(d);return b(e,f)})},orderByDescending:function(a,b){"string"==typeof b?b=LINQ.utils.parseExpression(b):"function"!=typeof b&&(b=function(a,b){return ab?1:0});var c=function(){return b.apply(this,arguments)*-1};return LINQ.methods.orderBy.apply(this,[a,c])},groupBy:function(a,b){if("string"==typeof a)a=LINQ.utils.parseExpression(a);else if("function"!=typeof a)throw new Error("Key selector is required");"string"==typeof b?b=LINQ.utils.parseExpression(b):"function"!=typeof b&&(b=function(a,b){return{group:a,values:b}});for(var c={},d=0,e=this.length;d=0;b--)if(a(this[b],b,this))return this[b];return null},joinWith:function(a,b,c,d,e){if("string"==typeof b)b=LINQ.utils.parseExpression(b);else if("function"!=typeof b)throw new Error("Inner key selector is required");if("string"==typeof c)c=LINQ.utils.parseExpression(c);else if("function"!=typeof c)throw new Error("Outer key selector is required");if("string"==typeof d)d=LINQ.utils.parseExpression(d);else if("function"!=typeof d)throw new Error("Results selector is required");"string"==typeof e?e=LINQ.utils.parseExpression(e):"function"!=typeof e&&(e=function(a,b){return a===b});for(var f=[],g=0,h=this.length;gf?f:b},a(this[0],0,this)])},max:function(a){if("string"==typeof a?a=LINQ.utils.parseExpression(a):"function"!=typeof a&&(a=function(a){return a}),!(this.length<=0))return LINQ.methods.aggregate.apply(this,[function(b,c,d,e){var f=a(c,d,e);return b100&&d._modificatorQueue.length>2&&d.optimize(),f(),a.utils.isArray(e)?e.slice(0):e}};Array.prototype.toLazy=function(){return new c(this)};for(var d in a.methods)a.methods.hasOwnProperty(d)&&(c.prototype[d]=function(b){return function(){var c=a.methods[b];return this._modificatorQueue.push({fn:a.methods[b],args:arguments,name:b}),c.finalize?this.toArray():this}}(d))}(LINQ),function(a){if("undefined"!=typeof ko&&ko.observableArray&&ko.observableArray.fn){Array.prototype.toObservableArray=function(){return ko.observableArray(this)},ko.observableArray.fn.toArray=function(){return this()};for(var b in a.methods)a.methods.hasOwnProperty(b)&&(ko.observableArray.fn[b]=function(b){return function(){return a.methods[b].apply(this(),arguments)}}(b))}}(LINQ)}(); \ No newline at end of file diff --git a/dist/mini-linq.min.js b/dist/mini-linq.min.js index e0dfe7c..ac21b05 100644 --- a/dist/mini-linq.min.js +++ b/dist/mini-linq.min.js @@ -22,4 +22,4 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -!function(){var stringTrim=function(a){return"string"!=typeof a||null===a?a:String.prototype.trim?a.trim():a.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"")},expressionCache={};LINQ={utils:{parseExpression:function(a){if("function"==typeof a)return a;if(null==a||"string"!=typeof a||a.indexOf("=>")<0)throw new SyntaxError('Expression "'+a+'" is invalid');if("function"==typeof expressionCache[a])return expressionCache[a];var b,c=a.split("=>"),d=stringTrim(c[0]).replace(/[\(\)\s]/gi,""),e=stringTrim(c[1]);try{e.indexOf("return")<0&&(e="return ("+e+")"),b=new Function(d,e)}catch(f){b=new Function(d,e)}if("function"!=typeof b)throw new SyntaxError('Expression "'+a+'" is invalid');return expressionCache[a]=b,b},getType:function(a){var b=typeof a;if("object"!==b)return b;if(null===a)return"null";var c=a.constructor,d="function"==typeof c&&c.name;return"string"==typeof d&&d.length>0?d:"object"},getDefaultValue:function(type){if("string"!=typeof type)throw new TypeError("Type must be a string.");switch(type){case"boolean":return!1;case"function":return function(){};case"null":return null;case"number":return 0;case"object":return{};case"string":return"";case"symbol":return Symbol();case"undefined":return}try{var ctor="function"==typeof this[type]?this[type]:eval(type);return new ctor}catch(e){return{}}},isArray:function(a){return Array.isArray?Array.isArray(a):"[object Array]"===Object.prototype.toString.call(a)}},methods:{any:function(a){if("string"==typeof a)a=LINQ.utils.parseExpression(a);else if("function"!=typeof a)return this.length>0;if("function"==typeof Array.prototype.some)return this.some(a);for(var b=0,c=this.length;c>b;b++)if(a(this[b],b,this))return!0;return!1},all:function(a){if("string"==typeof a)a=LINQ.utils.parseExpression(a);else if("function"!=typeof a)throw new Error("Predicate is required");if("function"==typeof Array.prototype.every)return this.every(a);var b=function(){return!a.apply(this,arguments)};return!LINQ.methods.any.apply(this,[b])},where:function(a){if("string"==typeof a)a=LINQ.utils.parseExpression(a);else if("function"!=typeof a)throw new Error("Predicate is required");if("function"==typeof Array.prototype.filter)return this.filter(a);for(var b=[],c=0,d=this.length;d>c;c++)a(this[c],c,this)&&b.push(this[c]);return b},select:function(a){if("string"==typeof a)a=LINQ.utils.parseExpression(a);else if("function"!=typeof a)throw new Error("Selector is required");if("function"==typeof Array.prototype.map)return this.map(a);for(var b=[],c=0,d=this.length;d>c;c++)b.push(a(this[c],c,this));return b},selectMany:function(a){if("string"==typeof a)a=LINQ.utils.parseExpression(a);else if("function"!=typeof a)throw new Error("Selector is required");for(var b=[],c=0,d=this.length;d>c;c++){var e=a(this[c],c,this);LINQ.utils.isArray(e)&&b.push(e)}return Array.prototype.concat.apply([],b)},count:function(a){if("string"==typeof a)a=LINQ.utils.parseExpression(a);else if("function"!=typeof a)return this.length;if("function"==typeof Array.prototype.filter)return this.filter(a).length;for(var b=0,c=0,d=this.length;d>c;c++)a(this[c],c,this)&&b++;return b},orderBy:function(a,b){return"string"==typeof a?a=LINQ.utils.parseExpression(a):"function"!=typeof a&&(a=function(a){return a}),"string"==typeof b?b=LINQ.utils.parseExpression(b):"function"!=typeof b&&(b=function(a,b){return b>a?-1:a>b?1:0}),this.slice(0).sort(function(c,d){var e=a(c),f=a(d);return b(e,f)})},orderByDescending:function(a,b){"string"==typeof b?b=LINQ.utils.parseExpression(b):"function"!=typeof b&&(b=function(a,b){return b>a?-1:a>b?1:0});var c=function(){return-1*b.apply(this,arguments)};return LINQ.methods.orderBy.apply(this,[a,c])},groupBy:function(a,b){if("string"==typeof a)a=LINQ.utils.parseExpression(a);else if("function"!=typeof a)throw new Error("Key selector is required");"string"==typeof b?b=LINQ.utils.parseExpression(b):"function"!=typeof b&&(b=function(a,b){return{group:a,values:b}});for(var c={},d=0,e=this.length;e>d;d++){var f=a(this[d],d,this);c[f]||(c[f]=[]),c[f].push(this[d])}var g=[];for(var h in c)c.hasOwnProperty(h)&&g.push(b(h,c[h]));return g},distinct:function(a,b){"string"==typeof a?a=LINQ.utils.parseExpression(a):"function"!=typeof a&&(a=function(a){return a}),"string"==typeof b?b=LINQ.utils.parseExpression(b):"function"!=typeof b&&(b=function(a,b){return a===b});for(var c=[],d={},e=0,f=this.length;f>e;e++){var g=a(this[e],e,this);if(d[g]){for(var h=!0,i=0,j=d[g].length;j>i;i++)if(b(d[g][i],g)){h=!1;break}h&&(c.push(this[e]),d[g].push(g))}else d[g]=[g],c.push(this[e])}return c},firstOrDefault:function(a){if("string"==typeof a?a=LINQ.utils.parseExpression(a):"function"!=typeof a&&(a=function(){return!0}),"function"==typeof Array.prototype.find)return this.find(a)||null;for(var b=0,c=this.length;c>b;b++)if(a(this[b],b,this))return this[b];return null},lastOrDefault:function(a){"string"==typeof a?a=LINQ.utils.parseExpression(a):"function"!=typeof a&&(a=function(){return!0});for(var b=this.length-1;b>=0;b--)if(a(this[b],b,this))return this[b];return null},joinWith:function(a,b,c,d,e){if("string"==typeof b)b=LINQ.utils.parseExpression(b);else if("function"!=typeof b)throw new Error("Inner key selector is required");if("string"==typeof c)c=LINQ.utils.parseExpression(c);else if("function"!=typeof c)throw new Error("Outer key selector is required");if("string"==typeof d)d=LINQ.utils.parseExpression(d);else if("function"!=typeof d)throw new Error("Results selector is required");"string"==typeof e?e=LINQ.utils.parseExpression(e):"function"!=typeof e&&(e=function(a,b){return a===b});for(var f=[],g=0,h=this.length;h>g;g++)for(var i=c(this[g],g,this),j=0,k=a.length;k>j;j++){var l=b(a[j],j,a);e(l,i)&&f.push(d(a[j],this[g]))}return f},groupJoinWith:function(a,b,c,d,e){if("string"==typeof b)b=LINQ.utils.parseExpression(b);else if("function"!=typeof b)throw new Error("Inner key selector is required");if("string"==typeof c)c=LINQ.utils.parseExpression(c);else if("function"!=typeof c)throw new Error("Outer key selector is required");if("string"==typeof d)d=LINQ.utils.parseExpression(d);else if("function"!=typeof d)throw new Error("Results selector is required");"string"==typeof e?e=LINQ.utils.parseExpression(e):"function"!=typeof e&&(e=function(a,b){return a===b});for(var f=[],g=0,h=this.length;h>g;g++){var i=c(this[g],g,this),j=LINQ.methods.where.apply(a,[function(c,d){return innerKey=b(a[d],d,a),e(innerKey,i)}]);f.push(d(j,this[g]))}return f},contains:function(a,b){var c;if("string"==typeof b){var d=LINQ.utils.parseExpression(b);c=function(b){return d(b,a)}}else c="function"!=typeof b?function(b){return b===a}:function(c){return b(c,a)};return LINQ.methods.any.apply(this,[c])},aggregate:function(a,b){if("string"==typeof a)a=LINQ.utils.parseExpression(a);else if("function"!=typeof a)throw new Error("Aggregator function is required");if(this.length<=0)return b;var c="undefined"==typeof b?LINQ.utils.getDefaultValue(LINQ.utils.getType(this[0])):b;if("function"==typeof Array.prototype.reduce)return this.reduce(a,c);for(var d=0,e=this.length;e>d;d++)c=a(c,this[d],d,this);return c},sum:function(a,b){return"string"==typeof a?a=LINQ.utils.parseExpression(a):"function"!=typeof a&&(a=function(a){return a}),b="undefined"==typeof b?LINQ.utils.getDefaultValue(LINQ.utils.getType(a(this[0],0,this))):b,LINQ.methods.aggregate.apply(this,[function(b,c,d,e){return b+a(c,d,e)},b])},min:function(a){return"string"==typeof a?a=LINQ.utils.parseExpression(a):"function"!=typeof a&&(a=function(a){return a}),this.length<=0?void 0:LINQ.methods.aggregate.apply(this,[function(b,c,d,e){var f=a(c,d,e);return b>f?f:b},a(this[0],0,this)])},max:function(a){return"string"==typeof a?a=LINQ.utils.parseExpression(a):"function"!=typeof a&&(a=function(a){return a}),this.length<=0?void 0:LINQ.methods.aggregate.apply(this,[function(b,c,d,e){var f=a(c,d,e);return f>b?f:b},a(this[0],0,this)])},skip:function(a){if("number"!=typeof a||0>a)throw new TypeError("Count is required and should be a positive number");return this.slice(a,this.length)},take:function(a){if("number"!=typeof a||0>a)throw new TypeError("Count is required and should be a positive number");return this.slice(0,a)},ofType:function(a){if("string"!=typeof a)throw new TypeError("Type is required.");return LINQ.methods.where.apply(this,[function(b){return typeof b===a}])},union:function(a,b){return[].concat(this,a).distinct(function(a){return a},b)},except:function(a,b){"string"==typeof b?b=LINQ.utils.parseExpression(b):"function"!=typeof b&&(b=function(a,b){return a===b});for(var c=[],d=0,e=this.length;e>d;d++){for(var f=!0,g=0,h=a.length;h>g;g++)if(b(this[d],a[g])){f=!1;break}f&&c.push(this[d])}return c}}},LINQ.methods.firstOrDefault.finalize=!0,LINQ.methods.lastOrDefault.finalize=!0,LINQ.methods.count.finalize=!0,LINQ.methods.any.finalize=!0,LINQ.methods.contains.finalize=!0,LINQ.methods.all.finalize=!0,LINQ.methods.aggregate.finalize=!0,LINQ.methods.sum.finalize=!0,LINQ.methods.min.finalize=!0,LINQ.methods.max.finalize=!0;for(var key in LINQ.methods)LINQ.methods.hasOwnProperty(key)&&(Array.prototype[key]=LINQ.methods[key])}(); \ No newline at end of file +!function(){var stringTrim=function(a){return"string"!=typeof a||null===a?a:String.prototype.trim?a.trim():a.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"")},expressionCache={},LINQ={utils:{parseExpression:function(a){if("function"==typeof a)return a;if(null==a||"string"!=typeof a||a.indexOf("=>")<0)throw new SyntaxError('Expression "'+a+'" is invalid');if("function"==typeof expressionCache[a])return expressionCache[a];var b,c=a.split("=>"),d=stringTrim(c[0]).replace(/[\(\)\s]/gi,""),e=stringTrim(c[1]);try{e.indexOf("return")<0&&(e="return ("+e+")"),b=new Function(d,e)}catch(f){b=new Function(d,e)}if("function"!=typeof b)throw new SyntaxError('Expression "'+a+'" is invalid');return expressionCache[a]=b,b},getType:function(a){var b=typeof a;if("object"!==b)return b;if(null===a)return"null";var c=a.constructor,d="function"==typeof c&&c.name;return"string"==typeof d&&d.length>0?d:"object"},getDefaultValue:function(type){if("string"!=typeof type)throw new TypeError("Type must be a string.");switch(type){case"boolean":return!1;case"function":return function(){};case"null":return null;case"number":return 0;case"object":return{};case"string":return"";case"symbol":return Symbol();case"undefined":return}try{var ctor="function"==typeof this[type]?this[type]:eval(type);return new ctor}catch(e){return{}}},isArray:function(a){return Array.isArray?Array.isArray(a):"[object Array]"===Object.prototype.toString.call(a)}},methods:{any:function(a){if("string"==typeof a)a=LINQ.utils.parseExpression(a);else if("function"!=typeof a)return this.length>0;if("function"==typeof Array.prototype.some)return this.some(a);for(var b=0,c=this.length;bb?1:0}),this.slice(0).sort(function(c,d){var e=a(c),f=a(d);return b(e,f)})},orderByDescending:function(a,b){"string"==typeof b?b=LINQ.utils.parseExpression(b):"function"!=typeof b&&(b=function(a,b){return ab?1:0});var c=function(){return b.apply(this,arguments)*-1};return LINQ.methods.orderBy.apply(this,[a,c])},groupBy:function(a,b){if("string"==typeof a)a=LINQ.utils.parseExpression(a);else if("function"!=typeof a)throw new Error("Key selector is required");"string"==typeof b?b=LINQ.utils.parseExpression(b):"function"!=typeof b&&(b=function(a,b){return{group:a,values:b}});for(var c={},d=0,e=this.length;d=0;b--)if(a(this[b],b,this))return this[b];return null},joinWith:function(a,b,c,d,e){if("string"==typeof b)b=LINQ.utils.parseExpression(b);else if("function"!=typeof b)throw new Error("Inner key selector is required");if("string"==typeof c)c=LINQ.utils.parseExpression(c);else if("function"!=typeof c)throw new Error("Outer key selector is required");if("string"==typeof d)d=LINQ.utils.parseExpression(d);else if("function"!=typeof d)throw new Error("Results selector is required");"string"==typeof e?e=LINQ.utils.parseExpression(e):"function"!=typeof e&&(e=function(a,b){return a===b});for(var f=[],g=0,h=this.length;gf?f:b},a(this[0],0,this)])},max:function(a){if("string"==typeof a?a=LINQ.utils.parseExpression(a):"function"!=typeof a&&(a=function(a){return a}),!(this.length<=0))return LINQ.methods.aggregate.apply(this,[function(b,c,d,e){var f=a(c,d,e);return b")<0)throw new SyntaxError('Expression "'+a+'" is invalid');if("function"==typeof expressionCache[a])return expressionCache[a];var b,c=a.split("=>"),d=stringTrim(c[0]).replace(/[\(\)\s]/gi,""),e=stringTrim(c[1]);try{e.indexOf("return")<0&&(e="return ("+e+")"),b=new Function(d,e)}catch(f){b=new Function(d,e)}if("function"!=typeof b)throw new SyntaxError('Expression "'+a+'" is invalid');return expressionCache[a]=b,b},getType:function(a){var b=typeof a;if("object"!==b)return b;if(null===a)return"null";var c=a.constructor,d="function"==typeof c&&c.name;return"string"==typeof d&&d.length>0?d:"object"},getDefaultValue:function(type){if("string"!=typeof type)throw new TypeError("Type must be a string.");switch(type){case"boolean":return!1;case"function":return function(){};case"null":return null;case"number":return 0;case"object":return{};case"string":return"";case"symbol":return Symbol();case"undefined":return}try{var ctor="function"==typeof this[type]?this[type]:eval(type);return new ctor}catch(e){return{}}},isArray:function(a){return Array.isArray?Array.isArray(a):"[object Array]"===Object.prototype.toString.call(a)}},methods:{any:function(a){if("string"==typeof a)a=LINQ.utils.parseExpression(a);else if("function"!=typeof a)return this.length>0;if("function"==typeof Array.prototype.some)return this.some(a);for(var b=0,c=this.length;c>b;b++)if(a(this[b],b,this))return!0;return!1},all:function(a){if("string"==typeof a)a=LINQ.utils.parseExpression(a);else if("function"!=typeof a)throw new Error("Predicate is required");if("function"==typeof Array.prototype.every)return this.every(a);var b=function(){return!a.apply(this,arguments)};return!LINQ.methods.any.apply(this,[b])},where:function(a){if("string"==typeof a)a=LINQ.utils.parseExpression(a);else if("function"!=typeof a)throw new Error("Predicate is required");if("function"==typeof Array.prototype.filter)return this.filter(a);for(var b=[],c=0,d=this.length;d>c;c++)a(this[c],c,this)&&b.push(this[c]);return b},select:function(a){if("string"==typeof a)a=LINQ.utils.parseExpression(a);else if("function"!=typeof a)throw new Error("Selector is required");if("function"==typeof Array.prototype.map)return this.map(a);for(var b=[],c=0,d=this.length;d>c;c++)b.push(a(this[c],c,this));return b},selectMany:function(a){if("string"==typeof a)a=LINQ.utils.parseExpression(a);else if("function"!=typeof a)throw new Error("Selector is required");for(var b=[],c=0,d=this.length;d>c;c++){var e=a(this[c],c,this);LINQ.utils.isArray(e)&&b.push(e)}return Array.prototype.concat.apply([],b)},count:function(a){if("string"==typeof a)a=LINQ.utils.parseExpression(a);else if("function"!=typeof a)return this.length;if("function"==typeof Array.prototype.filter)return this.filter(a).length;for(var b=0,c=0,d=this.length;d>c;c++)a(this[c],c,this)&&b++;return b},orderBy:function(a,b){return"string"==typeof a?a=LINQ.utils.parseExpression(a):"function"!=typeof a&&(a=function(a){return a}),"string"==typeof b?b=LINQ.utils.parseExpression(b):"function"!=typeof b&&(b=function(a,b){return b>a?-1:a>b?1:0}),this.slice(0).sort(function(c,d){var e=a(c),f=a(d);return b(e,f)})},orderByDescending:function(a,b){"string"==typeof b?b=LINQ.utils.parseExpression(b):"function"!=typeof b&&(b=function(a,b){return b>a?-1:a>b?1:0});var c=function(){return-1*b.apply(this,arguments)};return LINQ.methods.orderBy.apply(this,[a,c])},groupBy:function(a,b){if("string"==typeof a)a=LINQ.utils.parseExpression(a);else if("function"!=typeof a)throw new Error("Key selector is required");"string"==typeof b?b=LINQ.utils.parseExpression(b):"function"!=typeof b&&(b=function(a,b){return{group:a,values:b}});for(var c={},d=0,e=this.length;e>d;d++){var f=a(this[d],d,this);c[f]||(c[f]=[]),c[f].push(this[d])}var g=[];for(var h in c)c.hasOwnProperty(h)&&g.push(b(h,c[h]));return g},distinct:function(a,b){"string"==typeof a?a=LINQ.utils.parseExpression(a):"function"!=typeof a&&(a=function(a){return a}),"string"==typeof b?b=LINQ.utils.parseExpression(b):"function"!=typeof b&&(b=function(a,b){return a===b});for(var c=[],d={},e=0,f=this.length;f>e;e++){var g=a(this[e],e,this);if(d[g]){for(var h=!0,i=0,j=d[g].length;j>i;i++)if(b(d[g][i],g)){h=!1;break}h&&(c.push(this[e]),d[g].push(g))}else d[g]=[g],c.push(this[e])}return c},firstOrDefault:function(a){if("string"==typeof a?a=LINQ.utils.parseExpression(a):"function"!=typeof a&&(a=function(){return!0}),"function"==typeof Array.prototype.find)return this.find(a)||null;for(var b=0,c=this.length;c>b;b++)if(a(this[b],b,this))return this[b];return null},lastOrDefault:function(a){"string"==typeof a?a=LINQ.utils.parseExpression(a):"function"!=typeof a&&(a=function(){return!0});for(var b=this.length-1;b>=0;b--)if(a(this[b],b,this))return this[b];return null},joinWith:function(a,b,c,d,e){if("string"==typeof b)b=LINQ.utils.parseExpression(b);else if("function"!=typeof b)throw new Error("Inner key selector is required");if("string"==typeof c)c=LINQ.utils.parseExpression(c);else if("function"!=typeof c)throw new Error("Outer key selector is required");if("string"==typeof d)d=LINQ.utils.parseExpression(d);else if("function"!=typeof d)throw new Error("Results selector is required");"string"==typeof e?e=LINQ.utils.parseExpression(e):"function"!=typeof e&&(e=function(a,b){return a===b});for(var f=[],g=0,h=this.length;h>g;g++)for(var i=c(this[g],g,this),j=0,k=a.length;k>j;j++){var l=b(a[j],j,a);e(l,i)&&f.push(d(a[j],this[g]))}return f},groupJoinWith:function(a,b,c,d,e){if("string"==typeof b)b=LINQ.utils.parseExpression(b);else if("function"!=typeof b)throw new Error("Inner key selector is required");if("string"==typeof c)c=LINQ.utils.parseExpression(c);else if("function"!=typeof c)throw new Error("Outer key selector is required");if("string"==typeof d)d=LINQ.utils.parseExpression(d);else if("function"!=typeof d)throw new Error("Results selector is required");"string"==typeof e?e=LINQ.utils.parseExpression(e):"function"!=typeof e&&(e=function(a,b){return a===b});for(var f=[],g=0,h=this.length;h>g;g++){var i=c(this[g],g,this),j=LINQ.methods.where.apply(a,[function(c,d){return innerKey=b(a[d],d,a),e(innerKey,i)}]);f.push(d(j,this[g]))}return f},contains:function(a,b){var c;if("string"==typeof b){var d=LINQ.utils.parseExpression(b);c=function(b){return d(b,a)}}else c="function"!=typeof b?function(b){return b===a}:function(c){return b(c,a)};return LINQ.methods.any.apply(this,[c])},aggregate:function(a,b){if("string"==typeof a)a=LINQ.utils.parseExpression(a);else if("function"!=typeof a)throw new Error("Aggregator function is required");if(this.length<=0)return b;var c="undefined"==typeof b?LINQ.utils.getDefaultValue(LINQ.utils.getType(this[0])):b;if("function"==typeof Array.prototype.reduce)return this.reduce(a,c);for(var d=0,e=this.length;e>d;d++)c=a(c,this[d],d,this);return c},sum:function(a,b){return"string"==typeof a?a=LINQ.utils.parseExpression(a):"function"!=typeof a&&(a=function(a){return a}),b="undefined"==typeof b?LINQ.utils.getDefaultValue(LINQ.utils.getType(a(this[0],0,this))):b,LINQ.methods.aggregate.apply(this,[function(b,c,d,e){return b+a(c,d,e)},b])},min:function(a){return"string"==typeof a?a=LINQ.utils.parseExpression(a):"function"!=typeof a&&(a=function(a){return a}),this.length<=0?void 0:LINQ.methods.aggregate.apply(this,[function(b,c,d,e){var f=a(c,d,e);return b>f?f:b},a(this[0],0,this)])},max:function(a){return"string"==typeof a?a=LINQ.utils.parseExpression(a):"function"!=typeof a&&(a=function(a){return a}),this.length<=0?void 0:LINQ.methods.aggregate.apply(this,[function(b,c,d,e){var f=a(c,d,e);return f>b?f:b},a(this[0],0,this)])},skip:function(a){if("number"!=typeof a||0>a)throw new TypeError("Count is required and should be a positive number");return this.slice(a,this.length)},take:function(a){if("number"!=typeof a||0>a)throw new TypeError("Count is required and should be a positive number");return this.slice(0,a)},ofType:function(a){if("string"!=typeof a)throw new TypeError("Type is required.");return LINQ.methods.where.apply(this,[function(b){return typeof b===a}])},union:function(a,b){return[].concat(this,a).distinct(function(a){return a},b)},except:function(a,b){"string"==typeof b?b=LINQ.utils.parseExpression(b):"function"!=typeof b&&(b=function(a,b){return a===b});for(var c=[],d=0,e=this.length;e>d;d++){for(var f=!0,g=0,h=a.length;h>g;g++)if(b(this[d],a[g])){f=!1;break}f&&c.push(this[d])}return c}}},LINQ.methods.firstOrDefault.finalize=!0,LINQ.methods.lastOrDefault.finalize=!0,LINQ.methods.count.finalize=!0,LINQ.methods.any.finalize=!0,LINQ.methods.contains.finalize=!0,LINQ.methods.all.finalize=!0,LINQ.methods.aggregate.finalize=!0,LINQ.methods.sum.finalize=!0,LINQ.methods.min.finalize=!0,LINQ.methods.max.finalize=!0;for(var key in LINQ.methods)LINQ.methods.hasOwnProperty(key)&&(Array.prototype[key]=LINQ.methods[key])}(),function(a){if("undefined"!=typeof ko&&ko.observableArray&&ko.observableArray.fn){Array.prototype.toObservableArray=function(){return ko.observableArray(this)},ko.observableArray.fn.toArray=function(){return this()};for(var b in a.methods)a.methods.hasOwnProperty(b)&&(ko.observableArray.fn[b]=function(b){return function(){return a.methods[b].apply(this(),arguments)}}(b))}}(LINQ); \ No newline at end of file +!function(){var stringTrim=function(a){return"string"!=typeof a||null===a?a:String.prototype.trim?a.trim():a.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"")},expressionCache={},LINQ={utils:{parseExpression:function(a){if("function"==typeof a)return a;if(null==a||"string"!=typeof a||a.indexOf("=>")<0)throw new SyntaxError('Expression "'+a+'" is invalid');if("function"==typeof expressionCache[a])return expressionCache[a];var b,c=a.split("=>"),d=stringTrim(c[0]).replace(/[\(\)\s]/gi,""),e=stringTrim(c[1]);try{e.indexOf("return")<0&&(e="return ("+e+")"),b=new Function(d,e)}catch(f){b=new Function(d,e)}if("function"!=typeof b)throw new SyntaxError('Expression "'+a+'" is invalid');return expressionCache[a]=b,b},getType:function(a){var b=typeof a;if("object"!==b)return b;if(null===a)return"null";var c=a.constructor,d="function"==typeof c&&c.name;return"string"==typeof d&&d.length>0?d:"object"},getDefaultValue:function(type){if("string"!=typeof type)throw new TypeError("Type must be a string.");switch(type){case"boolean":return!1;case"function":return function(){};case"null":return null;case"number":return 0;case"object":return{};case"string":return"";case"symbol":return Symbol();case"undefined":return}try{var ctor="function"==typeof this[type]?this[type]:eval(type);return new ctor}catch(e){return{}}},isArray:function(a){return Array.isArray?Array.isArray(a):"[object Array]"===Object.prototype.toString.call(a)}},methods:{any:function(a){if("string"==typeof a)a=LINQ.utils.parseExpression(a);else if("function"!=typeof a)return this.length>0;if("function"==typeof Array.prototype.some)return this.some(a);for(var b=0,c=this.length;bb?1:0}),this.slice(0).sort(function(c,d){var e=a(c),f=a(d);return b(e,f)})},orderByDescending:function(a,b){"string"==typeof b?b=LINQ.utils.parseExpression(b):"function"!=typeof b&&(b=function(a,b){return ab?1:0});var c=function(){return b.apply(this,arguments)*-1};return LINQ.methods.orderBy.apply(this,[a,c])},groupBy:function(a,b){if("string"==typeof a)a=LINQ.utils.parseExpression(a);else if("function"!=typeof a)throw new Error("Key selector is required");"string"==typeof b?b=LINQ.utils.parseExpression(b):"function"!=typeof b&&(b=function(a,b){return{group:a,values:b}});for(var c={},d=0,e=this.length;d=0;b--)if(a(this[b],b,this))return this[b];return null},joinWith:function(a,b,c,d,e){if("string"==typeof b)b=LINQ.utils.parseExpression(b);else if("function"!=typeof b)throw new Error("Inner key selector is required");if("string"==typeof c)c=LINQ.utils.parseExpression(c);else if("function"!=typeof c)throw new Error("Outer key selector is required");if("string"==typeof d)d=LINQ.utils.parseExpression(d);else if("function"!=typeof d)throw new Error("Results selector is required");"string"==typeof e?e=LINQ.utils.parseExpression(e):"function"!=typeof e&&(e=function(a,b){return a===b});for(var f=[],g=0,h=this.length;gf?f:b},a(this[0],0,this)])},max:function(a){if("string"==typeof a?a=LINQ.utils.parseExpression(a):"function"!=typeof a&&(a=function(a){return a}),!(this.length<=0))return LINQ.methods.aggregate.apply(this,[function(b,c,d,e){var f=a(c,d,e);return b")<0)throw new SyntaxError('Expression "'+a+'" is invalid');if("function"==typeof expressionCache[a])return expressionCache[a];var b,c=a.split("=>"),d=stringTrim(c[0]).replace(/[\(\)\s]/gi,""),e=stringTrim(c[1]);try{e.indexOf("return")<0&&(e="return ("+e+")"),b=new Function(d,e)}catch(f){b=new Function(d,e)}if("function"!=typeof b)throw new SyntaxError('Expression "'+a+'" is invalid');return expressionCache[a]=b,b},getType:function(a){var b=typeof a;if("object"!==b)return b;if(null===a)return"null";var c=a.constructor,d="function"==typeof c&&c.name;return"string"==typeof d&&d.length>0?d:"object"},getDefaultValue:function(type){if("string"!=typeof type)throw new TypeError("Type must be a string.");switch(type){case"boolean":return!1;case"function":return function(){};case"null":return null;case"number":return 0;case"object":return{};case"string":return"";case"symbol":return Symbol();case"undefined":return}try{var ctor="function"==typeof this[type]?this[type]:eval(type);return new ctor}catch(e){return{}}},isArray:function(a){return Array.isArray?Array.isArray(a):"[object Array]"===Object.prototype.toString.call(a)}},methods:{any:function(a){if("string"==typeof a)a=LINQ.utils.parseExpression(a);else if("function"!=typeof a)return this.length>0;if("function"==typeof Array.prototype.some)return this.some(a);for(var b=0,c=this.length;c>b;b++)if(a(this[b],b,this))return!0;return!1},all:function(a){if("string"==typeof a)a=LINQ.utils.parseExpression(a);else if("function"!=typeof a)throw new Error("Predicate is required");if("function"==typeof Array.prototype.every)return this.every(a);var b=function(){return!a.apply(this,arguments)};return!LINQ.methods.any.apply(this,[b])},where:function(a){if("string"==typeof a)a=LINQ.utils.parseExpression(a);else if("function"!=typeof a)throw new Error("Predicate is required");if("function"==typeof Array.prototype.filter)return this.filter(a);for(var b=[],c=0,d=this.length;d>c;c++)a(this[c],c,this)&&b.push(this[c]);return b},select:function(a){if("string"==typeof a)a=LINQ.utils.parseExpression(a);else if("function"!=typeof a)throw new Error("Selector is required");if("function"==typeof Array.prototype.map)return this.map(a);for(var b=[],c=0,d=this.length;d>c;c++)b.push(a(this[c],c,this));return b},selectMany:function(a){if("string"==typeof a)a=LINQ.utils.parseExpression(a);else if("function"!=typeof a)throw new Error("Selector is required");for(var b=[],c=0,d=this.length;d>c;c++){var e=a(this[c],c,this);LINQ.utils.isArray(e)&&b.push(e)}return Array.prototype.concat.apply([],b)},count:function(a){if("string"==typeof a)a=LINQ.utils.parseExpression(a);else if("function"!=typeof a)return this.length;if("function"==typeof Array.prototype.filter)return this.filter(a).length;for(var b=0,c=0,d=this.length;d>c;c++)a(this[c],c,this)&&b++;return b},orderBy:function(a,b){return"string"==typeof a?a=LINQ.utils.parseExpression(a):"function"!=typeof a&&(a=function(a){return a}),"string"==typeof b?b=LINQ.utils.parseExpression(b):"function"!=typeof b&&(b=function(a,b){return b>a?-1:a>b?1:0}),this.slice(0).sort(function(c,d){var e=a(c),f=a(d);return b(e,f)})},orderByDescending:function(a,b){"string"==typeof b?b=LINQ.utils.parseExpression(b):"function"!=typeof b&&(b=function(a,b){return b>a?-1:a>b?1:0});var c=function(){return-1*b.apply(this,arguments)};return LINQ.methods.orderBy.apply(this,[a,c])},groupBy:function(a,b){if("string"==typeof a)a=LINQ.utils.parseExpression(a);else if("function"!=typeof a)throw new Error("Key selector is required");"string"==typeof b?b=LINQ.utils.parseExpression(b):"function"!=typeof b&&(b=function(a,b){return{group:a,values:b}});for(var c={},d=0,e=this.length;e>d;d++){var f=a(this[d],d,this);c[f]||(c[f]=[]),c[f].push(this[d])}var g=[];for(var h in c)c.hasOwnProperty(h)&&g.push(b(h,c[h]));return g},distinct:function(a,b){"string"==typeof a?a=LINQ.utils.parseExpression(a):"function"!=typeof a&&(a=function(a){return a}),"string"==typeof b?b=LINQ.utils.parseExpression(b):"function"!=typeof b&&(b=function(a,b){return a===b});for(var c=[],d={},e=0,f=this.length;f>e;e++){var g=a(this[e],e,this);if(d[g]){for(var h=!0,i=0,j=d[g].length;j>i;i++)if(b(d[g][i],g)){h=!1;break}h&&(c.push(this[e]),d[g].push(g))}else d[g]=[g],c.push(this[e])}return c},firstOrDefault:function(a){if("string"==typeof a?a=LINQ.utils.parseExpression(a):"function"!=typeof a&&(a=function(){return!0}),"function"==typeof Array.prototype.find)return this.find(a)||null;for(var b=0,c=this.length;c>b;b++)if(a(this[b],b,this))return this[b];return null},lastOrDefault:function(a){"string"==typeof a?a=LINQ.utils.parseExpression(a):"function"!=typeof a&&(a=function(){return!0});for(var b=this.length-1;b>=0;b--)if(a(this[b],b,this))return this[b];return null},joinWith:function(a,b,c,d,e){if("string"==typeof b)b=LINQ.utils.parseExpression(b);else if("function"!=typeof b)throw new Error("Inner key selector is required");if("string"==typeof c)c=LINQ.utils.parseExpression(c);else if("function"!=typeof c)throw new Error("Outer key selector is required");if("string"==typeof d)d=LINQ.utils.parseExpression(d);else if("function"!=typeof d)throw new Error("Results selector is required");"string"==typeof e?e=LINQ.utils.parseExpression(e):"function"!=typeof e&&(e=function(a,b){return a===b});for(var f=[],g=0,h=this.length;h>g;g++)for(var i=c(this[g],g,this),j=0,k=a.length;k>j;j++){var l=b(a[j],j,a);e(l,i)&&f.push(d(a[j],this[g]))}return f},groupJoinWith:function(a,b,c,d,e){if("string"==typeof b)b=LINQ.utils.parseExpression(b);else if("function"!=typeof b)throw new Error("Inner key selector is required");if("string"==typeof c)c=LINQ.utils.parseExpression(c);else if("function"!=typeof c)throw new Error("Outer key selector is required");if("string"==typeof d)d=LINQ.utils.parseExpression(d);else if("function"!=typeof d)throw new Error("Results selector is required");"string"==typeof e?e=LINQ.utils.parseExpression(e):"function"!=typeof e&&(e=function(a,b){return a===b});for(var f=[],g=0,h=this.length;h>g;g++){var i=c(this[g],g,this),j=LINQ.methods.where.apply(a,[function(c,d){return innerKey=b(a[d],d,a),e(innerKey,i)}]);f.push(d(j,this[g]))}return f},contains:function(a,b){var c;if("string"==typeof b){var d=LINQ.utils.parseExpression(b);c=function(b){return d(b,a)}}else c="function"!=typeof b?function(b){return b===a}:function(c){return b(c,a)};return LINQ.methods.any.apply(this,[c])},aggregate:function(a,b){if("string"==typeof a)a=LINQ.utils.parseExpression(a);else if("function"!=typeof a)throw new Error("Aggregator function is required");if(this.length<=0)return b;var c="undefined"==typeof b?LINQ.utils.getDefaultValue(LINQ.utils.getType(this[0])):b;if("function"==typeof Array.prototype.reduce)return this.reduce(a,c);for(var d=0,e=this.length;e>d;d++)c=a(c,this[d],d,this);return c},sum:function(a,b){return"string"==typeof a?a=LINQ.utils.parseExpression(a):"function"!=typeof a&&(a=function(a){return a}),b="undefined"==typeof b?LINQ.utils.getDefaultValue(LINQ.utils.getType(a(this[0],0,this))):b,LINQ.methods.aggregate.apply(this,[function(b,c,d,e){return b+a(c,d,e)},b])},min:function(a){return"string"==typeof a?a=LINQ.utils.parseExpression(a):"function"!=typeof a&&(a=function(a){return a}),this.length<=0?void 0:LINQ.methods.aggregate.apply(this,[function(b,c,d,e){var f=a(c,d,e);return b>f?f:b},a(this[0],0,this)])},max:function(a){return"string"==typeof a?a=LINQ.utils.parseExpression(a):"function"!=typeof a&&(a=function(a){return a}),this.length<=0?void 0:LINQ.methods.aggregate.apply(this,[function(b,c,d,e){var f=a(c,d,e);return f>b?f:b},a(this[0],0,this)])},skip:function(a){if("number"!=typeof a||0>a)throw new TypeError("Count is required and should be a positive number");return this.slice(a,this.length)},take:function(a){if("number"!=typeof a||0>a)throw new TypeError("Count is required and should be a positive number");return this.slice(0,a)},ofType:function(a){if("string"!=typeof a)throw new TypeError("Type is required.");return LINQ.methods.where.apply(this,[function(b){return typeof b===a}])},union:function(a,b){return[].concat(this,a).distinct(function(a){return a},b)},except:function(a,b){"string"==typeof b?b=LINQ.utils.parseExpression(b):"function"!=typeof b&&(b=function(a,b){return a===b});for(var c=[],d=0,e=this.length;e>d;d++){for(var f=!0,g=0,h=a.length;h>g;g++)if(b(this[d],a[g])){f=!1;break}f&&c.push(this[d])}return c}}},LINQ.methods.firstOrDefault.finalize=!0,LINQ.methods.lastOrDefault.finalize=!0,LINQ.methods.count.finalize=!0,LINQ.methods.any.finalize=!0,LINQ.methods.contains.finalize=!0,LINQ.methods.all.finalize=!0,LINQ.methods.aggregate.finalize=!0,LINQ.methods.sum.finalize=!0,LINQ.methods.min.finalize=!0,LINQ.methods.max.finalize=!0;for(var key in LINQ.methods)LINQ.methods.hasOwnProperty(key)&&(Array.prototype[key]=LINQ.methods[key])}(),function(a){var b=[function(b,c){if(b.name===c.name&&"where"===c.name){var d=a.utils.parseExpression(b.args[0]),e=a.utils.parseExpression(c.args[0]);return function(c,d){return{name:b.name,args:[function(){return c.apply(this,arguments)&&d.apply(this,arguments)}],fn:a.methods[b.name]}}(d,e)}return!1},function(b,c){if(b.name===c.name&&"select"===c.name){var d=a.utils.parseExpression(b.args[0]),e=a.utils.parseExpression(c.args[0]);return function(c,d){return{name:b.name,args:[function(){return d.apply(this,[c.apply(this,arguments)])}],fn:a.methods[b.name]}}(d,e)}return!1},function(a,b){var c=["orderBy","orderByDescending"];return c.contains(a.name)&&c.contains(b.name)?b:!1},function(a,b){return"skip"==a.name&&"take"==b.name?function(a,b){return{name:"skiptake",args:[a,b],fn:function(a,b){return this.slice(a,a+b)}}}(a.args[0],b.args[0]):!1}],c=function(c){var d=this,e=c;d._modificatorQueue=[];var f=function(){for(var a=d._modificatorQueue.length,b=0;a>b;b++){var c=d._modificatorQueue[b];e=c.fn.apply(e,c.args)}return d._modificatorQueue.splice(0,a),a},g=function(){for(var a=0;ag;g++){var i=b[g],j=i(c,e);j&&(f=!0,d._modificatorQueue.splice(a+1,1),d._modificatorQueue[a]=j)}f||a++}};d.optimize=function(){return g(),d},d.toArray=function(){return e.length>100&&d._modificatorQueue.length>2&&d.optimize(),f(),a.utils.isArray(e)?e.slice(0):e}};Array.prototype.toLazy=function(){return new c(this)};for(var d in a.methods)a.methods.hasOwnProperty(d)&&(c.prototype[d]=function(b){return function(){var c=a.methods[b];return this._modificatorQueue.push({fn:a.methods[b],args:arguments,name:b}),c.finalize?this.toArray():this}}(d))}(LINQ); \ No newline at end of file +!function(){var stringTrim=function(a){return"string"!=typeof a||null===a?a:String.prototype.trim?a.trim():a.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"")},expressionCache={},LINQ={utils:{parseExpression:function(a){if("function"==typeof a)return a;if(null==a||"string"!=typeof a||a.indexOf("=>")<0)throw new SyntaxError('Expression "'+a+'" is invalid');if("function"==typeof expressionCache[a])return expressionCache[a];var b,c=a.split("=>"),d=stringTrim(c[0]).replace(/[\(\)\s]/gi,""),e=stringTrim(c[1]);try{e.indexOf("return")<0&&(e="return ("+e+")"),b=new Function(d,e)}catch(f){b=new Function(d,e)}if("function"!=typeof b)throw new SyntaxError('Expression "'+a+'" is invalid');return expressionCache[a]=b,b},getType:function(a){var b=typeof a;if("object"!==b)return b;if(null===a)return"null";var c=a.constructor,d="function"==typeof c&&c.name;return"string"==typeof d&&d.length>0?d:"object"},getDefaultValue:function(type){if("string"!=typeof type)throw new TypeError("Type must be a string.");switch(type){case"boolean":return!1;case"function":return function(){};case"null":return null;case"number":return 0;case"object":return{};case"string":return"";case"symbol":return Symbol();case"undefined":return}try{var ctor="function"==typeof this[type]?this[type]:eval(type);return new ctor}catch(e){return{}}},isArray:function(a){return Array.isArray?Array.isArray(a):"[object Array]"===Object.prototype.toString.call(a)}},methods:{any:function(a){if("string"==typeof a)a=LINQ.utils.parseExpression(a);else if("function"!=typeof a)return this.length>0;if("function"==typeof Array.prototype.some)return this.some(a);for(var b=0,c=this.length;bb?1:0}),this.slice(0).sort(function(c,d){var e=a(c),f=a(d);return b(e,f)})},orderByDescending:function(a,b){"string"==typeof b?b=LINQ.utils.parseExpression(b):"function"!=typeof b&&(b=function(a,b){return ab?1:0});var c=function(){return b.apply(this,arguments)*-1};return LINQ.methods.orderBy.apply(this,[a,c])},groupBy:function(a,b){if("string"==typeof a)a=LINQ.utils.parseExpression(a);else if("function"!=typeof a)throw new Error("Key selector is required");"string"==typeof b?b=LINQ.utils.parseExpression(b):"function"!=typeof b&&(b=function(a,b){return{group:a,values:b}});for(var c={},d=0,e=this.length;d=0;b--)if(a(this[b],b,this))return this[b];return null},joinWith:function(a,b,c,d,e){if("string"==typeof b)b=LINQ.utils.parseExpression(b);else if("function"!=typeof b)throw new Error("Inner key selector is required");if("string"==typeof c)c=LINQ.utils.parseExpression(c);else if("function"!=typeof c)throw new Error("Outer key selector is required");if("string"==typeof d)d=LINQ.utils.parseExpression(d);else if("function"!=typeof d)throw new Error("Results selector is required");"string"==typeof e?e=LINQ.utils.parseExpression(e):"function"!=typeof e&&(e=function(a,b){return a===b});for(var f=[],g=0,h=this.length;gf?f:b},a(this[0],0,this)])},max:function(a){if("string"==typeof a?a=LINQ.utils.parseExpression(a):"function"!=typeof a&&(a=function(a){return a}),!(this.length<=0))return LINQ.methods.aggregate.apply(this,[function(b,c,d,e){var f=a(c,d,e);return b100&&d._modificatorQueue.length>2&&d.optimize(),f(),a.utils.isArray(e)?e.slice(0):e}};Array.prototype.toLazy=function(){return new c(this)};for(var d in a.methods)a.methods.hasOwnProperty(d)&&(c.prototype[d]=function(b){return function(){var c=a.methods[b];return this._modificatorQueue.push({fn:a.methods[b],args:arguments,name:b}),c.finalize?this.toArray():this}}(d))}(LINQ)}(); \ No newline at end of file diff --git a/gruntfile.js b/gruntfile.js index 7fb382f..69dd042 100644 --- a/gruntfile.js +++ b/gruntfile.js @@ -1,35 +1,61 @@ -module.exports = function(grunt) { - var license = grunt.file.read('LICENSE'); - var githubUrl = 'https://github.com/akopachov/mini-linq-js'; - grunt.initConfig({ - uglify: { - options: { - preserveComments: false, - banner: '/* ! ' + githubUrl + ' */\n/* !\n' + license + '\n */\n' - }, - core: { - files: { - 'dist/mini-linq.min.js': ['src/mini-linq.js'] - } - }, - coreAndLazy: { - files: { - 'dist/mini-linq.with-lazy.min.js': ['src/mini-linq.js', 'src/mini-linq.lazy.js'] - } - }, - coreAndKnockout: { - files: { - 'dist/mini-linq.with-knockout.min.js': ['src/mini-linq.js', 'src/mini-linq.knockout.js'] - } - }, - full: { - files: { - 'dist/mini-linq.full.min.js': ['src/mini-linq.js', 'src/mini-linq.lazy.js', 'src/mini-linq.knockout.js'] - } - } - } - }); - require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks); - - grunt.registerTask('default', ['uglify']); +module.exports = function(grunt) { + var license = grunt.file.read('LICENSE'); + var githubUrl = 'https://github.com/akopachov/mini-linq-js'; + grunt.initConfig({ + copy: { + core: { + src: 'src/mini-linq.js', + dest: 'dist/mini-linq.min.js', + options: { + process: function (content, srcpath) { + return content.replace('/* ADDITIONAL_ATTACHMENTS */', ''); + } + } + }, + coreAndLazy: { + src: 'src/mini-linq.js', + dest: 'dist/mini-linq.with-lazy.min.js', + options: { + process: function (content, srcpath) { + return content.replace('/* ADDITIONAL_ATTACHMENTS */', grunt.file.read('src/mini-linq.lazy.js')); + } + } + }, + coreAndKnockout: { + src: 'src/mini-linq.js', + dest: 'dist/mini-linq.with-knockout.min.js', + options: { + process: function (content, srcpath) { + return content.replace('/* ADDITIONAL_ATTACHMENTS */', grunt.file.read('src/mini-linq.knockout.js')); + } + } + }, + full: { + src: 'src/mini-linq.js', + dest: 'dist/mini-linq.full.min.js', + options: { + process: function (content, srcpath) { + return content.replace('/* ADDITIONAL_ATTACHMENTS */', grunt.file.read('src/mini-linq.lazy.js') + grunt.file.read('src/mini-linq.knockout.js')); + } + } + } + }, + uglify: { + options: { + preserveComments: false, + banner: '/* ! ' + githubUrl + ' */\n/* !\n' + license + '\n */\n' + }, + build: { + files: [{ + expand: true, + cwd: 'dist/', + src: '*.js', + dest: 'dist/' + }] + } + } + }); + require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks); + + grunt.registerTask('default', ['copy', 'uglify']); }; \ No newline at end of file diff --git a/package.json b/package.json index eb8f758..9d787fe 100644 --- a/package.json +++ b/package.json @@ -1,32 +1,36 @@ -{ - "name": "mini-linq-js", - "version": "1.3.1", - "description": "LINQ for JavaScript library, which allows to work with arrays in a more easy way and focus on business logic.", - "homepage": "https://github.com/akopachov/mini-linq-js", - "keywords": ["linq", "array"], - "license": "MIT", - "main": "dist/mini-linq.full.min.js", - "repository" : { - "type" : "git", - "url" : "https://github.com/akopachov/mini-linq-js.git" - }, - "author": { - "name" : "Alex Kopachov", - "email" : "alex.kopachov@gmail.com", - "url" : "https://www.linkedin.com/in/akopachov" - }, - "files": [ - "dist", - "src", - "README.md", - "tests", - "gruntfile.js" - ], - "devDependencies": { - "mocha": "^2.5.0", - "unit.js": "^2.0.0", - "grunt": "^1.0.1", - "grunt-contrib-uglify": "^1.0.1", - "matchdep": "^1.0.1" - } -} +{ + "name": "mini-linq-js", + "version": "1.3.2", + "description": "LINQ for JavaScript library, which allows to work with arrays in a more easy way and focus on business logic.", + "homepage": "https://github.com/akopachov/mini-linq-js", + "keywords": [ + "linq", + "array" + ], + "license": "MIT", + "main": "dist/mini-linq.full.min.js", + "repository": { + "type": "git", + "url": "https://github.com/akopachov/mini-linq-js.git" + }, + "author": { + "name": "Alex Kopachov", + "email": "alex.kopachov@gmail.com", + "url": "https://www.linkedin.com/in/akopachov" + }, + "files": [ + "dist", + "src", + "README.md", + "tests", + "gruntfile.js" + ], + "devDependencies": { + "grunt": "^1.0.1", + "grunt-contrib-copy": "^1.0.0", + "grunt-contrib-uglify": "^1.0.1", + "matchdep": "^1.0.1", + "mocha": "^2.5.0", + "unit.js": "^2.0.0" + } +} diff --git a/src/mini-linq.js b/src/mini-linq.js index 6bc131a..3359272 100644 --- a/src/mini-linq.js +++ b/src/mini-linq.js @@ -35,7 +35,7 @@ SOFTWARE. return str.trim(); }; var expressionCache = {}; - LINQ = { + var LINQ = { utils: { parseExpression: function (expression) { if (typeof (expression) === "function") { @@ -617,4 +617,6 @@ SOFTWARE. Array.prototype[key] = LINQ.methods[key]; } } + + /* ADDITIONAL_ATTACHMENTS */ })(); \ No newline at end of file diff --git a/tests/test-core.js b/tests/test-core.js index 035a124..8cc63b0 100644 --- a/tests/test-core.js +++ b/tests/test-core.js @@ -1,5 +1,5 @@ if (typeof(require) !== 'undefined') { - require('../src/mini-linq.js'); + require('../dist/mini-linq.min.js'); var test = require('unit.js'); } else { var test = unitjs; @@ -7,62 +7,6 @@ if (typeof(require) !== 'undefined') { var testArray1 = [1, 2, 8, 2, 6, 3, 9, 2, 4]; -describe('Core', function() { - it('Structure', function () { - test.object(LINQ) - .hasProperty('utils') - .hasProperty('methods'); - test.object(LINQ.methods) - .isNotEmpty() - .matchEach(function(it, key) { - return typeof(it) === 'function'; - }); - }); - - it('Expression parser - 1', function() { - var expression = function(x) { return x * x; } - var expressionParsed = LINQ.utils.parseExpression('x => x * x'); - var testValue = Math.random() * 99; - test.value(expressionParsed).isFunction(); - test.value(expressionParsed(testValue)).is(expression(testValue)); - }); - - it('Expression parser - 2', function() { - var expression = function(x) { return {x: x, xx: x * x}; } - var expressionParsed = LINQ.utils.parseExpression('x => {x : x, xx: x * x}'); - var testValue = Math.random() * 99; - test.value(expressionParsed).isFunction(); - test.object(expressionParsed(testValue)).is(expression(testValue)); - }); - - it('Expression parser - 3', function() { - var expression = function(x) { var y = 1; y++; return x + y; } - var expressionParsed = LINQ.utils.parseExpression('x => { var y = 1; y++; return x + y;}'); - var testValue = Math.random() * 99; - test.value(expressionParsed).isFunction(); - test.value(expressionParsed(testValue)).is(expression(testValue)); - }); - - it('Attachment to Array', function() { - var emptyArray = []; - test.object(LINQ.methods) - .isNotEmpty() - .matchEach(function(it, key) { - return emptyArray[key] === it; - }); - }); - - it('isArray method', function() { - test.value(LINQ.utils.isArray([])).isTrue(); - test.value(LINQ.utils.isArray([1, '2', true, false, {}, null])).isTrue(); - test.value(LINQ.utils.isArray([false])).isTrue(); - test.value(LINQ.utils.isArray(true)).isFalse(); - test.value(LINQ.utils.isArray({})).isFalse(); - test.value(LINQ.utils.isArray('test')).isFalse(); - test.value(LINQ.utils.isArray(null)).isFalse(); - }); -}); - describe('Methods', function() { it('.any', function() { test.value(testArray1.any('a => a == 2')) diff --git a/tests/test-lazy.js b/tests/test-lazy.js index 97f32b8..386f770 100644 --- a/tests/test-lazy.js +++ b/tests/test-lazy.js @@ -1,6 +1,5 @@ if (typeof(require) !== 'undefined') { - require('../src/mini-linq.js'); - require('../src/mini-linq.lazy.js'); + require('../dist/mini-linq.with-lazy.min.js'); var test = require('unit.js'); } else { var test = unitjs;