@justinc/dirs
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

NPM

This package contains:

dirsSync(absPath: string): string[]

dirs(absPath: string, cb: (e: Error, dirNames?: string[]) => any, asyncOpsLimit: number): any

asyncOpsLimit is optional. It controls the number of asynchronous operations when filtering files from directories (since each op requires reading from filesystem and this read is also done asynchronously). Default value is ASYNC_OPS_LIMIT:

var numOfCpus = cpus().length;
const ASYNC_OPS_LIMIT = numOfCpus + Math.floor(numOfCpus / 2);

If you want to get all directories in more than one path:

var async = require('async');
var dirs = require('@justinc/dirs').dirs;
var _ = require('lodash');

var paths = ['/path/1', '/path/2'];
async.map(paths, dirs, (err, allDirs) => {
  // allDirs[0] are all the directories in paths[0] etc…
  // so you can use something like lodash's zipObject to group
  // the output:
  _.zipObject(paths, allDirs);
  // -> { '/path/1': ['dirA', 'dirB'], '/path/2': ['dirC', 'dirD'] }
});

Package Sidebar

Install

npm i @justinc/dirs

Weekly Downloads

2

Version

1.0.0

License

ISC

Last publish

Collaborators

  • justinc