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

fs-crawl

v0.3.0

Published

File system operations utilities that calls your functions on different events for more versatility.

Downloads

4

Readme

fs-crawl

File system operations utilities for node.js that calls your functions on different events for more versatility.

API

The motivation for fs-crawl's API is to be able to run callback functions when crawling a directory in an asynchronous and promised fashion.

fs-crawl uses this model to, for example, create an entire directory structure from an object:

const myDirectoryObj = {
  'daddyFolder': {
    'child.txt': null,  
    'child2.txt': null,
    'childDir1': {
      'grandChild.txt': null
    },
    'childDir2': {}
  },
  'uncleFolder': {},
}

Notice fs-crawl expects the following:

  • file names must point to null
  • a key pointing to an empty object means that key specifies an empty directory

Storing the fs-crawl export in a variable called crawl, and specifying a destination called intoDirPath, we turn our object into a directory using crawl.objToDir:

crawl.objToDir(myDirectoryObj, intoDirPath);

In this case crawl.objToDir passes two callback functions to another fs-crawl utility crawl.crawlDirObj that visits our entire myDirectoryObj running a callback function that creates a file when crawl.crawlDirObj encounters a key that points to null, and running another callback function that creates a directory when crawl.crawlDirObj encounters a key that points to another object.

All files at a given depth are handled first, then all subdirectories.

Similarly, fs-crawl has the remove() utility that visits a specified absolute path, runs crawl.crawlDir() in this case to visit the contents of that directory rather than the contents of an object, and runs two internal callback functions: one that removes a file when one has been found, and another that removes the directory once its depths have been cleared. Basically, fs-crawl gets to all the files at a certain point in the call stack fist, and into the directories depth-first.

crawl.copyOneToMany(fromPath, destinationsArray) copies the contents inside fromPath into an arbitrary number of destinations listed in destinationsArray. It first runs crawl.dirToObj to obtain a copy of the directory structure as an object (i.e. the opposite of crawl.objToDir), then runs callbacks that copy each directory and file it encounters into each of the destinations.

The pattern of running callback functions when a directory or a file is found allows for easily building composable and ever more powerful file system management tools all while staying within the asynchronous and promises territory.