inray 0.0.2 → 0.0.3
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/LICENSE.md +1 -0
- package/README.md +132 -32
- package/dist/caching/mod.d.ts +2 -0
- package/dist/caching/mod.d.ts.map +1 -0
- package/dist/caching/mod.js +2 -0
- package/dist/caching/mod.js.map +1 -0
- package/dist/caching/src/cache.d.ts +89 -0
- package/dist/caching/src/cache.d.ts.map +1 -0
- package/dist/caching/src/cache.js +309 -0
- package/dist/caching/src/cache.js.map +1 -0
- package/dist/caching/src/hashing/cache.d.ts +92 -0
- package/dist/caching/src/hashing/cache.d.ts.map +1 -0
- package/dist/caching/src/hashing/cache.js +119 -0
- package/dist/caching/src/hashing/cache.js.map +1 -0
- package/dist/caching/src/hashing/hooks/eventified.d.ts +157 -0
- package/dist/caching/src/hashing/hooks/eventified.d.ts.map +1 -0
- package/dist/caching/src/hashing/hooks/eventified.js +333 -0
- package/dist/caching/src/hashing/hooks/eventified.js.map +1 -0
- package/dist/caching/src/hashing/hooks/index.d.ts +199 -0
- package/dist/caching/src/hashing/hooks/index.d.ts.map +1 -0
- package/dist/caching/src/hashing/hooks/index.js +383 -0
- package/dist/caching/src/hashing/hooks/index.js.map +1 -0
- package/dist/caching/src/hashing/hooks/types.d.ts +217 -0
- package/dist/caching/src/hashing/hooks/types.d.ts.map +1 -0
- package/dist/caching/src/hashing/hooks/types.js +10 -0
- package/dist/caching/src/hashing/hooks/types.js.map +1 -0
- package/dist/caching/src/hashing/index.d.ts +236 -0
- package/dist/caching/src/hashing/index.d.ts.map +1 -0
- package/dist/caching/src/hashing/index.js +447 -0
- package/dist/caching/src/hashing/index.js.map +1 -0
- package/dist/caching/src/hashing/providers/crc.d.ts +15 -0
- package/dist/caching/src/hashing/providers/crc.d.ts.map +1 -0
- package/dist/caching/src/hashing/providers/crc.js +49 -0
- package/dist/caching/src/hashing/providers/crc.js.map +1 -0
- package/dist/caching/src/hashing/providers/crypto.d.ts +19 -0
- package/dist/caching/src/hashing/providers/crypto.d.ts.map +1 -0
- package/dist/caching/src/hashing/providers/crypto.js +28 -0
- package/dist/caching/src/hashing/providers/crypto.js.map +1 -0
- package/dist/caching/src/hashing/providers/djb2.d.ts +60 -0
- package/dist/caching/src/hashing/providers/djb2.d.ts.map +1 -0
- package/dist/caching/src/hashing/providers/djb2.js +92 -0
- package/dist/caching/src/hashing/providers/djb2.js.map +1 -0
- package/dist/caching/src/hashing/providers/fnv1.d.ts +33 -0
- package/dist/caching/src/hashing/providers/fnv1.d.ts.map +1 -0
- package/dist/caching/src/hashing/providers/fnv1.js +68 -0
- package/dist/caching/src/hashing/providers/fnv1.js.map +1 -0
- package/dist/caching/src/hashing/providers/murmur.d.ts +81 -0
- package/dist/caching/src/hashing/providers/murmur.d.ts.map +1 -0
- package/dist/caching/src/hashing/providers/murmur.js +173 -0
- package/dist/caching/src/hashing/providers/murmur.js.map +1 -0
- package/dist/caching/src/hashing/providers.d.ts +126 -0
- package/dist/caching/src/hashing/providers.d.ts.map +1 -0
- package/dist/caching/src/hashing/providers.js +163 -0
- package/dist/caching/src/hashing/providers.js.map +1 -0
- package/dist/caching/src/hashing/types.d.ts +340 -0
- package/dist/caching/src/hashing/types.d.ts.map +1 -0
- package/dist/caching/src/hashing/types.js +10 -0
- package/dist/caching/src/hashing/types.js.map +1 -0
- package/dist/caching/src/keyValue/capabilities.d.ts +161 -0
- package/dist/caching/src/keyValue/capabilities.d.ts.map +1 -0
- package/dist/caching/src/keyValue/capabilities.js +334 -0
- package/dist/caching/src/keyValue/capabilities.js.map +1 -0
- package/dist/caching/src/keyValue/event-manager.d.ts +27 -0
- package/dist/caching/src/keyValue/event-manager.d.ts.map +1 -0
- package/dist/caching/src/keyValue/event-manager.js +88 -0
- package/dist/caching/src/keyValue/event-manager.js.map +1 -0
- package/dist/caching/src/keyValue/generic-store.d.ts +243 -0
- package/dist/caching/src/keyValue/generic-store.d.ts.map +1 -0
- package/dist/caching/src/keyValue/generic-store.js +295 -0
- package/dist/caching/src/keyValue/generic-store.js.map +1 -0
- package/dist/caching/src/keyValue/hooks-manager.d.ts +21 -0
- package/dist/caching/src/keyValue/hooks-manager.d.ts.map +1 -0
- package/dist/caching/src/keyValue/hooks-manager.js +59 -0
- package/dist/caching/src/keyValue/hooks-manager.js.map +1 -0
- package/dist/caching/src/keyValue/index.d.ts +334 -0
- package/dist/caching/src/keyValue/index.d.ts.map +1 -0
- package/dist/caching/src/keyValue/index.js +796 -0
- package/dist/caching/src/keyValue/index.js.map +1 -0
- package/dist/caching/src/keyValue/serialize/serialize.d.ts +12 -0
- package/dist/caching/src/keyValue/serialize/serialize.d.ts.map +1 -0
- package/dist/caching/src/keyValue/serialize/serialize.js +64 -0
- package/dist/caching/src/keyValue/serialize/serialize.js.map +1 -0
- package/dist/caching/src/keyValue/stats-manager.d.ts +27 -0
- package/dist/caching/src/keyValue/stats-manager.d.ts.map +1 -0
- package/dist/caching/src/keyValue/stats-manager.js +64 -0
- package/dist/caching/src/keyValue/stats-manager.js.map +1 -0
- package/dist/caching/src/keyValue/types.d.ts +22 -0
- package/dist/caching/src/keyValue/types.d.ts.map +1 -0
- package/dist/caching/src/keyValue/types.js +11 -0
- package/dist/caching/src/keyValue/types.js.map +1 -0
- package/dist/caching/src/keyv-adapter.d.ts +40 -0
- package/dist/caching/src/keyv-adapter.d.ts.map +1 -0
- package/dist/caching/src/keyv-adapter.js +56 -0
- package/dist/caching/src/keyv-adapter.js.map +1 -0
- package/dist/caching/src/utils/cache-tags.d.ts +275 -0
- package/dist/caching/src/utils/cache-tags.d.ts.map +1 -0
- package/dist/caching/src/utils/cache-tags.js +407 -0
- package/dist/caching/src/utils/cache-tags.js.map +1 -0
- package/dist/caching/src/utils/cacheable-item-types.d.ts +35 -0
- package/dist/caching/src/utils/cacheable-item-types.d.ts.map +1 -0
- package/dist/caching/src/utils/cacheable-item-types.js +10 -0
- package/dist/caching/src/utils/cacheable-item-types.js.map +1 -0
- package/dist/caching/src/utils/coalesce-async.d.ts +29 -0
- package/dist/caching/src/utils/coalesce-async.d.ts.map +1 -0
- package/dist/caching/src/utils/coalesce-async.js +88 -0
- package/dist/caching/src/utils/coalesce-async.js.map +1 -0
- package/dist/caching/src/utils/hash.d.ts +55 -0
- package/dist/caching/src/utils/hash.d.ts.map +1 -0
- package/dist/caching/src/utils/hash.js +116 -0
- package/dist/caching/src/utils/hash.js.map +1 -0
- package/dist/caching/src/utils/index.d.ts +24 -0
- package/dist/caching/src/utils/index.d.ts.map +1 -0
- package/dist/caching/src/utils/index.js +21 -0
- package/dist/caching/src/utils/index.js.map +1 -0
- package/dist/caching/src/utils/is-keyv-instance.d.ts +10 -0
- package/dist/caching/src/utils/is-keyv-instance.d.ts.map +1 -0
- package/dist/caching/src/utils/is-keyv-instance.js +37 -0
- package/dist/caching/src/utils/is-keyv-instance.js.map +1 -0
- package/dist/caching/src/utils/is-object.d.ts +10 -0
- package/dist/caching/src/utils/is-object.d.ts.map +1 -0
- package/dist/caching/src/utils/is-object.js +13 -0
- package/dist/caching/src/utils/is-object.js.map +1 -0
- package/dist/caching/src/utils/less-than.d.ts +10 -0
- package/dist/caching/src/utils/less-than.d.ts.map +1 -0
- package/dist/caching/src/utils/less-than.js +13 -0
- package/dist/caching/src/utils/less-than.js.map +1 -0
- package/dist/caching/src/utils/memoize.d.ts +107 -0
- package/dist/caching/src/utils/memoize.d.ts.map +1 -0
- package/dist/caching/src/utils/memoize.js +201 -0
- package/dist/caching/src/utils/memoize.js.map +1 -0
- package/dist/caching/src/utils/mock-cacheable.d.ts +28 -0
- package/dist/caching/src/utils/mock-cacheable.d.ts.map +1 -0
- package/dist/caching/src/utils/mock-cacheable.js +87 -0
- package/dist/caching/src/utils/mock-cacheable.js.map +1 -0
- package/dist/caching/src/utils/run-if-fn.d.ts +12 -0
- package/dist/caching/src/utils/run-if-fn.d.ts.map +1 -0
- package/dist/caching/src/utils/run-if-fn.js +12 -0
- package/dist/caching/src/utils/run-if-fn.js.map +1 -0
- package/dist/caching/src/utils/shorthand-time.d.ts +27 -0
- package/dist/caching/src/utils/shorthand-time.d.ts.map +1 -0
- package/dist/caching/src/utils/shorthand-time.js +96 -0
- package/dist/caching/src/utils/shorthand-time.js.map +1 -0
- package/dist/caching/src/utils/sleep.d.ts +10 -0
- package/dist/caching/src/utils/sleep.d.ts.map +1 -0
- package/dist/caching/src/utils/sleep.js +11 -0
- package/dist/caching/src/utils/sleep.js.map +1 -0
- package/dist/caching/src/utils/stats.d.ts +354 -0
- package/dist/caching/src/utils/stats.d.ts.map +1 -0
- package/dist/caching/src/utils/stats.js +593 -0
- package/dist/caching/src/utils/stats.js.map +1 -0
- package/dist/caching/src/utils/ttl.d.ts +58 -0
- package/dist/caching/src/utils/ttl.d.ts.map +1 -0
- package/dist/caching/src/utils/ttl.js +77 -0
- package/dist/caching/src/utils/ttl.js.map +1 -0
- package/package.json +11 -3
|
@@ -0,0 +1,447 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Original library: hashery (v1.5.1)
|
|
3
|
+
* - Copyright (c) 2025 Jared Wray
|
|
4
|
+
*
|
|
5
|
+
* Modified and integrated in "Inray":
|
|
6
|
+
* - Evgeniy Bushin
|
|
7
|
+
*/
|
|
8
|
+
/***/
|
|
9
|
+
import { Hookified } from "./hooks/index.js";
|
|
10
|
+
import { Cache } from "./cache.js";
|
|
11
|
+
import { CRC } from "./providers/crc.js";
|
|
12
|
+
import { WebCrypto } from "./providers/crypto.js";
|
|
13
|
+
import { DJB2 } from "./providers/djb2.js";
|
|
14
|
+
import { FNV1 } from "./providers/fnv1.js";
|
|
15
|
+
import { Murmur } from "./providers/murmur.js";
|
|
16
|
+
import { HashProviders } from "./providers.js";
|
|
17
|
+
export class Hashery extends Hookified {
|
|
18
|
+
_parse = JSON.parse;
|
|
19
|
+
_stringify = JSON.stringify;
|
|
20
|
+
_providers = new HashProviders();
|
|
21
|
+
_defaultAlgorithm = 'SHA-256';
|
|
22
|
+
_defaultAlgorithmSync = 'djb2';
|
|
23
|
+
_cache;
|
|
24
|
+
constructor(options) {
|
|
25
|
+
super(options);
|
|
26
|
+
if (options?.parse) {
|
|
27
|
+
this._parse = options.parse;
|
|
28
|
+
}
|
|
29
|
+
if (options?.stringify) {
|
|
30
|
+
this._stringify = options.stringify;
|
|
31
|
+
}
|
|
32
|
+
if (options?.defaultAlgorithm) {
|
|
33
|
+
this._defaultAlgorithm = options.defaultAlgorithm;
|
|
34
|
+
}
|
|
35
|
+
if (options?.defaultAlgorithmSync) {
|
|
36
|
+
this._defaultAlgorithmSync = options.defaultAlgorithmSync;
|
|
37
|
+
}
|
|
38
|
+
this._cache = new Cache(options?.cache);
|
|
39
|
+
this.loadProviders(options?.providers, {
|
|
40
|
+
includeBase: options?.includeBase ?? true
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Gets the parse function used to deserialize stored values.
|
|
45
|
+
* @returns The current parse function (defaults to JSON.parse)
|
|
46
|
+
*/
|
|
47
|
+
get parse() {
|
|
48
|
+
return this._parse;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Sets the parse function used to deserialize stored values.
|
|
52
|
+
* @param value - The parse function to use for deserialization
|
|
53
|
+
*/
|
|
54
|
+
set parse(value) {
|
|
55
|
+
this._parse = value;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Gets the stringify function used to serialize values for storage.
|
|
59
|
+
* @returns The current stringify function (defaults to JSON.stringify)
|
|
60
|
+
*/
|
|
61
|
+
get stringify() {
|
|
62
|
+
return this._stringify;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Sets the stringify function used to serialize values for storage.
|
|
66
|
+
* @param value - The stringify function to use for serialization
|
|
67
|
+
*/
|
|
68
|
+
set stringify(value) {
|
|
69
|
+
this._stringify = value;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Gets the HashProviders instance used to manage hash providers.
|
|
73
|
+
* @returns The current HashProviders instance
|
|
74
|
+
*/
|
|
75
|
+
get providers() {
|
|
76
|
+
return this._providers;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Sets the HashProviders instance used to manage hash providers.
|
|
80
|
+
* @param value - The HashProviders instance to use
|
|
81
|
+
*/
|
|
82
|
+
set providers(value) {
|
|
83
|
+
this._providers = value;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Gets the names of all registered hash algorithm providers.
|
|
87
|
+
* @returns An array of provider names (e.g., ['SHA-256', 'SHA-384', 'SHA-512'])
|
|
88
|
+
*/
|
|
89
|
+
get names() {
|
|
90
|
+
return this._providers.names;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Gets the default hash algorithm used when none is specified.
|
|
94
|
+
* @returns The current default algorithm (defaults to 'SHA-256')
|
|
95
|
+
*/
|
|
96
|
+
get defaultAlgorithm() {
|
|
97
|
+
return this._defaultAlgorithm;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Sets the default hash algorithm to use when none is specified.
|
|
101
|
+
* @param value - The default algorithm to use (e.g., 'SHA-256', 'SHA-512', 'djb2')
|
|
102
|
+
* @example
|
|
103
|
+
* ```ts
|
|
104
|
+
* const hashery = new Hashery();
|
|
105
|
+
* hashery.defaultAlgorithm = 'SHA-512';
|
|
106
|
+
*
|
|
107
|
+
* // Now toHash will use SHA-512 by default
|
|
108
|
+
* const hash = await hashery.toHash({ data: 'example' });
|
|
109
|
+
* ```
|
|
110
|
+
*/
|
|
111
|
+
set defaultAlgorithm(value) {
|
|
112
|
+
this._defaultAlgorithm = value;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Gets the default synchronous hash algorithm used when none is specified.
|
|
116
|
+
* @returns The current default synchronous algorithm (defaults to 'djb2')
|
|
117
|
+
*/
|
|
118
|
+
get defaultAlgorithmSync() {
|
|
119
|
+
return this._defaultAlgorithmSync;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Sets the default synchronous hash algorithm to use when none is specified.
|
|
123
|
+
* @param value - The default synchronous algorithm to use (e.g., 'djb2', 'fnv1', 'murmur', 'crc32')
|
|
124
|
+
* @example
|
|
125
|
+
* ```ts
|
|
126
|
+
* const hashery = new Hashery();
|
|
127
|
+
* hashery.defaultAlgorithmSync = 'fnv1';
|
|
128
|
+
*
|
|
129
|
+
* // Now synchronous operations will use fnv1 by default
|
|
130
|
+
* ```
|
|
131
|
+
*/
|
|
132
|
+
set defaultAlgorithmSync(value) {
|
|
133
|
+
this._defaultAlgorithmSync = value;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Gets the cache instance used to store computed hash values.
|
|
137
|
+
* @returns The Cache instance
|
|
138
|
+
* @example
|
|
139
|
+
* ```ts
|
|
140
|
+
* const hashery = new Hashery({ cache: { enabled: true } });
|
|
141
|
+
*
|
|
142
|
+
* // Access the cache
|
|
143
|
+
* hashery.cache.enabled; // true
|
|
144
|
+
* hashery.cache.size; // number of cached items
|
|
145
|
+
* hashery.cache.clear(); // clear all cached items
|
|
146
|
+
* ```
|
|
147
|
+
*/
|
|
148
|
+
get cache() {
|
|
149
|
+
return this._cache;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Generates a cryptographic hash of the provided data using the Web Crypto API.
|
|
153
|
+
* The data is first stringified using the configured stringify function, then hashed.
|
|
154
|
+
*
|
|
155
|
+
* If an invalid algorithm is provided, a 'warn' event is emitted and the method falls back
|
|
156
|
+
* to the default algorithm. You can listen to these warnings:
|
|
157
|
+
* ```ts
|
|
158
|
+
* hashery.on('warn', (message) => console.log(message));
|
|
159
|
+
* ```
|
|
160
|
+
*
|
|
161
|
+
* @param data - The data to hash (will be stringified before hashing)
|
|
162
|
+
* @param options - Optional configuration object
|
|
163
|
+
* @param options.algorithm - The hash algorithm to use (defaults to 'SHA-256')
|
|
164
|
+
* @param options.maxLength - Optional maximum length for the hash output
|
|
165
|
+
* @returns A Promise that resolves to the hexadecimal string representation of the hash
|
|
166
|
+
*
|
|
167
|
+
* @example
|
|
168
|
+
* ```ts
|
|
169
|
+
* const hashery = new Hashery();
|
|
170
|
+
* const hash = await hashery.toHash({ name: 'John', age: 30 });
|
|
171
|
+
* console.log(hash); // "a1b2c3d4..."
|
|
172
|
+
*
|
|
173
|
+
* // Using a different algorithm
|
|
174
|
+
* const hash512 = await hashery.toHash({ name: 'John' }, { algorithm: 'SHA-512' });
|
|
175
|
+
* ```
|
|
176
|
+
*/
|
|
177
|
+
async toHash(data, options) {
|
|
178
|
+
// Before hook - allows modification of input data and algorithm
|
|
179
|
+
const context = {
|
|
180
|
+
data,
|
|
181
|
+
algorithm: options?.algorithm ?? this._defaultAlgorithm,
|
|
182
|
+
maxLength: options?.maxLength
|
|
183
|
+
};
|
|
184
|
+
await this.beforeHook('toHash', context);
|
|
185
|
+
// Stringify the data using the configured stringify function
|
|
186
|
+
const stringified = this._stringify(context.data);
|
|
187
|
+
// Check cache first
|
|
188
|
+
const cacheKey = `${context.algorithm}:${stringified}`;
|
|
189
|
+
if (this._cache.enabled) {
|
|
190
|
+
const cached = this._cache.get(cacheKey);
|
|
191
|
+
if (cached !== undefined) {
|
|
192
|
+
let cachedHash = cached;
|
|
193
|
+
// Apply maxLength if specified
|
|
194
|
+
if (options?.maxLength && cachedHash.length > options.maxLength) {
|
|
195
|
+
cachedHash = cachedHash.substring(0, options.maxLength);
|
|
196
|
+
}
|
|
197
|
+
// After hook - run even on cache hits for consistent behavior
|
|
198
|
+
const result = {
|
|
199
|
+
hash: cachedHash,
|
|
200
|
+
data: context.data,
|
|
201
|
+
algorithm: context.algorithm
|
|
202
|
+
};
|
|
203
|
+
await this.afterHook('toHash', result);
|
|
204
|
+
return result.hash;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
// Convert the string to a Uint8Array
|
|
208
|
+
const encoder = new TextEncoder();
|
|
209
|
+
const dataBuffer = encoder.encode(stringified);
|
|
210
|
+
// Get the provider for the specified algorithm
|
|
211
|
+
let provider = this._providers.get(context.algorithm);
|
|
212
|
+
if (!provider) {
|
|
213
|
+
// Emit warning for invalid algorithm
|
|
214
|
+
this.emit('warn', `Invalid algorithm '${context.algorithm}' not found. Falling back to default algorithm '${this._defaultAlgorithm}'.`);
|
|
215
|
+
provider = new WebCrypto({
|
|
216
|
+
algorithm: this._defaultAlgorithm
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
// Use the provider to hash the data
|
|
220
|
+
let hash = await provider.toHash(dataBuffer);
|
|
221
|
+
// Store the full hash in cache before truncation
|
|
222
|
+
if (this._cache.enabled) {
|
|
223
|
+
this._cache.set(cacheKey, hash);
|
|
224
|
+
}
|
|
225
|
+
// if there is a max then change the hash
|
|
226
|
+
if (options?.maxLength && hash.length > options?.maxLength) {
|
|
227
|
+
hash = hash.substring(0, options.maxLength);
|
|
228
|
+
}
|
|
229
|
+
// After hook - allows modification/logging of result
|
|
230
|
+
const result = { hash, data: context.data, algorithm: context.algorithm };
|
|
231
|
+
await this.afterHook('toHash', result);
|
|
232
|
+
return result.hash;
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Generates a deterministic number within a specified range based on the hash of the provided data.
|
|
236
|
+
* This method uses the toHash function to create a consistent hash, then maps it to a number
|
|
237
|
+
* between min and max (inclusive).
|
|
238
|
+
*
|
|
239
|
+
* @param data - The data to hash (will be stringified before hashing)
|
|
240
|
+
* @param options - Configuration options (optional, defaults to min: 0, max: 100)
|
|
241
|
+
* @param options.min - The minimum value of the range (inclusive, defaults to 0)
|
|
242
|
+
* @param options.max - The maximum value of the range (inclusive, defaults to 100)
|
|
243
|
+
* @param options.algorithm - The hash algorithm to use (defaults to 'SHA-256')
|
|
244
|
+
* @param options.hashLength - Number of characters from hash to use for conversion (defaults to 16)
|
|
245
|
+
* @returns A Promise that resolves to a number between min and max (inclusive)
|
|
246
|
+
*
|
|
247
|
+
* @example
|
|
248
|
+
* ```ts
|
|
249
|
+
* const hashery = new Hashery();
|
|
250
|
+
* const num = await hashery.toNumber({ user: 'john' }); // Uses default min: 0, max: 100
|
|
251
|
+
* console.log(num); // Always returns the same number for the same input, e.g., 42
|
|
252
|
+
*
|
|
253
|
+
* // Using custom range
|
|
254
|
+
* const num2 = await hashery.toNumber({ user: 'john' }, { min: 1, max: 100 });
|
|
255
|
+
*
|
|
256
|
+
* // Using a different algorithm
|
|
257
|
+
* const num512 = await hashery.toNumber({ user: 'john' }, { min: 0, max: 255, algorithm: 'SHA-512' });
|
|
258
|
+
* ```
|
|
259
|
+
*/
|
|
260
|
+
async toNumber(data, options = {}) {
|
|
261
|
+
const { min = 0, max = 100, algorithm = this._defaultAlgorithm, hashLength = 16 } = options;
|
|
262
|
+
if (min > max) {
|
|
263
|
+
throw new Error('min cannot be greater than max');
|
|
264
|
+
}
|
|
265
|
+
// Get the hash as a hex string
|
|
266
|
+
// Take the first hashLength characters of the hash to convert to a number
|
|
267
|
+
// This provides good distribution while avoiding precision issues with JavaScript numbers
|
|
268
|
+
const hash = await this.toHash(data, { algorithm, maxLength: hashLength });
|
|
269
|
+
// Convert hex to a number
|
|
270
|
+
const hashNumber = Number.parseInt(hash, 16);
|
|
271
|
+
// Map the hash number to the desired range
|
|
272
|
+
const range = max - min + 1;
|
|
273
|
+
const mapped = min + (hashNumber % range);
|
|
274
|
+
return mapped;
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Generates a hash of the provided data synchronously using a non-cryptographic hash algorithm.
|
|
278
|
+
* The data is first stringified using the configured stringify function, then hashed.
|
|
279
|
+
*
|
|
280
|
+
* Note: This method only works with synchronous hash providers (djb2, fnv1, murmur, crc32).
|
|
281
|
+
* WebCrypto algorithms (SHA-256, SHA-384, SHA-512) are not supported and will throw an error.
|
|
282
|
+
*
|
|
283
|
+
* If an invalid algorithm is provided, a 'warn' event is emitted and the method falls back
|
|
284
|
+
* to the default synchronous algorithm. You can listen to these warnings:
|
|
285
|
+
* ```ts
|
|
286
|
+
* hashery.on('warn', (message) => console.log(message));
|
|
287
|
+
* ```
|
|
288
|
+
*
|
|
289
|
+
* @param data - The data to hash (will be stringified before hashing)
|
|
290
|
+
* @param options - Optional configuration object
|
|
291
|
+
* @param options.algorithm - The hash algorithm to use (defaults to 'djb2')
|
|
292
|
+
* @param options.maxLength - Optional maximum length for the hash output
|
|
293
|
+
* @returns The hexadecimal string representation of the hash
|
|
294
|
+
*
|
|
295
|
+
* @throws {Error} If the specified algorithm does not support synchronous hashing
|
|
296
|
+
* @throws {Error} If the default algorithm is not found
|
|
297
|
+
*
|
|
298
|
+
* @example
|
|
299
|
+
* ```ts
|
|
300
|
+
* const hashery = new Hashery();
|
|
301
|
+
* const hash = hashery.toHashSync({ name: 'John', age: 30 });
|
|
302
|
+
* console.log(hash); // "7c9df5ea..." (djb2 hash)
|
|
303
|
+
*
|
|
304
|
+
* // Using a different algorithm
|
|
305
|
+
* const hashFnv1 = hashery.toHashSync({ name: 'John' }, { algorithm: 'fnv1' });
|
|
306
|
+
* ```
|
|
307
|
+
*/
|
|
308
|
+
toHashSync(data, options) {
|
|
309
|
+
// Before hook - allows modification of input data and algorithm (synchronous/blocking)
|
|
310
|
+
const context = {
|
|
311
|
+
data,
|
|
312
|
+
algorithm: options?.algorithm ?? this._defaultAlgorithmSync,
|
|
313
|
+
maxLength: options?.maxLength
|
|
314
|
+
};
|
|
315
|
+
this.hookSync('before:toHashSync', context);
|
|
316
|
+
// Get algorithm from context (may have been modified by hook)
|
|
317
|
+
const algorithm = context.algorithm;
|
|
318
|
+
// Stringify the data using the configured stringify function
|
|
319
|
+
const stringified = this._stringify(context.data);
|
|
320
|
+
// Check cache first
|
|
321
|
+
const cacheKey = `${algorithm}:${stringified}`;
|
|
322
|
+
if (this._cache.enabled) {
|
|
323
|
+
const cached = this._cache.get(cacheKey);
|
|
324
|
+
if (cached !== undefined) {
|
|
325
|
+
let cachedHash = cached;
|
|
326
|
+
// Apply maxLength if specified
|
|
327
|
+
if (options?.maxLength && cachedHash.length > options.maxLength) {
|
|
328
|
+
cachedHash = cachedHash.substring(0, options.maxLength);
|
|
329
|
+
}
|
|
330
|
+
// After hook - run even on cache hits for consistent behavior
|
|
331
|
+
const result = {
|
|
332
|
+
hash: cachedHash,
|
|
333
|
+
data: context.data,
|
|
334
|
+
algorithm
|
|
335
|
+
};
|
|
336
|
+
this.hookSync('after:toHashSync', result);
|
|
337
|
+
return result.hash;
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
// Convert the string to a Uint8Array
|
|
341
|
+
const encoder = new TextEncoder();
|
|
342
|
+
const dataBuffer = encoder.encode(stringified);
|
|
343
|
+
// Get the provider for the specified algorithm
|
|
344
|
+
let provider = this._providers.get(algorithm);
|
|
345
|
+
if (!provider) {
|
|
346
|
+
// Emit warning for invalid algorithm
|
|
347
|
+
this.emit('warn', `Invalid algorithm '${algorithm}' not found. Falling back to default algorithm '${this._defaultAlgorithmSync}'.`);
|
|
348
|
+
// Fallback to default sync algorithm
|
|
349
|
+
provider = this._providers.get(this._defaultAlgorithmSync);
|
|
350
|
+
// If default algorithm is also not found, throw error
|
|
351
|
+
if (!provider) {
|
|
352
|
+
throw new Error(`Hash provider '${this._defaultAlgorithmSync}' (default) not found`);
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
// Check if provider supports synchronous hashing
|
|
356
|
+
if (!provider.toHashSync) {
|
|
357
|
+
throw new Error(`Hash provider '${algorithm}' does not support synchronous hashing. Use toHash() instead or choose a different algorithm (djb2, fnv1, murmur, crc32).`);
|
|
358
|
+
}
|
|
359
|
+
// Use the provider to hash the data synchronously
|
|
360
|
+
let hash = provider.toHashSync(dataBuffer);
|
|
361
|
+
// Store the full hash in cache before truncation
|
|
362
|
+
if (this._cache.enabled) {
|
|
363
|
+
this._cache.set(cacheKey, hash);
|
|
364
|
+
}
|
|
365
|
+
// if there is a max then change the hash
|
|
366
|
+
if (options?.maxLength && hash.length > options?.maxLength) {
|
|
367
|
+
hash = hash.substring(0, options.maxLength);
|
|
368
|
+
}
|
|
369
|
+
// After hook - allows modification/logging of result (synchronous/blocking)
|
|
370
|
+
const result = { hash, data: context.data, algorithm: context.algorithm };
|
|
371
|
+
this.hookSync('after:toHashSync', result);
|
|
372
|
+
return result.hash;
|
|
373
|
+
}
|
|
374
|
+
/**
|
|
375
|
+
* Generates a deterministic number within a specified range based on the hash of the provided data synchronously.
|
|
376
|
+
* This method uses the toHashSync function to create a consistent hash, then maps it to a number
|
|
377
|
+
* between min and max (inclusive).
|
|
378
|
+
*
|
|
379
|
+
* Note: This method only works with synchronous hash providers (djb2, fnv1, murmur, crc32).
|
|
380
|
+
*
|
|
381
|
+
* @param data - The data to hash (will be stringified before hashing)
|
|
382
|
+
* @param options - Configuration options (optional, defaults to min: 0, max: 100)
|
|
383
|
+
* @param options.min - The minimum value of the range (inclusive, defaults to 0)
|
|
384
|
+
* @param options.max - The maximum value of the range (inclusive, defaults to 100)
|
|
385
|
+
* @param options.algorithm - The hash algorithm to use (defaults to 'djb2')
|
|
386
|
+
* @param options.hashLength - Number of characters from hash to use for conversion (defaults to 16)
|
|
387
|
+
* @returns A number between min and max (inclusive)
|
|
388
|
+
*
|
|
389
|
+
* @throws {Error} If the specified algorithm does not support synchronous hashing
|
|
390
|
+
* @throws {Error} If min is greater than max
|
|
391
|
+
*
|
|
392
|
+
* @example
|
|
393
|
+
* ```ts
|
|
394
|
+
* const hashery = new Hashery();
|
|
395
|
+
* const num = hashery.toNumberSync({ user: 'john' }); // Uses default min: 0, max: 100
|
|
396
|
+
* console.log(num); // Always returns the same number for the same input, e.g., 42
|
|
397
|
+
*
|
|
398
|
+
* // Using custom range
|
|
399
|
+
* const num2 = hashery.toNumberSync({ user: 'john' }, { min: 1, max: 100 });
|
|
400
|
+
*
|
|
401
|
+
* // Using a different algorithm
|
|
402
|
+
* const numFnv1 = hashery.toNumberSync({ user: 'john' }, { min: 0, max: 255, algorithm: 'fnv1' });
|
|
403
|
+
* ```
|
|
404
|
+
*/
|
|
405
|
+
toNumberSync(data, options = {}) {
|
|
406
|
+
const { min = 0, max = 100, algorithm = this._defaultAlgorithmSync, hashLength = 16 } = options;
|
|
407
|
+
if (min > max) {
|
|
408
|
+
throw new Error('min cannot be greater than max');
|
|
409
|
+
}
|
|
410
|
+
// Get the hash as a hex string
|
|
411
|
+
// Take the first hashLength characters of the hash to convert to a number
|
|
412
|
+
// This provides good distribution while avoiding precision issues with JavaScript numbers
|
|
413
|
+
const hash = this.toHashSync(data, { algorithm, maxLength: hashLength });
|
|
414
|
+
// Convert hex to a number
|
|
415
|
+
const hashNumber = Number.parseInt(hash, 16);
|
|
416
|
+
// Map the hash number to the desired range
|
|
417
|
+
const range = max - min + 1;
|
|
418
|
+
const mapped = min + (hashNumber % range);
|
|
419
|
+
return mapped;
|
|
420
|
+
}
|
|
421
|
+
loadProviders(providers, options = { includeBase: true }) {
|
|
422
|
+
if (providers) {
|
|
423
|
+
for (const provider of providers) {
|
|
424
|
+
this._providers.add(provider);
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
// load all the providers
|
|
428
|
+
if (options.includeBase) {
|
|
429
|
+
this.providers.add(new WebCrypto({ algorithm: 'SHA-256' }));
|
|
430
|
+
this.providers.add(new WebCrypto({ algorithm: 'SHA-384' }));
|
|
431
|
+
this.providers.add(new WebCrypto({ algorithm: 'SHA-512' }));
|
|
432
|
+
this.providers.add(new CRC());
|
|
433
|
+
this.providers.add(new DJB2());
|
|
434
|
+
this.providers.add(new FNV1());
|
|
435
|
+
this.providers.add(new Murmur());
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
// Classes
|
|
440
|
+
export { Cache } from './cache.js';
|
|
441
|
+
export { CRC } from './providers/crc.js';
|
|
442
|
+
export { WebCrypto } from './providers/crypto.js';
|
|
443
|
+
export { DJB2 } from './providers/djb2.js';
|
|
444
|
+
export { FNV1 } from './providers/fnv1.js';
|
|
445
|
+
export { Murmur } from './providers/murmur.js';
|
|
446
|
+
export { HashProviders } from './providers.js';
|
|
447
|
+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S,CAAC,EAAE,SAAS,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC;YAC5D,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,GAAG,EAAE,CAAC,CAAC;YAC9B,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC;YAC/B,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC;YAC/B,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,MAAM,EAAE,CAAC,CAAC;QACnC,CAAC;IACH,CAAC;CACF;AAID,UAAU;AACV,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,GAAG,EAAE,MAAM,oBAAoB,CAAC;AAEzC,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAC3C,OAAO,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Original library: hashery (v1.5.1)
|
|
3
|
+
* - Copyright (c) 2025 Jared Wray
|
|
4
|
+
*
|
|
5
|
+
* Modified and integrated in "Inray":
|
|
6
|
+
* - Evgeniy Bushin
|
|
7
|
+
*/
|
|
8
|
+
/***/
|
|
9
|
+
import type { HashProvider } from '../types.ts';
|
|
10
|
+
export declare class CRC implements HashProvider {
|
|
11
|
+
get name(): string;
|
|
12
|
+
toHashSync(data: BufferSource): string;
|
|
13
|
+
toHash(data: BufferSource): Promise<string>;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=crc.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crc.d.ts","sourceRoot":"","sources":["../../../../../src/caching/src/hashing/providers/crc.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,KAAK;AAEL,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEhD,qBAAa,GAAI,YAAW,YAAY;IACtC,IAAW,IAAI,IAAI,MAAM,CAExB;IAEM,UAAU,CAAC,IAAI,EAAE,YAAY,GAAG,MAAM;IAmChC,MAAM,CAAC,IAAI,EAAE,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC;CAGzD"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Original library: hashery (v1.5.1)
|
|
3
|
+
* - Copyright (c) 2025 Jared Wray
|
|
4
|
+
*
|
|
5
|
+
* Modified and integrated in "Inray":
|
|
6
|
+
* - Evgeniy Bushin
|
|
7
|
+
*/
|
|
8
|
+
/***/
|
|
9
|
+
export class CRC {
|
|
10
|
+
get name() {
|
|
11
|
+
return 'crc32';
|
|
12
|
+
}
|
|
13
|
+
toHashSync(data) {
|
|
14
|
+
// Convert BufferSource to Uint8Array
|
|
15
|
+
let bytes;
|
|
16
|
+
if (data instanceof Uint8Array) {
|
|
17
|
+
bytes = data;
|
|
18
|
+
}
|
|
19
|
+
else if (data instanceof ArrayBuffer) {
|
|
20
|
+
bytes = new Uint8Array(data);
|
|
21
|
+
}
|
|
22
|
+
else if (data instanceof DataView) {
|
|
23
|
+
bytes = new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
const view = data;
|
|
27
|
+
bytes = new Uint8Array(view.buffer, view.byteOffset, view.byteLength);
|
|
28
|
+
}
|
|
29
|
+
// CRC-32 algorithm (IEEE 802.3 polynomial)
|
|
30
|
+
// This is the same algorithm used by PHP's crc32() function
|
|
31
|
+
const CRC32_POLYNOMIAL = 0xedb88320;
|
|
32
|
+
let crc = 0xffffffff;
|
|
33
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
34
|
+
crc = crc ^ bytes[i];
|
|
35
|
+
for (let j = 0; j < 8; j++) {
|
|
36
|
+
crc = (crc >>> 1) ^ (CRC32_POLYNOMIAL & -(crc & 1));
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
// Finalize CRC
|
|
40
|
+
crc = (crc ^ 0xffffffff) >>> 0;
|
|
41
|
+
// Convert to hexadecimal string (8 characters, zero-padded)
|
|
42
|
+
const hashHex = crc.toString(16).padStart(8, '0');
|
|
43
|
+
return hashHex;
|
|
44
|
+
}
|
|
45
|
+
async toHash(data) {
|
|
46
|
+
return this.toHashSync(data);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=crc.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crc.js","sourceRoot":"","sources":["../../../../../src/caching/src/hashing/providers/crc.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,KAAK;AAIL,MAAM,OAAO,GAAG;IACd,IAAW,IAAI;QACb,OAAO,OAAO,CAAC;IACjB,CAAC;IAEM,UAAU,CAAC,IAAkB;QAClC,qCAAqC;QACrC,IAAI,KAAiB,CAAC;QAEtB,IAAI,IAAI,YAAY,UAAU,EAAE,CAAC;YAC/B,KAAK,GAAG,IAAI,CAAC;QACf,CAAC;aAAM,IAAI,IAAI,YAAY,WAAW,EAAE,CAAC;YACvC,KAAK,GAAG,IAAI,UAAU,CAAC,IAAI,CAAC,CAAC;QAC/B,CAAC;aAAM,IAAI,IAAI,YAAY,QAAQ,EAAE,CAAC;YACpC,KAAK,GAAG,IAAI,UAAU,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;QACxE,CAAC;aAAM,CAAC;YACN,MAAM,IAAI,GAAG,IAAuB,CAAC;YACrC,KAAK,GAAG,IAAI,UAAU,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;QACxE,CAAC;QAED,2CAA2C;QAC3C,4DAA4D;QAC5D,MAAM,gBAAgB,GAAG,UAAU,CAAC;QACpC,IAAI,GAAG,GAAG,UAAU,CAAC;QAErB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YACtC,GAAG,GAAG,GAAG,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;YACrB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;gBAC3B,GAAG,GAAG,CAAC,GAAG,KAAK,CAAC,CAAC,GAAG,CAAC,gBAAgB,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC;YACtD,CAAC;QACH,CAAC;QAED,eAAe;QACf,GAAG,GAAG,CAAC,GAAG,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC;QAE/B,4DAA4D;QAC5D,MAAM,OAAO,GAAG,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;QAClD,OAAO,OAAO,CAAC;IACjB,CAAC;IAEM,KAAK,CAAC,MAAM,CAAC,IAAkB;QACpC,OAAO,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;IAC/B,CAAC;CACF"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Original library: hashery (v1.5.1)
|
|
3
|
+
* - Copyright (c) 2025 Jared Wray
|
|
4
|
+
*
|
|
5
|
+
* Modified and integrated in "Inray":
|
|
6
|
+
* - Evgeniy Bushin
|
|
7
|
+
*/
|
|
8
|
+
/***/
|
|
9
|
+
import type { WebCryptoHashAlgorithm, HashProvider } from '../types.ts';
|
|
10
|
+
export type WebCryptoOptions = {
|
|
11
|
+
algorithm?: WebCryptoHashAlgorithm;
|
|
12
|
+
};
|
|
13
|
+
export declare class WebCrypto implements HashProvider {
|
|
14
|
+
private _algorithm;
|
|
15
|
+
constructor(options?: WebCryptoOptions);
|
|
16
|
+
get name(): string;
|
|
17
|
+
toHash(data: BufferSource): Promise<string>;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=crypto.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crypto.d.ts","sourceRoot":"","sources":["../../../../../src/caching/src/hashing/providers/crypto.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,KAAK;AAEL,OAAO,KAAK,EAAE,sBAAsB,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAExE,MAAM,MAAM,gBAAgB,GAAG;IAC7B,SAAS,CAAC,EAAE,sBAAsB,CAAC;CACpC,CAAC;AAEF,qBAAa,SAAU,YAAW,YAAY;IAC5C,OAAO,CAAC,UAAU,CAAqC;gBAC3C,OAAO,CAAC,EAAE,gBAAgB;IAMtC,IAAW,IAAI,IAAI,MAAM,CAExB;IAEY,MAAM,CAAC,IAAI,EAAE,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC;CAUzD"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Original library: hashery (v1.5.1)
|
|
3
|
+
* - Copyright (c) 2025 Jared Wray
|
|
4
|
+
*
|
|
5
|
+
* Modified and integrated in "Inray":
|
|
6
|
+
* - Evgeniy Bushin
|
|
7
|
+
*/
|
|
8
|
+
/***/
|
|
9
|
+
export class WebCrypto {
|
|
10
|
+
_algorithm = 'SHA-256';
|
|
11
|
+
constructor(options) {
|
|
12
|
+
if (options?.algorithm) {
|
|
13
|
+
this._algorithm = options?.algorithm;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
get name() {
|
|
17
|
+
return this._algorithm;
|
|
18
|
+
}
|
|
19
|
+
async toHash(data) {
|
|
20
|
+
// Hash the data using Web Crypto API
|
|
21
|
+
const hashBuffer = await crypto.subtle.digest(this._algorithm, data);
|
|
22
|
+
// Convert the hash to a hexadecimal string
|
|
23
|
+
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
|
24
|
+
const hashHex = hashArray.map((byte) => byte.toString(16).padStart(2, '0')).join('');
|
|
25
|
+
return hashHex;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=crypto.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crypto.js","sourceRoot":"","sources":["../../../../../src/caching/src/hashing/providers/crypto.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,KAAK;AAQL,MAAM,OAAO,SAAS;IACZ,UAAU,GAA2B,SAAS,CAAC;IACvD,YAAY,OAA0B;QACpC,IAAI,OAAO,EAAE,SAAS,EAAE,CAAC;YACvB,IAAI,CAAC,UAAU,GAAG,OAAO,EAAE,SAAS,CAAC;QACvC,CAAC;IACH,CAAC;IAED,IAAW,IAAI;QACb,OAAO,IAAI,CAAC,UAAU,CAAC;IACzB,CAAC;IAEM,KAAK,CAAC,MAAM,CAAC,IAAkB;QACpC,qCAAqC;QACrC,MAAM,UAAU,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;QAErE,2CAA2C;QAC3C,MAAM,SAAS,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,UAAU,CAAC,UAAU,CAAC,CAAC,CAAC;QACzD,MAAM,OAAO,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAErF,OAAO,OAAO,CAAC;IACjB,CAAC;CACF"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { HashProvider } from '../types.ts';
|
|
2
|
+
/**
|
|
3
|
+
* DJB2 hash algorithm implementation.
|
|
4
|
+
*
|
|
5
|
+
* DJB2 is a non-cryptographic hash function created by Daniel J. Bernstein.
|
|
6
|
+
* It produces a 32-bit hash value, making it suitable for hash tables and checksums,
|
|
7
|
+
* but NOT for cryptographic purposes.
|
|
8
|
+
*
|
|
9
|
+
* Algorithm: hash = hash * 33 + c (where c is each byte)
|
|
10
|
+
* Initial value: 5381
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* import { Hashery } from 'hashery';
|
|
15
|
+
* import { DJB2 } from 'hashery/providers/djb2';
|
|
16
|
+
*
|
|
17
|
+
* const hashery = new Hashery();
|
|
18
|
+
* hashery.providers.add(new DJB2());
|
|
19
|
+
*
|
|
20
|
+
* const hash = await hashery.toHash({ data: 'hello' }, 'djb2');
|
|
21
|
+
* console.log(hash); // "7c9df5ea"
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export declare class DJB2 implements HashProvider {
|
|
25
|
+
/**
|
|
26
|
+
* The name identifier for this hash provider.
|
|
27
|
+
*/
|
|
28
|
+
get name(): string;
|
|
29
|
+
/**
|
|
30
|
+
* Computes the DJB2 hash of the provided data synchronously.
|
|
31
|
+
*
|
|
32
|
+
* @param data - The data to hash (Uint8Array, ArrayBuffer, or DataView)
|
|
33
|
+
* @returns An 8-character lowercase hexadecimal string
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```typescript
|
|
37
|
+
* const djb2 = new DJB2();
|
|
38
|
+
* const data = new TextEncoder().encode('hello');
|
|
39
|
+
* const hash = djb2.toHashSync(data);
|
|
40
|
+
* console.log(hash); // "7c9df5ea"
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
toHashSync(data: BufferSource): string;
|
|
44
|
+
/**
|
|
45
|
+
* Computes the DJB2 hash of the provided data.
|
|
46
|
+
*
|
|
47
|
+
* @param data - The data to hash (Uint8Array, ArrayBuffer, or DataView)
|
|
48
|
+
* @returns A Promise resolving to an 8-character lowercase hexadecimal string
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```typescript
|
|
52
|
+
* const djb2 = new DJB2();
|
|
53
|
+
* const data = new TextEncoder().encode('hello');
|
|
54
|
+
* const hash = await djb2.toHash(data);
|
|
55
|
+
* console.log(hash); // "7c9df5ea"
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
toHash(data: BufferSource): Promise<string>;
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=djb2.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"djb2.d.ts","sourceRoot":"","sources":["../../../../../src/caching/src/hashing/providers/djb2.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEhD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,qBAAa,IAAK,YAAW,YAAY;IACvC;;OAEG;IACH,IAAW,IAAI,IAAI,MAAM,CAExB;IAED;;;;;;;;;;;;;OAaG;IACI,UAAU,CAAC,IAAI,EAAE,YAAY,GAAG,MAAM;IAiC7C;;;;;;;;;;;;;OAaG;IACU,MAAM,CAAC,IAAI,EAAE,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC;CAGzD"}
|