Permalink
Browse files

normalize()

  • Loading branch information...
1 parent c7c3d0d commit 737f467f77158b0617adfea1576c1f85c2a49a15 @dvv dvv committed Nov 30, 2010
Showing with 8 additions and 2 deletions.
  1. +8 −2 lib/query.js
View
@@ -180,22 +180,28 @@ Query.prototype.normalize = function(options){
select: [],
values: false
};
+ var plusMinus = {
+ // [plus, minus]
+ sort: [1, -1],
+ select: [1, 0]
+ };
function normal(func, args){
// cache some parameters
if (func === 'sort' || func === 'select') {
result[func] = args;
+ var pm = plusMinus[func];
result[func+'Arr'] = result[func].map(function(x){
if (x instanceof Array) x = x.join('.');
var o = {};
var a = /([-+]*)(.+)/.exec(x);
- o[a[2]] = a[1].charAt(0) === '-' ? -1 : 1;
+ o[a[2]] = pm[(a[1].charAt(0) === '-')*1];
return o;
});
result[func+'Obj'] = {};
result[func].forEach(function(x){
if (x instanceof Array) x = x.join('.');
var a = /([-+]*)(.+)/.exec(x);
- result[func+'Obj'][a[2]] = a[1].charAt(0) === '-' ? -1 : 1;
+ result[func+'Obj'][a[2]] = pm[(a[1].charAt(0) === '-')*1];
});
} else if (func === 'limit') {
// validate limit() args to be numbers, with sane defaults

0 comments on commit 737f467

Please sign in to comment.