@stryke/hash 0.5.1 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,15 +5,15 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.hashDirectory = hashDirectory;
7
7
  exports.hashFiles = hashFiles;
8
- var _promises = require("node:fs/promises");
9
8
  var _listFiles = require("@stryke/fs/files/list-files");
9
+ var _readFile = require("@stryke/fs/files/read-file");
10
10
  var _hash = require("./hash.cjs");
11
- async function hashFiles(r, s) {
11
+ async function hashFiles(i, s) {
12
12
  const t = {};
13
- return await Promise.all(r.map(async i => {
14
- t[i] = await (0, _promises.readFile)(i, "utf8");
13
+ return await Promise.all(i.map(async r => {
14
+ t[r] = await (0, _readFile.readFile)(r);
15
15
  })), (0, _hash.hash)(t, s);
16
16
  }
17
- async function hashDirectory(r, s) {
18
- return hashFiles(await (0, _listFiles.listFiles)(r), s);
17
+ async function hashDirectory(i, s = {}) {
18
+ return s.ignored = s.ignored ?? ["**/node_modules/**", "**/.git/**", "**/.nx/**", "**/.cache/**", "**/tmp/**"], hashFiles(await (0, _listFiles.listFiles)(i, s), s);
19
19
  }
@@ -1,4 +1,6 @@
1
+ import type { ListFilesOptions } from "@stryke/fs/files/list-files";
1
2
  import type { HashOptions } from "./hash";
3
+ export type HashFilesOptions = HashOptions & ListFilesOptions;
2
4
  /**
3
5
  * Hash a list of file paths into a string based on the file content
4
6
  *
@@ -6,12 +8,12 @@ import type { HashOptions } from "./hash";
6
8
  * @param options - Hashing options
7
9
  * @returns A hashed string value
8
10
  */
9
- export declare function hashFiles(files: string[], options?: HashOptions): Promise<string>;
11
+ export declare function hashFiles(files: string[], options?: HashFilesOptions): Promise<string>;
10
12
  /**
11
13
  * Hash a folder path into a string based on the file content
12
14
  *
13
15
  * @param directoryPath - The folder path to hash
14
- * @param options - Hashing options
16
+ * @param options - Hashing options. By default, the `node_modules`, `.git`, `.nx`, `.cache`, and `tmp` folders is ignored.
15
17
  * @returns A hashed string value
16
18
  */
17
- export declare function hashDirectory(directoryPath: string, options?: HashOptions): Promise<string>;
19
+ export declare function hashDirectory(directoryPath: string, options?: HashFilesOptions): Promise<string>;
@@ -1 +1 @@
1
- import{readFile as o}from"node:fs/promises";import{listFiles as a}from"@stryke/fs/files/list-files";import{hash as n}from"./hash";export async function hashFiles(r,s){const t={};return await Promise.all(r.map(async i=>{t[i]=await o(i,"utf8")})),n(t,s)}export async function hashDirectory(r,s){return hashFiles(await a(r),s)}
1
+ import{listFiles as e}from"@stryke/fs/files/list-files";import{readFile as o}from"@stryke/fs/files/read-file";import{hash as n}from"./hash";export async function hashFiles(i,s){const t={};return await Promise.all(i.map(async r=>{t[r]=await o(r)})),n(t,s)}export async function hashDirectory(i,s={}){return s.ignored=s.ignored??["**/node_modules/**","**/.git/**","**/.nx/**","**/.cache/**","**/tmp/**"],hashFiles(await e(i,s),s)}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stryke/hash",
3
- "version": "0.5.1",
3
+ "version": "0.7.0",
4
4
  "type": "module",
5
5
  "description": "A package containing utility functions that hash data using various algorithms.",
6
6
  "repository": {
@@ -11,7 +11,7 @@
11
11
  "private": false,
12
12
  "dependencies": {
13
13
  "js-xxhash": "^4.0.0",
14
- "@stryke/fs": ">=0.5.1",
14
+ "@stryke/fs": ">=0.8.0",
15
15
  "@stryke/types": ">=0.5.1"
16
16
  },
17
17
  "publishConfig": { "access": "public" },