Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

readdir-glob

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

readdir-glob

Recursive fs.readdir with streaming API and glob filtering.

  • 2.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
6.4M
decreased by-18%
Maintainers
1
Weekly downloads
 
Created

What is readdir-glob?

The readdir-glob npm package is designed to read directories and list files in them, potentially filtering by patterns using glob syntax. It combines the functionality of reading directories recursively (like `fs.readdir` or `fs.readdirSync` but with support for deep traversal) and filtering files using glob patterns, which specify sets of filenames with wildcard characters.

What are readdir-glob's main functionalities?

Reading directories with glob patterns

This feature allows you to read through directories and subdirectories to find files that match a specific glob pattern. In the provided code sample, `readdir-glob` is used to find all JavaScript files (`**/*.js`) in the current directory and its subdirectories. Events like 'match' and 'end' are used to handle the found files and the completion of the directory reading process.

const readdirGlob = require('readdir-glob');
const baseDirectory = '.';
const options = { glob: '**/*.js' };

const globber = readdirGlob(baseDirectory, options);
globber.on('match', function(match) {
  console.log('Matched file:', match);
});
globber.on('end', function() {
  console.log('Finished reading directory.');
});

Filtering with negation patterns

This feature demonstrates how to use negation patterns to exclude certain directories or files from the search. In the example, all JavaScript files are matched except those within any `node_modules` directory. This is particularly useful for node.js projects where you might want to ignore dependencies.

const readdirGlob = require('readdir-glob');
const baseDirectory = '.';
const options = { glob: ['**/*.js', '!**/node_modules/**'] };

const globber = readdirGlob(baseDirectory, options);
globber.on('match', function(match) {
  console.log('Matched file:', match);
});
globber.on('end', function() {
  console.log('Finished reading directory.');
});

Other packages similar to readdir-glob

Keywords

FAQs

Package last updated on 28 Oct 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc