Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

completed filter and not, add inverse until

  • Loading branch information...
commit 41ad33c93b39a2808ccbc4404c6cbd253691992d 1 parent f9cf686
SkyArrow authored September 03, 2012

Showing 2 changed files with 58 additions and 13 deletions. Show diff stats Hide diff stats

  1. 49  lib/qfs.js
  2. 22  lib/utils.js
49  lib/qfs.js
@@ -132,28 +132,51 @@ qfs.fn.map = function(callback){
132 132
   return this;
133 133
 };
134 134
 
135  
-qfs.fn.filter = function(iterator){
136  
-  if (iterator instanceof qfs){
  135
+var filter = function(iterator){
  136
+  var arr = [];
137 137
 
138  
-  } else if (utils.isRegExp(iterator)){
  138
+  if (utils.isRegExp(iterator)){
  139
+    this.each(function(){
  140
+      var path = this.path();
139 141
 
  142
+      if (path.match(iterator)){
  143
+        arr.push(path);
  144
+      }
  145
+    });
140 146
   } else if (utils.isFunction(iterator)){
141  
-
  147
+    this.each(function(i){
  148
+      var callback = iterator.call(this, i);
  149
+      if (callback){
  150
+        arr.push(this.path());
  151
+      }
  152
+    });
142 153
   } else {
  154
+    var identity = iterator.substring(0, 1);
143 155
 
  156
+    if (identity === '.'){
  157
+      this.each(function(){
  158
+        if (this.ext() === iterator){
  159
+          arr.push(this.path());
  160
+        }
  161
+      });
  162
+    } else {
  163
+      this.each(function(){
  164
+        if (this.name() === iterator){
  165
+          arr.push(this.path());
  166
+        }
  167
+      });
  168
+    }
144 169
   }
145  
-};
146  
-
147  
-qfs.fn.not = function(iterator){
148  
-  if (iterator instanceof qfs){
149 170
 
150  
-  } else if (utils.isRegExp(iterator)){
151  
-
152  
-  } else if (utils.isFunction(iterator)){
  171
+  return arr;
  172
+};
153 173
 
154  
-  } else {
  174
+qfs.fn.filter = function(iterator){
  175
+  return qfs(filter.call(this, iterator));
  176
+};
155 177
 
156  
-  }
  178
+qfs.fn.not = function(iterator){
  179
+  return qfs(utils.inverse(this.toArray(), filter.call(this, iterator)));
157 180
 };
158 181
 
159 182
 utils.each(['stat', 'exists'], function(item){
22  lib/utils.js
@@ -94,4 +94,26 @@ var unique = exports.unique = function(arr){
94 94
   });
95 95
 
96 96
   return result;
  97
+};
  98
+
  99
+var inverse = exports.inverse = function(all, obj){
  100
+  if (isArray(all)){
  101
+    var result = [];
  102
+
  103
+    each(all, function(item){
  104
+      if (inArray(obj, item) === -1){
  105
+        result.push(item);
  106
+      }
  107
+    });
  108
+  } else if (isObject(all)){
  109
+    var result = {};
  110
+
  111
+    each(all, function(value, key){
  112
+      if (!obj.hasOwnProperty(key)){
  113
+        result[key] = value;
  114
+      }
  115
+    });
  116
+  }
  117
+
  118
+  return result;
97 119
 };

0 notes on commit 41ad33c

Please sign in to comment.
Something went wrong with that request. Please try again.