@stryke/hash 0.3.0 → 0.5.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.
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.hashDirectory = hashDirectory;
7
+ exports.hashFiles = hashFiles;
8
+ var _promises = require("node:fs/promises");
9
+ var _listFiles = require("@stryke/fs/files/list-files");
10
+ var _hash = require("./hash.cjs");
11
+ async function hashFiles(r, s) {
12
+ const t = {};
13
+ return await Promise.all(r.map(async i => {
14
+ t[i] = await (0, _promises.readFile)(i, "utf8");
15
+ })), (0, _hash.hash)(t, s);
16
+ }
17
+ async function hashDirectory(r, s) {
18
+ return hashFiles(await (0, _listFiles.listFiles)(r), s);
19
+ }
@@ -0,0 +1,17 @@
1
+ import type { HashOptions } from "./hash";
2
+ /**
3
+ * Hash a list of file paths into a string based on the file content
4
+ *
5
+ * @param files - The list of file paths to hash
6
+ * @param options - Hashing options
7
+ * @returns A hashed string value
8
+ */
9
+ export declare function hashFiles(files: string[], options?: HashOptions): Promise<string>;
10
+ /**
11
+ * Hash a folder path into a string based on the file content
12
+ *
13
+ * @param directoryPath - The folder path to hash
14
+ * @param options - Hashing options
15
+ * @returns A hashed string value
16
+ */
17
+ export declare function hashDirectory(directoryPath: string, options?: HashOptions): Promise<string>;
@@ -0,0 +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)}
package/dist/hash.cjs CHANGED
@@ -7,8 +7,8 @@ exports.hash = hash;
7
7
  var _isString = require("@stryke/types/type-checks/is-string");
8
8
  var _hashObject = require("./hash-object.cjs");
9
9
  var _sha = require("./sha-256.cjs");
10
- function hash(t, s) {
11
- const n = (0, _sha.sha256base64)((0, _isString.isString)(t) ? t : (0, _hashObject.hashObject)(t, s)),
12
- e = s?.maxLength ?? 32;
13
- return n.length > e ? n.slice(0, e) : n;
10
+ function hash(t, e) {
11
+ const s = (0, _sha.sha256base64)((0, _isString.isString)(t) ? t : (0, _hashObject.hashObject)(t, e)),
12
+ n = e?.maxLength ?? 32;
13
+ return s.length > n ? s.slice(0, n) : s;
14
14
  }
package/dist/hash.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { type HashObjectOptions } from "./hash-object";
1
+ import type { HashObjectOptions } from "./hash-object";
2
2
  export interface HashOptions extends HashObjectOptions {
3
3
  /**
4
4
  * The maximum length of the hash
package/dist/hash.mjs CHANGED
@@ -1 +1 @@
1
- import{isString as r}from"@stryke/types/type-checks/is-string";import{hashObject as a}from"./hash-object";import{sha256base64 as h}from"./sha-256";export function hash(t,s){const n=h(r(t)?t:a(t,s)),e=s?.maxLength??32;return n.length>e?n.slice(0,e):n}
1
+ import{isString as r}from"@stryke/types/type-checks/is-string";import{hashObject as h}from"./hash-object";import{sha256base64 as a}from"./sha-256";export function hash(t,e){const s=a(r(t)?t:h(t,e)),n=e?.maxLength??32;return s.length>n?s.slice(0,n):s}
package/dist/index.cjs CHANGED
@@ -14,6 +14,17 @@ Object.keys(_hash).forEach(function (key) {
14
14
  }
15
15
  });
16
16
  });
17
+ var _hashFiles = require("./hash-files.cjs");
18
+ Object.keys(_hashFiles).forEach(function (key) {
19
+ if (key === "default" || key === "__esModule") return;
20
+ if (key in exports && exports[key] === _hashFiles[key]) return;
21
+ Object.defineProperty(exports, key, {
22
+ enumerable: true,
23
+ get: function () {
24
+ return _hashFiles[key];
25
+ }
26
+ });
27
+ });
17
28
  var _sha = require("./sha-256.cjs");
18
29
  Object.keys(_sha).forEach(function (key) {
19
30
  if (key === "default" || key === "__esModule") return;
package/dist/index.d.ts CHANGED
@@ -7,5 +7,6 @@
7
7
  * @packageDocumentation
8
8
  */
9
9
  export * from "./hash";
10
+ export * from "./hash-files";
10
11
  export * from "./sha-256";
11
12
  export * from "./xx-hash";
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- export*from"./hash";export*from"./sha-256";export*from"./xx-hash";
1
+ export*from"./hash";export*from"./hash-files";export*from"./sha-256";export*from"./xx-hash";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stryke/hash",
3
- "version": "0.3.0",
3
+ "version": "0.5.0",
4
4
  "type": "module",
5
5
  "description": "A package containing utility functions that hash data using various algorithms.",
6
6
  "repository": {
@@ -9,7 +9,11 @@
9
9
  "directory": "packages/hash"
10
10
  },
11
11
  "private": false,
12
- "dependencies": { "js-xxhash": "^4.0.0", "@stryke/types": ">=0.4.0" },
12
+ "dependencies": {
13
+ "js-xxhash": "^4.0.0",
14
+ "@stryke/fs": ">=0.5.0",
15
+ "@stryke/types": ">=0.5.0"
16
+ },
13
17
  "publishConfig": { "access": "public" },
14
18
  "devDependencies": {},
15
19
  "sideEffects": false,
@@ -125,6 +129,20 @@
125
129
  "default": "./dist/hash-object.mjs"
126
130
  }
127
131
  },
132
+ "./hash-files": {
133
+ "import": {
134
+ "types": "./dist/hash-files.d.ts",
135
+ "default": "./dist/hash-files.mjs"
136
+ },
137
+ "require": {
138
+ "types": "./dist/hash-files.d.ts",
139
+ "default": "./dist/hash-files.cjs"
140
+ },
141
+ "default": {
142
+ "types": "./dist/hash-files.d.ts",
143
+ "default": "./dist/hash-files.mjs"
144
+ }
145
+ },
128
146
  ".": {
129
147
  "import": { "types": "./dist/index.d.ts", "default": "./dist/index.mjs" },
130
148
  "require": {