2.1.0 • Published 2 months ago

als-readdir v2.1.0

Weekly downloads
-
License
MIT
Repository
-
Last release
2 months ago

als-readdir

als-readdir is a Node.js module that enhances the functionality of fs.readdir and fs.readdirSync by adding the path property to the Dirent objects returned by these functions. This is particularly useful in Node.js versions prior to v20.10.0, where Dirent objects do not include the path property. Additionally, als-readdir supports custom recursive directory traversal and returns separated lists of files, directories, and any encountered errors.

Features

  • Adds the path property to Dirent objects returned by fs.readdir and fs.readdirSync.
  • Seamlessly integrates with both the synchronous and asynchronous versions of readdir.
  • Ensures compatibility with older versions of Node.js that do not include the path in Dirent.
  • Supports custom recursive
  • returns separated files,directories and errors

Installation

To install the package, use the following command:

npm install als-readdir

Usage

Synchronous Usage

const { readdirSync } = require('als-readdir');
const dirPath = '/path/to/directory';

const {files,dirs,errors} = readdirSync(dirPath, { withFileTypes: true });
files.forEach(file => {
    console.log(file.name, file.path); // `file` now includes a `path` property
});

Asynchronous Usage

const { readdir } = require('als-readdir');
const dirPath = '/path/to/directory';

readdir(dirPath, { withFileTypes: true, recursive: true })
.then(({files,dirs,errors}) => {
    files.forEach(file => {
        console.log(file.name, file.path); // `file` now includes a `path` property
    });
});