2.1.1 • Published 5 years ago

lstat-dir v2.1.1

Weekly downloads
177
License
ISC
Repository
github
Last release
5 years ago

lstat-dir

npm version Build Status Coverage Status

Run fs.lstat() for all contents in a given directory

const lstatDir = require('lstat-dir');

(async () => {
  await lstatDir('node_modules/lstat-dir'); /*=> Map {
    '/Users/example/node_modules/lstat-dir/LICENSE' => {mode: 33188, size: 1086, ...},
    '/Users/example/node_modules/lstat-dir/README.md' => {mode: 33188, size: 2060, ...}
    '/Users/example/node_modules/lstat-dir/index.js' => {mode: 33188, size: 124, ...}
    '/Users/example/node_modules/lstat-dir/package.json' => {mode: 33188, size: 922, ...}
  } */
})();

Installation

Use npm.

npm install lstat-dir

API

const lstatDir = require('lstat-dir');

lstatDir(dir, options)

dir: string (directory path)
options: Object (readdir-sorted options)
Return: Promise<Map>

The returned Promise is fulfilled with a Map, whose keys are absolute paths of contents in the directory, and whose values are fs.Stats of contents.

/* my-dir
   ├── file.txt
   ├── symlink => file.txt
   └── tmp
       └── debug.log
*/

(async () => {
  const stats = await lstatDir('my-dir');

  stats instanceof Map; //=> true

  stats.keys(); /*=> MapIterator {
    '/Users/example/my-dir/file.txt',
    '/Users/example/my-dir/symlink',
    '/Users/example/my-dir/tmp'
  } */

  stats.get('/Users/example/my-dir/file.txt').isFile(); //=> true
  stats.get('/Users/example/my-dir/symlink').isSymbolicLink(); //=> true
  stats.get('/Users/example/my-dir/tmp').isDirectory()(); //=> true
})();

Options are directly passed to the underlying readdir-sorted to control the order of keys.

(async() => {
  [...(await lstatDir('/path/dir')).keys()];
  // => ['/path/dir/10.txt', '/path/dir/2.txt', '/path/dir/ä.txt', '/path/dir/z.txt']

  [...(await lstatDir('/path/dir', {
    locale: 'sv',
    numeric: true
  })).keys()];
  //=> ['/path/dir/2.txt', '/path/dir/10.txt', '/path/dir/z.txt', '/path/dir/ä.txt']
})();

License

ISC License © 2017 - 2018 Shinnosuke Watanabe

2.1.1

5 years ago

2.1.0

6 years ago

2.0.2

7 years ago

2.0.1

7 years ago

2.0.0

7 years ago

1.0.0

7 years ago

0.5.0

7 years ago

0.4.0

7 years ago

0.3.0

7 years ago

0.2.0

7 years ago

0.1.0

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago

0.0.0

7 years ago