npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

readdir-glob

v2.0.1

Published

Recursive fs.readdir with streaming API and glob filtering.

Downloads

33,991,319

Readme

Readdir-Glob

Build Status Coverage Status

Recursive version of fs.readdir wih stream API and glob filtering. Uses the minimatch library to do its matching.

Requirements:

  • 1.x.x requires Node.js 10.0 or later.
  • 2.x.x requires Node.js 14.0 or later.

Performances

Compared to glob, readdir-glob is memory efficient: no matter the file system size, or the number of returned files, the memory usage is constant.

The CPU cost is proportional to the number of files in root folder, minus the number files in options.skip folders.

Advice: For better performances use options.skip to restrict the search as much as possible.

Usage

Install with npm

npm i readdir-glob
const readdirGlob = require('readdir-glob');
const globber = readdirGlob('.', {pattern: '**/*.js'});
globber.on('match', match => {
    // m.relative: relative path of the matched file
    // m.absolute: absolute path of the matched file
    // m.stat: stat of the matched file (only if stat:true option is used)
});
globber.on('error', err => {
    console.error('fatal error', err);
});
globber.on('end', (m) => {
    console.log('done');
});

readdirGlob(root, [options])

  • root {String} Path to be read recursively, default: '.'
  • options {Object} Options, default: {}

Returns a EventEmitter reading given root recursively.

Properties

  • options: The options object passed in.
  • paused: Boolean which is set to true when calling pause().
  • aborted Boolean which is set to true when calling abort(). There is no way at this time to continue a glob search after aborting.

Events

  • match: Every time a match is found, this is emitted with the specific thing that matched.
  • end: When the matching is finished, this is emitted with all the matches found.
  • error: Emitted when an unexpected error is encountered.

Methods

  • pause(): Temporarily stop the search
  • resume(): Resume the search
  • abort(): Stop the search forever

Options

  • pattern: Glob pattern or Array of Glob patterns to match the found files with. A file has to match at least one of the provided patterns to be returned.
  • ignore: Glob pattern or Array of Glob patterns to exclude matches. If a file or a folder matches at least one of the provided patterns, it's not returned. It doesn't prevent files from folder content to be returned. Note: ignore patterns are always in dot:true mode.
  • skip: Glob pattern or Array of Glob patterns to exclude folders. If a folder matches one of the provided patterns, it's not returned, and it's not explored: this prevents any of its children to be returned. Note: skip patterns are always in dot:true mode.
  • mark: Add a / character to directory matches.
  • stat: Set to true to stat all results. This reduces performance.
  • silent: When an unusual error is encountered when attempting to read a directory, a warning will be printed to stderr. Set the silent option to true to suppress these warnings.
  • nodir: Do not match directories, only files.
  • follow: Follow symlinked directories. Note that requires to stat all results, and so reduces performance.

The following options apply only if pattern option is set, and are forwarded to minimatch:

  • dot: Allow pattern to match filenames starting with a period, even if the pattern does not explicitly have a period in that spot.
  • noglobstar: Disable ** matching against multiple folder names.
  • nocase: Perform a case-insensitive match. Note: on case-insensitive filesystems, non-magic patterns will match by default, since stat and readdir will not raise errors.
  • matchBase: Perform a basename-only match if the pattern does not contain any slash characters. That is, *.js would be treated as equivalent to **/*.js, matching all js files in all directories.

References

Unit-test set is based on node-glob tests.