Socket
Socket
Sign inDemoInstall

walkdir

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

walkdir - npm Package Compare versions

Comparing version 0.0.12 to 0.1.0

test.ts

11

package.json
{
"name": "walkdir",
"description": "Find files simply. Walks a directory tree emitting events based on what it finds. Presents a familiar callback/emitter/a+sync interface. Walk a tree of any depth.",
"version": "0.0.12",
"version": "0.1.0",
"author": "Ryan Day <soldair@gmail.com>",

@@ -20,9 +20,12 @@ "keywords": [

"scripts": {
"test": "tape test/*.js"
"test": "tape test/*.js && npm run ts",
"ts": "tsc --noEmit test.ts"
},
"devDependencies": {
"tape": "^4.0.0"
"@types/node": "^10.12.21",
"tape": "^4.0.0",
"typescript": "^3.3.1"
},
"engines": {
"node": ">=0.6.0"
"node": ">=6.0.0"
},

@@ -29,0 +32,0 @@ "license": "MIT",

@@ -39,2 +39,6 @@ [![Build Status](https://secure.travis-ci.org/soldair/node-walkdir.png)](http://travis-ci.org/soldair/node-walkdir)

// async await/promise!
let result = await walk.async('../',{return_object:true})
//result['path'] = {statObject}
```

@@ -68,3 +72,3 @@

- sync only
- walkdir.sync/walkdir.async only

@@ -71,0 +75,0 @@ ```js

@@ -1,3 +0,4 @@

var test = require('tape'),
walkdir = require('../walkdir.js');
var test = require('tape');
var walkdir = require('../walkdir.js');
var path = require('path');

@@ -14,54 +15,20 @@ var expectedPaths = {

test('async events',function(t){
var paths = [],
files = [],
dirs = [];
test("can use async method with promise",(t)=>{
if(typeof Promise === 'undefined'){
console.log('cannot use async promise returning methods in runtime without Promise')
return t.end()
}
var emitter = walkdir(__dirname+'/dir/foo',function(path){
//console.log('path: ',path);
paths.push(path.replace(__dirname+'/',''));
});
var p = walkdir.async(path.join(__dirname,'dir'))
emitter.on('directory',function(path,stat){
dirs.push(path.replace(__dirname+'/',''));
});
emitter.on('file',function(path,stat){
//console.log('file: ',path);
files.push(path.replace(__dirname+'/',''));
});
emitter.on('end',function(){
files.forEach(function(v,k){
t.equals(expectedPaths[v],'file','path from file event should be file');
});
var expected = Object.keys(expectedPaths);
t.ok(expected.length == paths.length, 'expected and emitted paths should have the same length');
expected.forEach(function(v,k){
if(expectedPaths[v] == 'file') {
t.ok(files.indexOf(v) > -1,'should have file in files array');
}
});
dirs.forEach(function(v,k){
t.equals(expectedPaths[v],'dir','path from dir event should be dir '+v);
});
expected.forEach(function(v,k){
if(expectedPaths[v] == 'dir') {
t.ok(dirs.indexOf(v) > -1,'should have dir in dirs array');
}
});
expected.forEach(function(v,k){
t.ok(paths.indexOf(v) !== -1,'should have found all expected paths '+v);
});
t.end();
});
});
p.then(function(result){
result = result.map(function(p){
return p.replace(__dirname,'')
})
t.ok(result.indexOf('/dir/symlinks/dir1/dangling-symlink') > -1,'should be a list of found files and have found one in particular')
t.end()
}).catch(function(e){
t.fail(e);
})
})

@@ -11,10 +11,36 @@ var EventEmitter = require('events').EventEmitter,

walkdir.sync = function(path,options,cb){
walkdir.sync = function(path,options,eventHandler){
if(typeof options == 'function') cb = options;
options = options || {};
options.sync = true;
return walkdir(path,options,cb);
return walkdir(path,options,eventHandler);
};
// return promise.
walkdir.async = function(path,options,eventHandler){
return new Promise((resolve,reject)=>{
if(typeof options == 'function') cb = options;
options = options || {};
let emitter = walkdir(path,options,eventHandler)
emitter.on('error',reject)
emitter.on('fail',(path,err)=>{
err.message = 'Error walking": '+path+' '+err.message
if(err) reject(err)
})
let allPaths = {}
emitter.on('path',(path,stat)=>{
if(options.no_return !== true) allPaths[path] = stat;
})
emitter.on('end',()=>{
if(options.no_return !== true){
return resolve(options.return_object?allPaths:Object.keys(allPaths))
}
resolve()
})
})
}
function walkdir(path,options,cb){

@@ -90,3 +116,3 @@

emitter.emit('path', path, stat,depth);
emitter.emit('path', path, stat, depth);

@@ -93,0 +119,0 @@ var i,name;

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc