Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

dirs

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dirs - npm Package Compare versions

Comparing version 0.1.0 to 0.1.1

25

.verbrc.md

@@ -18,3 +18,12 @@ # {%= name %} {%= badge("fury") %}

var list = require('{%= name %}');
console.log(list('fixtures'));
// async
list('fixtures', function (err, files) {
if (err) console.log(err);
console.log(files)
});
// sync
var files = list('fixtures');
console.log(files);
```

@@ -30,4 +39,14 @@

var isDir = require('is-directory');
console.log(dirs('fixtures').filter(isDir.sync));
//=> [ 'fixtures/one', 'fixtures/three', 'fixtures/two' ]
// async
list('fixtures', function (err, files) {
if (err) console.log(err);
files = files.filter(isDir);
console.log(files)
//=> [ 'fixtures/one', 'fixtures/three', 'fixtures/two' ]
});
// Sync
console.log(list('fixtures').filter(isDir));
```

@@ -34,0 +53,0 @@

@@ -0,1 +1,8 @@

/*!
* dirs <https://github.com/jonschlinkert/dirs>
*
* Copyright (c) 2014 Jon Schlinkert, contributors.
* Licensed under the MIT License
*/
'use strict';

@@ -6,15 +13,43 @@

var dirs = module.exports = function dirs(dir, cb) {
if (typeof cb !== 'function') {
return dirs.sync(dir);
}
module.exports = function dirs(dir) {
return fs.readdirSync(dir)
.reduce(function(acc, filepath) {
filepath = [dir, filepath].join('/');
if (!dir.length) {
return cb(null, []);
}
if (isDir.sync(filepath)) {
acc = acc.concat(dirs(filepath));
fs.readdir(dir, function (err, files) {
if (err) {
return cb(err);
}
acc.push(filepath);
return acc;
}, []);
var arr = [];
files.forEach(function (filepath) {
filepath = [dir, filepath].join('/');
if (isDir(filepath)) {
arr = arr.concat(dirs(filepath));
}
arr.push(filepath);
});
return cb(null, arr);
});
};
dirs.sync = function dirsSync(dir) {
return fs.readdirSync(dir)
.reduce(function (acc, filepath) {
filepath = [dir, filepath].join('/');
if (isDir(filepath)) {
acc = acc.concat(dirs(filepath));
}
acc.push(filepath);
return acc;
}, []);
};

7

package.json
{
"name": "dirs",
"description": "List directories or files.",
"version": "0.1.0",
"description": "List directories or files, async or sync.",
"version": "0.1.1",
"homepage": "https://github.com/jonschlinkert/dirs",

@@ -31,3 +31,4 @@ "author": {

"dependencies": {
"is-directory": "^0.2.0"
"async": "^0.9.0",
"is-directory": "^0.2.1"
},

@@ -34,0 +35,0 @@ "devDependencies": {

# dirs [![NPM version](https://badge.fury.io/js/dirs.svg)](http://badge.fury.io/js/dirs)
> List directories or files.
> List directories or files, async or sync.

@@ -23,3 +23,12 @@ ## Install

var list = require('dirs');
console.log(list('fixtures'));
// async
list('fixtures', function (err, files) {
if (err) console.log(err);
console.log(files)
});
// sync
var files = list('fixtures');
console.log(files);
```

@@ -35,4 +44,14 @@

var isDir = require('is-directory');
console.log(dirs('fixtures').filter(isDir.sync));
//=> [ 'fixtures/one', 'fixtures/three', 'fixtures/two' ]
// async
list('fixtures', function (err, files) {
if (err) console.log(err);
files = files.filter(isDir);
console.log(files)
//=> [ 'fixtures/one', 'fixtures/three', 'fixtures/two' ]
});
// Sync
console.log(list('fixtures').filter(isDir));
```

@@ -39,0 +58,0 @@

@@ -12,8 +12,6 @@ /*!

var should = require('should');
var isDirectory = require('is-directory');
var isDir = require('is-directory');
var dirs = require('./');
function isDir (fp) {
return isDirectory.sync(fp);
}
function isFile (fp) {

@@ -29,21 +27,53 @@ return !isDir(fp);

describe('dirs', function () {
it('should return an array of directories and files', function (done) {
dirs('fixtures', function (err, files) {
files.should.be.an.array;
assert.equal(files.length > 1, true);
done();
});
});
it('should list directories', function (done) {
dirs('fixtures', function (err, files) {
files = files.filter(isDir);
files.should.be.an.array;
assert.equal(files.length > 1, true);
assert.equal(files.filter(matches(/\.js/)).length === 0, true);
done();
});
});
it('should list files', function (done) {
dirs('fixtures', function (err, files) {
files = files.filter(isFile);
files.should.be.an.array;
assert.equal(files.length > 1, true);
assert.equal(files.filter(matches(/\.js/)).length > 1, true);
done();
});
});
});
describe('dirs sync', function () {
it('should return an array of directories and files', function () {
var actual = dirs('fixtures');
actual.should.be.an.array;
assert.equal(actual.length > 1, true);
var files = dirs('fixtures');
files.should.be.an.array;
assert.equal(files.length > 1, true);
});
it('should list directories', function () {
var actual = dirs('fixtures').filter(isDir);
actual.should.be.an.array;
assert.equal(actual.length > 1, true);
assert.equal(actual.filter(matches(/\.js/)).length === 0, true);
var files = dirs('fixtures').filter(isDir);
files.should.be.an.array;
assert.equal(files.length > 1, true);
assert.equal(files.filter(matches(/\.js/)).length === 0, true);
});
it('should list files', function () {
var actual = dirs('fixtures').filter(isFile);
actual.should.be.an.array;
assert.equal(actual.length > 1, true);
assert.equal(actual.filter(matches(/\.js/)).length > 1, true);
var files = dirs('fixtures').filter(isFile);
files.should.be.an.array;
assert.equal(files.length > 1, true);
assert.equal(files.filter(matches(/\.js/)).length > 1, true);
});
});
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