Permalink
Browse files

Merge git://github.com/dvv/rql

  • Loading branch information...
2 parents 736c7a0 + b888e48 commit e66e36aa0e8736880aa1a9ff2c7fa609a7af5b10 @kriszyp committed Jul 29, 2010
Showing with 15 additions and 8 deletions.
  1. +7 −5 lib/js-array.js
  2. +7 −2 lib/query.js
  3. +1 −1 package.json
View
12 lib/js-array.js
@@ -1,7 +1,7 @@
/*
* An implementation of RQL for JavaScript arrays. For example:
* require("./js-array").query("a=3", {}, [{a:1},{a:3}]) -> [{a:3}]
- *
+ *
*/
var parseQuery = require("./parser").parseQuery;
@@ -70,10 +70,11 @@ exports.operators = {
},
select: function(){
var args = arguments;
+ var argc = arguments.length;
return this.map(function(object){
var selected = {};
- for(var i = 0; i < args.length; i++){
- var propertyName= args[i];
+ for(var i = 0; i < argc; i++){
+ var propertyName = args[i];
if(object.hasOwnProperty(propertyName)){
selected[propertyName] = object[propertyName];
}
@@ -88,10 +89,11 @@ exports.operators = {
});
}
var args = arguments;
+ var argc = arguments.length;
return this.map(function(object){
var selected = [];
- for(var i = 0; i < args.length; i++){
- var propertyName= args[i];
+ for(var i = 0; i < argc; i++){
+ var propertyName = args[i];
selected.push(object[propertyName]);
}
return selected;
View
9 lib/query.js
@@ -6,8 +6,8 @@
* require("./js-array").query(query, params, data); // if we want to operate on an array
* };
* query.eq("a", 3).le("b", 4).forEach(function(object){
- * // for each object that matches the query
- * });
+ * // for each object that matches the query
+ * });
*/
try{
@@ -74,6 +74,11 @@ exports.encodeValue = function(val) {
val.toISOString && val.toISOString() || val.toString()
))) {
var type = typeof val;
+ if(val instanceof RegExp){
+ type = "re";
+ val = val.toString();
+ val = val.substr(1, val.length-2);
+ }
if(type === "object"){
type = "epoch";
val = val.getTime();
View
2 package.json
@@ -1,7 +1,7 @@
{
"name": "rql",
"author": "Kris Zyp",
- "contributors": [],
+ "contributors": ["Vladimir Dronnikov <dronnikov@gmail.com>"],
"keywords": [
"resource",
"query",

0 comments on commit e66e36a

Please sign in to comment.