@stryke/hash 0.9.7 → 0.11.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.
package/dist/etag.cjs ADDED
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.generateETag = exports.fnv1a52 = void 0;
7
+ const fnv1a52 = t => {
8
+ const i = t.length;
9
+ let o = 0,
10
+ x = 0,
11
+ e = 8997,
12
+ l = 0,
13
+ r = 33826,
14
+ n = 0,
15
+ c = 40164,
16
+ s = 0,
17
+ g = 52210;
18
+ for (; o < i;) e ^= t.charCodeAt(o++), x = e * 435, l = r * 435, n = c * 435, s = g * 435, n += e << 8, s += r << 8, l += x >>> 16, e = x & 65535, n += l >>> 16, r = l & 65535, g = s + (n >>> 16) & 65535, c = n & 65535;
19
+ return (g & 15) * 281474976710656 + c * 4294967296 + r * 65536 + (e ^ g >> 4);
20
+ },
21
+ generateETag = (t, i = !1) => `${(i ? 'W/"' : '"') + fnv1a52(t).toString(36) + t.length.toString(36)}"`;
22
+ exports.generateETag = generateETag;
23
+ exports.fnv1a52 = fnv1a52;
package/dist/etag.d.ts ADDED
@@ -0,0 +1,18 @@
1
+ /**
2
+ * FNV-1a Hash implementation
3
+ *
4
+ * Ported from https://github.com/tjwebb/fnv-plus/blob/master/index.js
5
+ *
6
+ * @remarks
7
+ * Simplified, optimized and add modified for 52 bit, which provides a larger hash space
8
+ * and still making use of Javascript's 53-bit integer space.
9
+ */
10
+ export declare const fnv1a52: (str: string) => number;
11
+ /**
12
+ * Generates an ETag for the given payload.
13
+ *
14
+ * @param payload - The payload to generate an ETag for.
15
+ * @param weak - Whether to generate a weak ETag.
16
+ * @returns The generated ETag.
17
+ */
18
+ export declare const generateETag: (payload: string, weak?: boolean) => string;
package/dist/etag.mjs ADDED
@@ -0,0 +1 @@
1
+ export const fnv1a52=t=>{const i=t.length;let o=0,x=0,e=8997,l=0,r=33826,n=0,c=40164,s=0,g=52210;for(;o<i;)e^=t.charCodeAt(o++),x=e*435,l=r*435,n=c*435,s=g*435,n+=e<<8,s+=r<<8,l+=x>>>16,e=x&65535,n+=l>>>16,r=l&65535,g=s+(n>>>16)&65535,c=n&65535;return(g&15)*281474976710656+c*4294967296+r*65536+(e^g>>4)},generateETag=(t,i=!1)=>`${(i?'W/"':'"')+fnv1a52(t).toString(36)+t.length.toString(36)}"`;
package/dist/hash.d.ts CHANGED
@@ -9,8 +9,8 @@ export interface HashOptions {
9
9
  /**
10
10
  * Hash any JS value into a string
11
11
  *
12
- * @param object - The value to hash
12
+ * @param content - The value to hash
13
13
  * @param options - Hashing options
14
14
  * @returns A hashed string value
15
15
  */
16
- export declare function hash(object: any, options?: HashOptions): string;
16
+ export declare function hash(content: any, options?: HashOptions): string;
package/dist/index.cjs CHANGED
@@ -3,6 +3,17 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ var _etag = require("./etag.cjs");
7
+ Object.keys(_etag).forEach(function (key) {
8
+ if (key === "default" || key === "__esModule") return;
9
+ if (key in exports && exports[key] === _etag[key]) return;
10
+ Object.defineProperty(exports, key, {
11
+ enumerable: true,
12
+ get: function () {
13
+ return _etag[key];
14
+ }
15
+ });
16
+ });
6
17
  var _hash = require("./hash.cjs");
7
18
  Object.keys(_hash).forEach(function (key) {
8
19
  if (key === "default" || key === "__esModule") return;
@@ -25,6 +36,17 @@ Object.keys(_hashFiles).forEach(function (key) {
25
36
  }
26
37
  });
27
38
  });
