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

recur-fs

v2.2.4

Published

A collection of recursive filesystem utilities

Downloads

515

Readme

NPM Version Build Status

A collection of recursive filesystem utilities.

Installation

npm install recur-fs

Usage

var fs = require('recur-fs');

// Gather all nested files and directories
fs.readdir('/some/directory', function(err, resources) {
  // Do something with 'resources'
});

API

readdir(directory, visitor(resource, stat, next), fn(err, resources)) Recursively read contents of directory, returning all resources. visitor is an optional function called on each resource. Calling next(false) from visitor will exclude resource from the collection.

fs.readdir('/some/directory', function (err, resources) {
  // Do something with 'resources'
});

fs.readdir('/some/other/directory', function (resource, stat, next) {
  // Return 'false' to skip adding to 'resources'
  next(stat.isFile());
}, function(err, resources) {
  // Do something with 'resources'
});

readdir.sync(directory, visitor(resource, stat)) Synchronously, recursively read contents of directory, returning all resources. visitor is an optional function called on each resource. Returning false from visitor will exclude resource from the collection.

var resources = fs.readdir.sync('/some/directory');

var files = fs.readdir.sync('/some/other/directory', function (resource, stat) {
  // Return 'false' to skip adding to 'resources'
  return stat.isFile();
});

walk(directory, visitor(resource, stat, next), fn(err)) Walk up filesystem tree from directory, passing all resources to visitor, and stopping when root directory is reached. Calling next(true) will abort walking before completion.

fs.walk('/some/directory', function (resource, stat, next) {
  // Return 'true' to stop walking
  next(resource == 'index.js');
}, function (err) {
  // Handle error
});

walk.sync(directory, visitor(resource, stat)) Synchronously walk up filesystem tree from directory, passing all resources to visitor, and stopping when root directory is reached, or visitor returns true.

fs.walk.sync('/some/directory', function (resource, stat) {
  // Do something with resource
});

hunt(directory, matcher(resource, stat, next), stopOnFirstMatch, fn(err, matches)) Walk up filesystem tree from directory, returning all resources matched with matcher, and stopping when root directory is reached, or after first match if stopOnFirstMatch=true.

matcher can be a glob-type string (see minimatch), or function calling next(true) to signal a match. In addition, next also accepts a second argument in order to abort before completion.

fs.hunt('/some/directory', '*.js', false, function (err, matches) {
  // Do something with matching js files
});

fs.hunt('/some/directory', '*.css', true, function (err, match) {
  // Do something with single matching css file
});

fs.hunt('/some/other/directory', function (resource, stat, next) {
  if (resource == 'index.js') {
    // Return second argument to stop walking
    next(true, true);
  } else {
    next(false);
  }
}, false, function (err, matches) {
  // Do something with matches
});

hunt.sync(directory, matcher(resource, stat), stopOnFirstMatch) Synchronously walk up filesystem tree from directory, returning all resources matched with matcher, and stopping when root directory is reached, or after first match if stopOnFirstMatch=true.

matcher can be a glob-type string (see minimatch), or function returning true to signal a match.

var jsFiles = fs.hunt.sync('/some/directory', '*.js', false);

var cssFile = fs.hunt.sync('/some/directory', '*.css', true);

var index = fs.hunt.sync('/some/other/directory', function (resource, stat) {
  return (resource == 'index.js');
}, true);

cp(source, destination, force, fn(err, filepath)) Recursively copy source to destination (cp -r). Copies contents of source directory if path contains a trailing /. force=true will overwrite destination if it already exists.

fs.cp('/some/file', '/some/destination', true, function(err, filepath) {
  // Do something with new 'filepath'
});

// Copy directory contents (note trailing slash)
fs.cp('/some/directory/contents/', '/some/destination', true, function(err, filepath) {
  // Do something with new 'filepath'
});

cp.sync(source, destination, force) Synchronously, recursively copy source to destination (cp -r). Copies contents of source directory if path contains a trailing /. force=true will overwrite destination if it already exists.

var filepath = fs.cp('/some/file', '/some/destination', true);

mkdir(directory, fn(err)) Recursively create nested directory (mkdir -p). If directory looks like a filepath (has .extension), directories will be created at path.dirname(directory).

fs.mkdir('/some/directory', function(err) {
  // Do something
});

mkdir.sync(directory) Synchronously, recursively create nested directory (mkdir -p). If directory looks like a filepath (has .extension), directories will be created at path.dirname(directory).

fs.mkdir.sync('/some/directory');

mv(source, destination, force, fn(err, filepath)) Move source to destination, including all contents of source if directory. force=true will overwrite destination if it already exists.

fs.mv('/some/file', '/some/destination', function(err, filepath) {
  // Do something with new 'filepath'
});

mv.sync(source, destination, force) Synchronously move source to destination, including all contents of source if directory. force=true will overwrite destination if it already exists.

fs.mv.sync('/some/file', '/some/destination');

rm(source, fn(err)) Recursively remove source (rm -rf). Prevents removal of resources outside of process.cwd().

fs.rm('/some/directory/and/children', function(err) {
  // Do something when complete
});

rm.sync(source) Synchronously, recursively remove source (rm -rf). Prevents removal of resources outside of process.cwd().

fs.rm.sync('/some/directory/and/children');

indir(directory, filepath) Check that filepath is likely child of directory. NOTE: only makes string comparison.

fs.indir('/some/directory', '/some/directory/file');