@alwatr/hash-string 5.2.8 → 5.2.9
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/CHANGELOG.md +6 -0
- package/dist/djb2-hash.d.ts +2 -2
- package/dist/main.cjs +1 -5
- package/dist/main.cjs.map +2 -2
- package/dist/main.d.ts.map +1 -1
- package/dist/main.mjs +1 -7
- package/dist/main.mjs.map +3 -3
- package/package.json +2 -5
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,12 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [5.2.9](https://github.com/Alwatr/nanolib/compare/@alwatr/hash-string@5.2.8...@alwatr/hash-string@5.2.9) (2025-09-13)
|
|
7
|
+
|
|
8
|
+
### 🧹 Miscellaneous Chores
|
|
9
|
+
|
|
10
|
+
* remove package-tracer dependency and related code from fetch package ([96fe4e9](https://github.com/Alwatr/nanolib/commit/96fe4e9552a205f218ceed187c55e4e904a07089))
|
|
11
|
+
|
|
6
12
|
## [5.2.8](https://github.com/Alwatr/nanolib/compare/@alwatr/hash-string@5.2.7...@alwatr/hash-string@5.2.8) (2025-09-09)
|
|
7
13
|
|
|
8
14
|
### 🧹 Miscellaneous Chores
|
package/dist/djb2-hash.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* DJB2
|
|
2
|
+
* DJB2 hash algorithm but faster!
|
|
3
3
|
*
|
|
4
4
|
* This implementation is based on Daniel J. Bernstein's popular 'times 33' hash algorithm,
|
|
5
5
|
* commonly known as DJB2. It's known for its simplicity, speed, and good distribution properties
|
|
6
6
|
* for short strings, making it suitable for general purpose hashing needs.
|
|
7
7
|
*
|
|
8
|
-
* Performance
|
|
8
|
+
* Performance improvements in this version:
|
|
9
9
|
* - Uses right-to-left iteration to avoid repeated length lookups
|
|
10
10
|
* - Employs bit shifting operations for faster computation
|
|
11
11
|
* - Final right shift ensures unsigned 32-bit integer output
|
package/dist/main.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* @alwatr/hash-string v5.2.
|
|
1
|
+
/* @alwatr/hash-string v5.2.9 */
|
|
2
2
|
"use strict";
|
|
3
3
|
var __defProp = Object.defineProperty;
|
|
4
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -25,7 +25,6 @@ __export(main_exports, {
|
|
|
25
25
|
nanoHash: () => nanoHash
|
|
26
26
|
});
|
|
27
27
|
module.exports = __toCommonJS(main_exports);
|
|
28
|
-
var import_package_tracer = require("@alwatr/package-tracer");
|
|
29
28
|
|
|
30
29
|
// src/djb2-hash.ts
|
|
31
30
|
function djb2Hash(str) {
|
|
@@ -61,9 +60,6 @@ function nanoHash(str, prefix, repeat = 1) {
|
|
|
61
60
|
return nanoHash(result, prefix, repeat - 1);
|
|
62
61
|
}
|
|
63
62
|
}
|
|
64
|
-
|
|
65
|
-
// src/main.ts
|
|
66
|
-
__dev_mode__: import_package_tracer.packageTracer.add("@alwatr/hash-string", "5.2.8");
|
|
67
63
|
// Annotate the CommonJS export names for ESM import in node:
|
|
68
64
|
0 && (module.exports = {
|
|
69
65
|
djb2Hash,
|
package/dist/main.cjs.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/main.ts", "../src/djb2-hash.ts", "../src/nano-hash.ts"],
|
|
4
|
-
"sourcesContent": ["
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA
|
|
4
|
+
"sourcesContent": ["export * from './djb2-hash.js';\nexport * from './nano-hash.js';\n", "/**\n * DJB2 hash algorithm but faster!\n *\n * This implementation is based on Daniel J. Bernstein's popular 'times 33' hash algorithm,\n * commonly known as DJB2. It's known for its simplicity, speed, and good distribution properties\n * for short strings, making it suitable for general purpose hashing needs.\n *\n * Performance improvements in this version:\n * - Uses right-to-left iteration to avoid repeated length lookups\n * - Employs bit shifting operations for faster computation\n * - Final right shift ensures unsigned 32-bit integer output\n *\n * @param {string} str - The input string to be hashed\n * @returns {number} A 32-bit unsigned integer hash value\n *\n * @example\n * // Returns a numeric hash value\n * const hashValue = djb2Hash(\"hello world\");\n */\nexport function djb2Hash(str: string): number {\n // 5381 is a prime number used as initial value in the DJB2 algorithm\n let hashValue = 5381;\n\n // Reverse loop for better performance - avoids repeated length property lookup\n for (let i = str.length - 1; i >= 0; i--) {\n // Using left shift (*2) and addition instead of multiplication by 33\n // (hash * 33) is equivalent to ((hash << 5) + hash)\n hashValue = ((hashValue << 5) + hashValue) ^ str.charCodeAt(i);\n }\n\n return hashValue >>> 0;\n}\n", "/**\n * Simple hash string for fast hashing (like md5).\n * This function is not very secure and should not be used for security purposes.\n * But it cannot be reversed easily and brute force can take up to years for fast computers.\n *\n * @param str - The string or number to hash\n * @param prefix - A prefix to add to the beginning of the hash result\n * @param repeat - Number of times to repeat the hashing process for increased complexity (default: 3)\n * @returns A hashed string with the specified prefix\n */\nexport function nanoHash(str: string | number, prefix: string, repeat = 1): string {\n if (repeat < 1) {\n throw new Error('The repeat parameter must be greater than or equal to 1');\n }\n\n let hash1 = 0xdeadbeef;\n let hash2 = 0x41c6ce57;\n\n if (typeof str === 'number') {\n str = str.toString();\n }\n\n const len = str.length;\n for (let i = 0; i < len; i++) {\n const char = str.charCodeAt(i);\n hash1 = Math.imul(hash1 ^ char, 2654435761);\n hash2 = Math.imul(hash2 ^ char, 1597334677);\n }\n\n hash1 = Math.imul(hash1 ^ (hash1 >>> 16), 2246822507) ^ Math.imul(hash2 ^ (hash2 >>> 13), 3266489909);\n hash2 = Math.imul(hash2 ^ (hash2 >>> 16), 2246822507) ^ Math.imul(hash1 ^ (hash1 >>> 13), 3266489909);\n\n const result = prefix + (hash1 >>> 0).toString(36) + (hash2 >>> 0).toString(36);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
|
1
|
-
{"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC"}
|
package/dist/main.mjs
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
/* @alwatr/hash-string v5.2.
|
|
2
|
-
|
|
3
|
-
// src/main.ts
|
|
4
|
-
import { packageTracer } from "@alwatr/package-tracer";
|
|
1
|
+
/* @alwatr/hash-string v5.2.9 */
|
|
5
2
|
|
|
6
3
|
// src/djb2-hash.ts
|
|
7
4
|
function djb2Hash(str) {
|
|
@@ -37,9 +34,6 @@ function nanoHash(str, prefix, repeat = 1) {
|
|
|
37
34
|
return nanoHash(result, prefix, repeat - 1);
|
|
38
35
|
}
|
|
39
36
|
}
|
|
40
|
-
|
|
41
|
-
// src/main.ts
|
|
42
|
-
__dev_mode__: packageTracer.add("@alwatr/hash-string", "5.2.8");
|
|
43
37
|
export {
|
|
44
38
|
djb2Hash,
|
|
45
39
|
nanoHash
|
package/dist/main.mjs.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../src/
|
|
4
|
-
"sourcesContent": ["
|
|
5
|
-
"mappings": ";;;
|
|
3
|
+
"sources": ["../src/djb2-hash.ts", "../src/nano-hash.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * DJB2 hash algorithm but faster!\n *\n * This implementation is based on Daniel J. Bernstein's popular 'times 33' hash algorithm,\n * commonly known as DJB2. It's known for its simplicity, speed, and good distribution properties\n * for short strings, making it suitable for general purpose hashing needs.\n *\n * Performance improvements in this version:\n * - Uses right-to-left iteration to avoid repeated length lookups\n * - Employs bit shifting operations for faster computation\n * - Final right shift ensures unsigned 32-bit integer output\n *\n * @param {string} str - The input string to be hashed\n * @returns {number} A 32-bit unsigned integer hash value\n *\n * @example\n * // Returns a numeric hash value\n * const hashValue = djb2Hash(\"hello world\");\n */\nexport function djb2Hash(str: string): number {\n // 5381 is a prime number used as initial value in the DJB2 algorithm\n let hashValue = 5381;\n\n // Reverse loop for better performance - avoids repeated length property lookup\n for (let i = str.length - 1; i >= 0; i--) {\n // Using left shift (*2) and addition instead of multiplication by 33\n // (hash * 33) is equivalent to ((hash << 5) + hash)\n hashValue = ((hashValue << 5) + hashValue) ^ str.charCodeAt(i);\n }\n\n return hashValue >>> 0;\n}\n", "/**\n * Simple hash string for fast hashing (like md5).\n * This function is not very secure and should not be used for security purposes.\n * But it cannot be reversed easily and brute force can take up to years for fast computers.\n *\n * @param str - The string or number to hash\n * @param prefix - A prefix to add to the beginning of the hash result\n * @param repeat - Number of times to repeat the hashing process for increased complexity (default: 3)\n * @returns A hashed string with the specified prefix\n */\nexport function nanoHash(str: string | number, prefix: string, repeat = 1): string {\n if (repeat < 1) {\n throw new Error('The repeat parameter must be greater than or equal to 1');\n }\n\n let hash1 = 0xdeadbeef;\n let hash2 = 0x41c6ce57;\n\n if (typeof str === 'number') {\n str = str.toString();\n }\n\n const len = str.length;\n for (let i = 0; i < len; i++) {\n const char = str.charCodeAt(i);\n hash1 = Math.imul(hash1 ^ char, 2654435761);\n hash2 = Math.imul(hash2 ^ char, 1597334677);\n }\n\n hash1 = Math.imul(hash1 ^ (hash1 >>> 16), 2246822507) ^ Math.imul(hash2 ^ (hash2 >>> 13), 3266489909);\n hash2 = Math.imul(hash2 ^ (hash2 >>> 16), 2246822507) ^ Math.imul(hash1 ^ (hash1 >>> 13), 3266489909);\n\n const result = prefix + (hash1 >>> 0).toString(36) + (hash2 >>> 0).toString(36);\n if (repeat === 1) {\n return result;\n }\n else {\n return nanoHash(result, prefix, repeat - 1);\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;AAmBO,SAAS,SAAS,KAAqB;AAE5C,MAAI,YAAY;AAGhB,WAAS,IAAI,IAAI,SAAS,GAAG,KAAK,GAAG,KAAK;AAGxC,iBAAc,aAAa,KAAK,YAAa,IAAI,WAAW,CAAC;AAAA,EAC/D;AAEA,SAAO,cAAc;AACvB;;;ACrBO,SAAS,SAAS,KAAsB,QAAgB,SAAS,GAAW;AACjF,MAAI,SAAS,GAAG;AACd,UAAM,IAAI,MAAM,yDAAyD;AAAA,EAC3E;AAEA,MAAI,QAAQ;AACZ,MAAI,QAAQ;AAEZ,MAAI,OAAO,QAAQ,UAAU;AAC3B,UAAM,IAAI,SAAS;AAAA,EACrB;AAEA,QAAM,MAAM,IAAI;AAChB,WAAS,IAAI,GAAG,IAAI,KAAK,KAAK;AAC5B,UAAM,OAAO,IAAI,WAAW,CAAC;AAC7B,YAAQ,KAAK,KAAK,QAAQ,MAAM,UAAU;AAC1C,YAAQ,KAAK,KAAK,QAAQ,MAAM,UAAU;AAAA,EAC5C;AAEA,UAAQ,KAAK,KAAK,QAAS,UAAU,IAAK,UAAU,IAAI,KAAK,KAAK,QAAS,UAAU,IAAK,UAAU;AACpG,UAAQ,KAAK,KAAK,QAAS,UAAU,IAAK,UAAU,IAAI,KAAK,KAAK,QAAS,UAAU,IAAK,UAAU;AAEpG,QAAM,SAAS,UAAU,UAAU,GAAG,SAAS,EAAE,KAAK,UAAU,GAAG,SAAS,EAAE;AAC9E,MAAI,WAAW,GAAG;AAChB,WAAO;AAAA,EACT,OACK;AACH,WAAO,SAAS,QAAQ,QAAQ,SAAS,CAAC;AAAA,EAC5C;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alwatr/hash-string",
|
|
3
3
|
"description": "A simple utility to generate a hash string.",
|
|
4
|
-
"version": "5.2.
|
|
4
|
+
"version": "5.2.9",
|
|
5
5
|
"author": "S. Ali Mihandoost <ali.mihandoost@gmail.com>",
|
|
6
6
|
"bugs": "https://github.com/Alwatr/nanolib/issues",
|
|
7
|
-
"dependencies": {
|
|
8
|
-
"@alwatr/package-tracer": "5.5.10"
|
|
9
|
-
},
|
|
10
7
|
"devDependencies": {
|
|
11
8
|
"@alwatr/nano-build": "6.1.1",
|
|
12
9
|
"@alwatr/prettier-config": "5.0.3",
|
|
@@ -75,5 +72,5 @@
|
|
|
75
72
|
},
|
|
76
73
|
"type": "module",
|
|
77
74
|
"types": "./dist/main.d.ts",
|
|
78
|
-
"gitHead": "
|
|
75
|
+
"gitHead": "0555c6f5ac11e7a911deee9bc90cfa44b6fe0b48"
|
|
79
76
|
}
|