Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

fs-readdir-with-file-types

coderaiser29MIT1.0.2

fs.readdir withFileTypes ponyfill

ponyfill, readdir, withFileTypes, fs

readme

fs-readdir-with-file-types License NPM version Dependency Status Build Status Coverage Status

Node.js v10.11.0 fsPromises.readdir ponyfill of withFileTypes option.

options.withFileTypes is always set to true and result contain objects similar to fs.Dirent.

Install

npm i fs-readdir-with-file-types

API

  • path <string> | <Buffer> | <URL>

Resolves: <fs.Dirent[]>

Example:

const readdir = require('fs-readdir-with-file-types');

async () => {
    await readdirSync('.');
}();

// returns on node v10.10
Dirent { name: 'LICENSE', [Symbol(type)]: 1 },
Dirent { name: 'README.md', [Symbol(type)]: 1 },
Dirent { name: 'index.js', [Symbol(type)]: 1 },

// returns on node < v10.10
{ name: 'LICENSE',
isBlockDevice: [Function: bound ],
isCharacterDevice: [Function: bound ],
isDirectory: [Function: bound ],
isFIFO: [Function: bound ],
isFile: [Function: bound ],
isSocket: [Function: bound ],
isSymbolicLink: [Function: bound ] },

{ name: 'README.md',
isBlockDevice: [Function: bound ],
isCharacterDevice: [Function: bound ],
isDirectory: [Function: bound ],
isFIFO: [Function: bound ],
isFile: [Function: bound ],
isSocket: [Function: bound ],
isSymbolicLink: [Function: bound ] },

{ name: 'index.js',
isBlockDevice: [Function: bound ],
isCharacterDevice: [Function: bound ],
isDirectory: [Function: bound ],
isFIFO: [Function: bound ],
isFile: [Function: bound ],
isSocket: [Function: bound ],
isSymbolicLink: [Function: bound ] }

If you do not want to use promises or async-await use callbackify:

const {callbackify} = require('util');
const readdir = callbackify(require('fs-readdir-with-file-types'));

readdir('.', (e, dirents) => {
    console.log(e, dirents);
});

License

MIT

changelog

2018.10.09, v1.0.2

fix:

  • (index) getDirEnt: name -> path

2018.10.09, v1.0.1

feature:

  • (index) speed up: series -> paralell