Comparing version 0.0.1 to 0.0.2
72
index.js
@@ -46,8 +46,8 @@ var compareStringMap = { | ||
return obj.filter(createFilterCallback(filters)); | ||
return createFilterFunction(filters)(obj); | ||
} | ||
filter.createFilterCallback = createFilterCallback; | ||
filter.createFilterFunction = createFilterFunction; | ||
function createFilterCallback(filters) { | ||
function createFilterFunction(filters) { | ||
var //index for looping through filters | ||
@@ -72,3 +72,3 @@ filterIx | ||
// | ||
, executionPlanFunction | ||
, filterFunction | ||
; | ||
@@ -111,5 +111,16 @@ | ||
eval("executionPlanFunction = function (obj) { if ( " + executionPlan.join(" || ") + " ) {return true;} else {return false;} };"); | ||
var fnString = "filterFunction = function (data) {" | ||
+ " var result = [], obj;" | ||
+ " for (var x = 0; x < data.length; x++) {" | ||
+ " obj = data[x];" | ||
+ " if ( " + executionPlan.join(" || ") + " ) {" | ||
+ " result.push(obj);" | ||
+ " }" | ||
+ " }" | ||
+ " return result;" | ||
+ "};" | ||
return executionPlanFunction; | ||
eval(fnString); | ||
return filterFunction; | ||
} | ||
@@ -207,3 +218,3 @@ | ||
self.haveFilter = true; | ||
self.filterCallbackFunction = null; | ||
self.filterFunction = null; | ||
self.currentFilter[field] = self.currentFilter[field] || []; | ||
@@ -236,6 +247,6 @@ | ||
Selector.prototype.executeFilter = function (data) { | ||
var self = this; | ||
var self = this, result = []; | ||
if (!self.filterCallbackFunction) { | ||
self.filterCallbackFunction = createFilterCallback(self.filters); | ||
if (!self.filterFunction) { | ||
self.filterFunction = createFilterFunction(self.filters); | ||
} | ||
@@ -247,3 +258,3 @@ | ||
return data.filter(self.filterCallbackFunction); | ||
return self.filterFunction(data); | ||
}; | ||
@@ -256,3 +267,3 @@ | ||
self.filterCallbackFunction = null; | ||
self.filterFunction = null; | ||
self.currentFilter = {}; | ||
@@ -274,3 +285,3 @@ self.filters.push(self.currentFilter); | ||
self.filterCallbackFunction = null; | ||
self.filterFunction = null; | ||
@@ -394,2 +405,37 @@ if (!obj) { | ||
Selector.prototype.max = function (column) { | ||
var self = this; | ||
var ary = this.select(); | ||
return ary.reduce(function (x, record) { | ||
return Math.max(x, record[column]); | ||
}, ary[0][column]); | ||
}; | ||
Selector.prototype.min = function (column) { | ||
var self = this; | ||
var ary = this.select(); | ||
return ary.reduce(function (x, record) { | ||
return Math.min(x, record[column]); | ||
}, ary[0][column]); | ||
}; | ||
Selector.prototype.avg = function (column) { | ||
var self = this; | ||
var ary = this.select(); | ||
var sum = ary.reduce(function (x, record, ix) { | ||
if (ix === 1) { | ||
return x[column] + record[column]; | ||
} | ||
return x + record[column]; | ||
}); | ||
return sum / ary.length; | ||
}; | ||
function doSort (sort, records) { | ||
@@ -396,0 +442,0 @@ var keys = Object.keys(sort).reverse(); |
{ | ||
"name": "aloof", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "Array of Objects Filtering", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -332,2 +332,20 @@ /* TODO: We need more tests for: | ||
}, | ||
"with() chaining : test max()" : { | ||
fn : function (data) { | ||
return filter.with(data).max('mosquitoBites'); | ||
}, | ||
result : 430 | ||
}, | ||
"with() chaining : test min()" : { | ||
fn : function (data) { | ||
return filter.with(data).min('mosquitoBites'); | ||
}, | ||
result : 98 | ||
}, | ||
"with() chaining : test avg()" : { | ||
fn : function (data) { | ||
return filter.with(data).avg('id'); | ||
}, | ||
result : 2.5 | ||
}, | ||
"with() chaining : test falsy()" : { | ||
@@ -334,0 +352,0 @@ fn : function (data) { |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Non-existent author
Supply chain riskThe package was published by an npm account that no longer exists.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
824069
8
3985
1
6
0
1