Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added siblings

  • Loading branch information...
commit ec044dacd98bb9a357cedf86b7ac2e1e2808bd20 1 parent af7df8e
@tommy351 authored
Showing with 54 additions and 0 deletions.
  1. +54 −0 lib/qfs.js
View
54 lib/qfs.js
@@ -341,6 +341,60 @@ utils.each({
}
}
],
+ siblings: [
+ function(selector, callback){
+ if (utils.isFunction(selector)){
+ callback = selector;
+ selector = null;
+ }
+
+ var _this = this,
+ fn = [];
+
+ this.each(function(){
+ var _this = this;
+
+ fn.push(function(next){
+ _this.parent().children(function(err, files){
+ if (err) return callback(err);
+
+ var siblings = files.not(_this.name()).toArray();
+ next(null, siblings);
+ });
+ });
+ });
+
+ async.parallel(fn, function(err, results){
+ if (err) return callback(err);
+
+ var arr = qfs(utils.merge.apply(null, results));
+
+ if (selector){
+ arr = arr.filter(selector);
+ }
+
+ callback.call(_this, err, arr);
+ });
+
+ return this;
+ },
+ function(selector){
+ var arr = [];
+
+ this.each(function(){
+ var path = this.path(),
+ siblings = this.parent().children().not(this.name()).toArray();
+
+ arr = utils.merge(arr, siblings);
+ });
+
+ if (selector){
+ return qfs(arr).filter(selector);
+ } else {
+ return qfs(arr);
+ }
+ }
+ ],
mkdir: [
function(name, callback){
var fn = [];
Please sign in to comment.
Something went wrong with that request. Please try again.