@justinc/dirs
read directory names given path:string or path:string[]
Last updated 4 years ago by justinc .
ISC · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @justinc/dirs 
SYNC missed versions from official npm registry.

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'] }
});

Current Tags

  • 1.0.0                                ...           latest (4 years ago)

1 Versions

  • 1.0.0                                ...           4 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 2
Last Month 2
Dependencies (1)
Dev Dependencies (4)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |