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

@aminzer/dir-diff

v4.0.13

Published

Utility for recursive directory iteration and comparison

Downloads

67

Readme

Overview

NodeJS utility for recursive directory iteration and comparison.

Installation

npm i @aminzer/dir-diff

Usage examples

Directory iteration
const { iterateDirectoryChildren } = require('@aminzer/dir-diff');

await iterateDirectoryChildren('d:/work', (fsEntry) => {
  console.log(`${fsEntry.isFile ? 'File' : 'Directory'} ${fsEntry.relativePath} was found`);
});
Directory comparison
const { compareDirectories } = require('@aminzer/dir-diff');

await compareDirectories('d:/work', 'e:/backups/work', {
  onSourceOnlyEntry: (fsEntry) => {
   console.log(`${fsEntry.isFile ? 'File' : 'Directory'} ${fsEntry.relativePath} exists in the source directory only`);
  },
  onTargetOnlyEntry: (fsEntry) => {
   console.log(`${fsEntry.isFile ? 'File' : 'Directory'} ${fsEntry.relativePath} exists in the target directory only`);
  },
  onDifferentEntries: (sourceFsEntry, targetFsEntry) => {
   console.log(`File ${sourceFsEntry.relativePath} exists in both source and target directories, but with different content`);
  },
});

API

iterateDirectoryChildren

Overview

iterateDirectoryChildren is used for recursive iteration of directory children.

iterateDirectoryChildren(dirPath, onEachChild);
Parameters
  • dirPath (string, required) - path to the directory which children should be iterated.
  • onEachChild (function, required) - callback that is called for each child file and directory.

onEachChild callback accepts following arguments:

  • fsEntry (FsEntry) - currently iterated child file or directory.
  • additionalArgs (object, optional) - additional callback arguments:
    • skipEntryChildrenIteration (function) - if this function is called within onEachChild function then iteration of entry children will be skipped.
Return value

Promise that becomes fulfilled when directory children iteration is completed.

compareDirectories

Overview

compareDirectories is used for recursive comparison of 2 directories.

compareDirectories(sourceDirPath, targetDirPath, opts)
Parameters
  • sourceDirPath (string, required) - path to the source directory.
  • targetDirPath (string, required) - path to the target directory.
  • opts (object, optional) - additional options to pass:
    • onSourceOnlyEntry (function, null by default) - function that is called for files and directories that are present in source directory, but are missing in target directory. Corresponding FsEntry instance is passed as parameter.
    • onTargetOnlyEntry (function, null by default) - function that is called for files and directories that are missing in source directory, but are present in target directory. Corresponding FsEntry instance is passed as parameter.
    • onDifferentEntries (function, null by default) - function that is called for files that are present in both source and target directories but have different content. Corresponding FsEntry instances are passed as parameters.
    • onEachEntry (function, null by default) - function that is called for all files and directories from both source and target directories. Corresponding FsEntry instance is passed as parameter.
    • skipContentComparison (boolean, false by default) - files are compared by size only. Content comparison is skipped. It speeds up execution by avoiding "expensive" content-comparison process for large files.
    • skipExcessNestedIterations (boolean, false by default) - children of source-only and target-only directories are not considered. It speeds up execution by avoiding recursive calls for such directories.
Return value

Promise that becomes fulfilled when directory comparison is completed.

FsEntry

Overview

FsEntry - class representing File System Entry (file or directory).

const { FsEntry } =  require('@aminzer/dir-diff');

Instance properties:

  • name (string) - name of entry.
  • absolutePath (string) - absolute path to entry.
  • relativePath (string) - relative path to entry. It's relative to source directory for source entries and relative to target directory for target entries.
  • size (number) - size of file in bytes, 0 for directories.
  • isFile (boolean) - true if entry is file.
  • isDirectory (boolean) - true if entry is directory.

Command line tool

@aminzer/dir-diff-cli