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

directory-hash-lock

v0.2.0

Published

Generates lockfile for the given directory

Downloads

11

Readme

Directory Hash Lock

build

directory-hash-lock is a lightweight and easy-to-use npm package for generating a hash of a directory's contents and creating a lock file with that hash. It's useful for detecting changes in the contents of a directory, such as verifying the integrity of files or tracking changes in version control systems.

Features

  • Generate a hash for a directory, including all its files and subdirectories.
  • Filter files included in the hash using wildcard patterns.
  • Create a lock file containing the hash.
  • Uses SHA-256 hashing algorithm by default, but can be configured to use other algorithms supported by the Node.js crypto module.
  • Written in TypeScript with type definitions included.
  • Configurable directory path and file patterns as command-line arguments, defaulting to ./patches and **/* respectively.

Installation

Install the package using npm or yarn as a dev dependency:

npm install --save-dev directory-hash-lock

or

yarn add --dev directory-hash-lock

Usage

--path

Specifies the absolute or relative path to the directory that you want to hash. If no path is provided, it defaults to ./patches.

Example usage:

npm run directory-hash-lock -- --path=/path/to/your/directory

--patterns

Specifies the wildcard patterns to match the files to be included in the hash. Multiple patterns should be comma-separated. If no patterns are provided, it defaults to include all files (**/*).

Example usage:

npm run directory-hash-lock -- --patterns="**/*.txt,**/*.json"

--frozen-lockfile

Prevents the tool from overwriting an existing lock file if its hash differs from the current directory hash. This can be useful if you want to ensure that the contents of the directory haven't changed.

Example usage:

npm run directory-hash-lock -- --frozen-lockfile

All options can be combined as needed. For instance, to hash a specific directory and only include .txt files, without overwriting an existing lock file, you could run:

npm run directory-hash-lock -- --path=/path/to/your/directory --patterns="**/*.txt" --frozen-lockfile

API Documentation

hashDirectory(directoryPath: string, algo: string = 'sha256', patterns: string[] = ['**/*']): Promise

Generates a hash of the files in a directory and its subdirectories.

  • directoryPath: The absolute or relative path to the directory.
  • algo: The algorithm to be used for hashing. Defaults to 'sha256'. Other values can be any algorithm supported by Node.js crypto module.
  • patterns: An array of wildcard patterns to match the files to be included in the hash. Defaults to all files (['**/*']).

Returns a Promise that resolves with a string representing the hexadecimal hash of the directory's contents.

createLockFile(directoryPath: string, lockFilePath: string, patterns: string[] = ['**/*'], frozenLockfile: boolean = false): Promise

Generates a hash of a directory's contents and writes it to a lock file. If the frozenLockfile parameter is set to true, it will not overwrite the existing lock file if its hash differs from the current directory hash.

  • directoryPath: The absolute or relative path to the directory.
  • lockFilePath: The absolute or relative path to the lock file. The lock file will be created if it does not exist.
  • patterns: An array of wildcard patterns to match the files to be included in the hash. Defaults to all files (['**/*']).
  • frozenLockfile: A boolean indicating whether the lock file should be overwritten if the hash differs. Defaults to false.

Returns a Promise that resolves when the lock file has been written.

Repository

For more information, examples, and to contribute to the directory-hash-lock package, please visit the GitHub repository:

https://github.com/bomjkolyadun/directory-hash-lock