39
+ var _md = require("./md5.cjs");
40
+ Object.keys(_md).forEach(function (key) {
41
+ if (key === "default" || key === "__esModule") return;
42
+ if (key in exports && exports[key] === _md[key]) return;
43
+ Object.defineProperty(exports, key, {
44
+ enumerable: true,
45
+ get: function () {
46
+ return _md[key];
47
+ }
48
+ });
49
+ });
28
50
  var _sha = require("./sha-256.cjs");
29
51
  Object.keys(_sha).forEach(function (key) {
30
52
  if (key === "default" || key === "__esModule") return;
package/dist/index.d.ts CHANGED
@@ -6,7 +6,9 @@
6
6
  *
7
7
  * @packageDocumentation
8
8
  */
9
+ export * from "./etag";
9
10
  export * from "./hash";
10
11
  export * from "./hash-files";
12
+ export * from "./md5";
11
13
  export * from "./sha-256";
12
14
  export * from "./xx-hash";
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- export*from"./hash";export*from"./hash-files";export*from"./sha-256";export*from"./xx-hash";
1
+ export*from"./etag";export*from"./hash";export*from"./hash-files";export*from"./md5";export*from"./sha-256";export*from"./xx-hash";
package/dist/md5.cjs ADDED
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.md5 = md5;
7
+ var _nodeCrypto = require("node:crypto");
8
+ function md5(e, t = 32) {
9
+ return (0, _nodeCrypto.createHash)("md5").update(e).digest("hex").slice(0, t);
10
+ }
package/dist/md5.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Generate an MD5 hash of the provided content.
3
+ *
4
+ * @param content - The content to hash.
5
+ * @param length - The length of the hash to return.
6
+ * @returns The generated MD5 hash.
7
+ */
8
+ export declare function md5(content: string, length?: number): string;
package/dist/md5.mjs ADDED
@@ -0,0 +1 @@
1
+ import{createHash as r}from"node:crypto";export function md5(e,t=32){return r("md5").update(e).digest("hex").slice(0,t)}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stryke/hash",
3
- "version": "0.9.7",
3
+ "version": "0.11.0",
4
4
  "type": "module",
5
5
  "description": "A package containing utility functions that hash data using various algorithms.",
6
6
  "repository": {
@@ -12,7 +12,7 @@
12
12
  "dependencies": {
13
13
  "js-xxhash": "^4.0.0",
14
14
  "ohash": "^2.0.11",
15
- "@stryke/fs": "^0.21.3"
15
+ "@stryke/fs": "^0.25.0"
16
16
  },
17
17
  "publishConfig": { "access": "public" },
18
18
  "devDependencies": {},
@@ -87,6 +87,11 @@
87
87
  "default": "./dist/sha-256.mjs"
88
88
  }
89
89
  },
90
+ "./md5": {
91
+ "import": { "types": "./dist/md5.d.ts", "default": "./dist/md5.mjs" },
92
+ "require": { "types": "./dist/md5.d.ts", "default": "./dist/md5.cjs" },
93
+ "default": { "types": "./dist/md5.d.ts", "default": "./dist/md5.mjs" }
94
+ },
90
95
  "./index": {
91
96
  "import": { "types": "./dist/index.d.ts", "default": "./dist/index.mjs" },
92
97
  "require": {
@@ -128,6 +133,11 @@
128
133
  "default": "./dist/hash-files.mjs"
129
134
  }
130
135
  },
136
+ "./etag": {
137
+ "import": { "types": "./dist/etag.d.ts", "default": "./dist/etag.mjs" },
138
+ "require": { "types": "./dist/etag.d.ts", "default": "./dist/etag.cjs" },
139
+ "default": { "types": "./dist/etag.d.ts", "default": "./dist/etag.mjs" }
140
+ },
131
141
  ".": {
132
142
  "import": { "types": "./dist/index.d.ts", "default": "./dist/index.mjs" },
133
143
  "require": {
@@ -140,5 +150,6 @@
140
150
  },
141
151
  "main": "./dist/index.cjs",
142
152
  "module": "./dist/index.mjs",
143
- "types": "./dist/index.d.ts"
153
+ "types": "./dist/index.d.ts",
154
+ "gitHead": "3326ca10ce43fd782ffb2fa29d49bf152e1dac05"
144
155
  }