@alwatr/hash-string 5.2.10 → 5.2.12

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 CHANGED
@@ -3,6 +3,16 @@
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.12](https://github.com/Alwatr/nanolib/compare/@alwatr/hash-string@5.2.11...@alwatr/hash-string@5.2.12) (2025-09-15)
7
+
8
+ **Note:** Version bump only for package @alwatr/hash-string
9
+
10
+ ## [5.2.11](https://github.com/Alwatr/nanolib/compare/@alwatr/hash-string@5.2.10...@alwatr/hash-string@5.2.11) (2025-09-14)
11
+
12
+ ### 🔨 Code Refactoring
13
+
14
+ * **hash:** remove djb2Hash implementation and tests ([140a1e1](https://github.com/Alwatr/nanolib/commit/140a1e191bbe864379e2621919f7fbc37f403afa))
15
+
6
16
  ## [5.2.10](https://github.com/Alwatr/nanolib/compare/@alwatr/hash-string@5.2.9...@alwatr/hash-string@5.2.10) (2025-09-13)
7
17
 
8
18
  **Note:** Version bump only for package @alwatr/hash-string
package/dist/main.cjs CHANGED
@@ -1,68 +1,3 @@
1
- /* @alwatr/hash-string v5.2.10 */
2
- "use strict";
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __export = (target, all) => {
8
- for (var name in all)
9
- __defProp(target, name, { get: all[name], enumerable: true });
10
- };
11
- var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from))
14
- if (!__hasOwnProp.call(to, key) && key !== except)
15
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
- }
17
- return to;
18
- };
19
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
-
21
- // src/main.ts
22
- var main_exports = {};
23
- __export(main_exports, {
24
- djb2Hash: () => djb2Hash,
25
- nanoHash: () => nanoHash
26
- });
27
- module.exports = __toCommonJS(main_exports);
28
-
29
- // src/djb2-hash.ts
30
- function djb2Hash(str) {
31
- let hashValue = 5381;
32
- for (let i = str.length - 1; i >= 0; i--) {
33
- hashValue = (hashValue << 5) + hashValue ^ str.charCodeAt(i);
34
- }
35
- return hashValue >>> 0;
36
- }
37
-
38
- // src/nano-hash.ts
39
- function nanoHash(str, prefix, repeat = 1) {
40
- if (repeat < 1) {
41
- throw new Error("The repeat parameter must be greater than or equal to 1");
42
- }
43
- let hash1 = 3735928559;
44
- let hash2 = 1103547991;
45
- if (typeof str === "number") {
46
- str = str.toString();
47
- }
48
- const len = str.length;
49
- for (let i = 0; i < len; i++) {
50
- const char = str.charCodeAt(i);
51
- hash1 = Math.imul(hash1 ^ char, 2654435761);
52
- hash2 = Math.imul(hash2 ^ char, 1597334677);
53
- }
54
- hash1 = Math.imul(hash1 ^ hash1 >>> 16, 2246822507) ^ Math.imul(hash2 ^ hash2 >>> 13, 3266489909);
55
- hash2 = Math.imul(hash2 ^ hash2 >>> 16, 2246822507) ^ Math.imul(hash1 ^ hash1 >>> 13, 3266489909);
56
- const result = prefix + (hash1 >>> 0).toString(36) + (hash2 >>> 0).toString(36);
57
- if (repeat === 1) {
58
- return result;
59
- } else {
60
- return nanoHash(result, prefix, repeat - 1);
61
- }
62
- }
63
- // Annotate the CommonJS export names for ESM import in node:
64
- 0 && (module.exports = {
65
- djb2Hash,
66
- nanoHash
67
- });
1
+ /* @alwatr/hash-string v5.2.12 */
2
+ "use strict";var __defProp=Object.defineProperty;var __getOwnPropDesc=Object.getOwnPropertyDescriptor;var __getOwnPropNames=Object.getOwnPropertyNames;var __hasOwnProp=Object.prototype.hasOwnProperty;var __export=(target,all)=>{for(var name in all)__defProp(target,name,{get:all[name],enumerable:true})};var __copyProps=(to,from,except,desc)=>{if(from&&typeof from==="object"||typeof from==="function"){for(let key of __getOwnPropNames(from))if(!__hasOwnProp.call(to,key)&&key!==except)__defProp(to,key,{get:()=>from[key],enumerable:!(desc=__getOwnPropDesc(from,key))||desc.enumerable})}return to};var __toCommonJS=mod=>__copyProps(__defProp({},"__esModule",{value:true}),mod);var main_exports={};__export(main_exports,{nanoHash:()=>nanoHash});module.exports=__toCommonJS(main_exports);function nanoHash(str,prefix,repeat=1){if(repeat<1){throw new Error("The repeat parameter must be greater than or equal to 1")}let hash1=3735928559;let hash2=1103547991;if(typeof str==="number"){str=str.toString()}const len=str.length;for(let i=0;i<len;i++){const char=str.charCodeAt(i);hash1=Math.imul(hash1^char,2654435761);hash2=Math.imul(hash2^char,1597334677)}hash1=Math.imul(hash1^hash1>>>16,2246822507)^Math.imul(hash2^hash2>>>13,3266489909);hash2=Math.imul(hash2^hash2>>>16,2246822507)^Math.imul(hash1^hash1>>>13,3266489909);const result=prefix+(hash1>>>0).toString(36)+(hash2>>>0).toString(36);if(repeat===1){return result}else{return nanoHash(result,prefix,repeat-1)}}0&&(module.exports={nanoHash});
68
3
  //# sourceMappingURL=main.cjs.map
package/dist/main.cjs.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../src/main.ts", "../src/djb2-hash.ts", "../src/nano-hash.ts"],
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);\n if (repeat === 1) {\n return result;\n }\n else {\n return nanoHash(result, prefix, repeat - 1);\n }\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACmBO,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;",
3
+ "sources": ["../src/main.ts"],
4
+ "sourcesContent": ["/**\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": ";qqBAAA,6GAUO,SAAS,SAAS,IAAsB,OAAgB,OAAS,EAAW,CACjF,GAAI,OAAS,EAAG,CACd,MAAM,IAAI,MAAM,yDAAyD,CAC3E,CAEA,IAAI,MAAQ,WACZ,IAAI,MAAQ,WAEZ,GAAI,OAAO,MAAQ,SAAU,CAC3B,IAAM,IAAI,SAAS,CACrB,CAEA,MAAM,IAAM,IAAI,OAChB,QAAS,EAAI,EAAG,EAAI,IAAK,IAAK,CAC5B,MAAM,KAAO,IAAI,WAAW,CAAC,EAC7B,MAAQ,KAAK,KAAK,MAAQ,KAAM,UAAU,EAC1C,MAAQ,KAAK,KAAK,MAAQ,KAAM,UAAU,CAC5C,CAEA,MAAQ,KAAK,KAAK,MAAS,QAAU,GAAK,UAAU,EAAI,KAAK,KAAK,MAAS,QAAU,GAAK,UAAU,EACpG,MAAQ,KAAK,KAAK,MAAS,QAAU,GAAK,UAAU,EAAI,KAAK,KAAK,MAAS,QAAU,GAAK,UAAU,EAEpG,MAAM,OAAS,QAAU,QAAU,GAAG,SAAS,EAAE,GAAK,QAAU,GAAG,SAAS,EAAE,EAC9E,GAAI,SAAW,EAAG,CAChB,OAAO,MACT,KACK,CACH,OAAO,SAAS,OAAQ,OAAQ,OAAS,CAAC,CAC5C,CACF",
6
6
  "names": []
7
7
  }
package/dist/main.d.ts CHANGED
@@ -1,3 +1,12 @@
1
- export * from './djb2-hash.js';
2
- export * from './nano-hash.js';
1
+ /**
2
+ * Simple hash string for fast hashing (like md5).
3
+ * This function is not very secure and should not be used for security purposes.
4
+ * But it cannot be reversed easily and brute force can take up to years for fast computers.
5
+ *
6
+ * @param str - The string or number to hash
7
+ * @param prefix - A prefix to add to the beginning of the hash result
8
+ * @param repeat - Number of times to repeat the hashing process for increased complexity (default: 3)
9
+ * @returns A hashed string with the specified prefix
10
+ */
11
+ export declare function nanoHash(str: string | number, prefix: string, repeat?: number): string;
3
12
  //# sourceMappingURL=main.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC"}
1
+ {"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,SAAI,GAAG,MAAM,CA6BjF"}
package/dist/main.mjs CHANGED
@@ -1,41 +1,3 @@
1
- /* @alwatr/hash-string v5.2.10 */
2
-
3
- // src/djb2-hash.ts
4
- function djb2Hash(str) {
5
- let hashValue = 5381;
6
- for (let i = str.length - 1; i >= 0; i--) {
7
- hashValue = (hashValue << 5) + hashValue ^ str.charCodeAt(i);
8
- }
9
- return hashValue >>> 0;
10
- }
11
-
12
- // src/nano-hash.ts
13
- function nanoHash(str, prefix, repeat = 1) {
14
- if (repeat < 1) {
15
- throw new Error("The repeat parameter must be greater than or equal to 1");
16
- }
17
- let hash1 = 3735928559;
18
- let hash2 = 1103547991;
19
- if (typeof str === "number") {
20
- str = str.toString();
21
- }
22
- const len = str.length;
23
- for (let i = 0; i < len; i++) {
24
- const char = str.charCodeAt(i);
25
- hash1 = Math.imul(hash1 ^ char, 2654435761);
26
- hash2 = Math.imul(hash2 ^ char, 1597334677);
27
- }
28
- hash1 = Math.imul(hash1 ^ hash1 >>> 16, 2246822507) ^ Math.imul(hash2 ^ hash2 >>> 13, 3266489909);
29
- hash2 = Math.imul(hash2 ^ hash2 >>> 16, 2246822507) ^ Math.imul(hash1 ^ hash1 >>> 13, 3266489909);
30
- const result = prefix + (hash1 >>> 0).toString(36) + (hash2 >>> 0).toString(36);
31
- if (repeat === 1) {
32
- return result;
33
- } else {
34
- return nanoHash(result, prefix, repeat - 1);
35
- }
36
- }
37
- export {
38
- djb2Hash,
39
- nanoHash
40
- };
1
+ /* @alwatr/hash-string v5.2.12 */
2
+ function nanoHash(str,prefix,repeat=1){if(repeat<1){throw new Error("The repeat parameter must be greater than or equal to 1")}let hash1=3735928559;let hash2=1103547991;if(typeof str==="number"){str=str.toString()}const len=str.length;for(let i=0;i<len;i++){const char=str.charCodeAt(i);hash1=Math.imul(hash1^char,2654435761);hash2=Math.imul(hash2^char,1597334677)}hash1=Math.imul(hash1^hash1>>>16,2246822507)^Math.imul(hash2^hash2>>>13,3266489909);hash2=Math.imul(hash2^hash2>>>16,2246822507)^Math.imul(hash1^hash1>>>13,3266489909);const result=prefix+(hash1>>>0).toString(36)+(hash2>>>0).toString(36);if(repeat===1){return result}else{return nanoHash(result,prefix,repeat-1)}}export{nanoHash};
41
3
  //# sourceMappingURL=main.mjs.map
package/dist/main.mjs.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
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;",
3
+ "sources": ["../src/main.ts"],
4
+ "sourcesContent": ["/**\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": ";AAUO,SAAS,SAAS,IAAsB,OAAgB,OAAS,EAAW,CACjF,GAAI,OAAS,EAAG,CACd,MAAM,IAAI,MAAM,yDAAyD,CAC3E,CAEA,IAAI,MAAQ,WACZ,IAAI,MAAQ,WAEZ,GAAI,OAAO,MAAQ,SAAU,CAC3B,IAAM,IAAI,SAAS,CACrB,CAEA,MAAM,IAAM,IAAI,OAChB,QAAS,EAAI,EAAG,EAAI,IAAK,IAAK,CAC5B,MAAM,KAAO,IAAI,WAAW,CAAC,EAC7B,MAAQ,KAAK,KAAK,MAAQ,KAAM,UAAU,EAC1C,MAAQ,KAAK,KAAK,MAAQ,KAAM,UAAU,CAC5C,CAEA,MAAQ,KAAK,KAAK,MAAS,QAAU,GAAK,UAAU,EAAI,KAAK,KAAK,MAAS,QAAU,GAAK,UAAU,EACpG,MAAQ,KAAK,KAAK,MAAS,QAAU,GAAK,UAAU,EAAI,KAAK,KAAK,MAAS,QAAU,GAAK,UAAU,EAEpG,MAAM,OAAS,QAAU,QAAU,GAAG,SAAS,EAAE,GAAK,QAAU,GAAG,SAAS,EAAE,EAC9E,GAAI,SAAW,EAAG,CAChB,OAAO,MACT,KACK,CACH,OAAO,SAAS,OAAQ,OAAQ,OAAS,CAAC,CAC5C,CACF",
6
6
  "names": []
7
7
  }
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@alwatr/hash-string",
3
3
  "description": "A simple utility to generate a hash string.",
4
- "version": "5.2.10",
4
+ "version": "5.2.12",
5
5
  "author": "S. Ali Mihandoost <ali.mihandoost@gmail.com>",
6
6
  "bugs": "https://github.com/Alwatr/nanolib/issues",
7
7
  "devDependencies": {
8
- "@alwatr/nano-build": "6.1.2",
8
+ "@alwatr/nano-build": "6.2.0",
9
9
  "@alwatr/prettier-config": "5.0.3",
10
10
  "@alwatr/tsconfig-base": "6.0.1",
11
11
  "jest": "^30.1.3",
@@ -72,5 +72,5 @@
72
72
  },
73
73
  "type": "module",
74
74
  "types": "./dist/main.d.ts",
75
- "gitHead": "4da18811162df49c118acd71086cdbe38b27f250"
75
+ "gitHead": "e081773e1ba6bf1c62c07d7dc966b174fa7dd3ea"
76
76
  }
@@ -1,21 +0,0 @@
1
- /**
2
- * DJB2 hash algorithm but faster!
3
- *
4
- * This implementation is based on Daniel J. Bernstein's popular 'times 33' hash algorithm,
5
- * commonly known as DJB2. It's known for its simplicity, speed, and good distribution properties
6
- * for short strings, making it suitable for general purpose hashing needs.
7
- *
8
- * Performance improvements in this version:
9
- * - Uses right-to-left iteration to avoid repeated length lookups
10
- * - Employs bit shifting operations for faster computation
11
- * - Final right shift ensures unsigned 32-bit integer output
12
- *
13
- * @param {string} str - The input string to be hashed
14
- * @returns {number} A 32-bit unsigned integer hash value
15
- *
16
- * @example
17
- * // Returns a numeric hash value
18
- * const hashValue = djb2Hash("hello world");
19
- */
20
- export declare function djb2Hash(str: string): number;
21
- //# sourceMappingURL=djb2-hash.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"djb2-hash.d.ts","sourceRoot":"","sources":["../src/djb2-hash.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAY5C"}
@@ -1,12 +0,0 @@
1
- /**
2
- * Simple hash string for fast hashing (like md5).
3
- * This function is not very secure and should not be used for security purposes.
4
- * But it cannot be reversed easily and brute force can take up to years for fast computers.
5
- *
6
- * @param str - The string or number to hash
7
- * @param prefix - A prefix to add to the beginning of the hash result
8
- * @param repeat - Number of times to repeat the hashing process for increased complexity (default: 3)
9
- * @returns A hashed string with the specified prefix
10
- */
11
- export declare function nanoHash(str: string | number, prefix: string, repeat?: number): string;
12
- //# sourceMappingURL=nano-hash.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"nano-hash.d.ts","sourceRoot":"","sources":["../src/nano-hash.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,SAAI,GAAG,MAAM,CA6BjF"}
@@ -1,72 +0,0 @@
1
- import {djb2Hash} from '@alwatr/hash-string';
2
-
3
- describe('djb2Hash', () => {
4
- it('should generate numeric hash values for string inputs', () => {
5
- const result = djb2Hash('test');
6
- expect(typeof result).toBe('number');
7
- expect(Number.isInteger(result)).toBe(true);
8
- });
9
-
10
- it('should return different hashes for different inputs', () => {
11
- const hash1 = djb2Hash('test1');
12
- const hash2 = djb2Hash('test2');
13
- expect(hash1).not.toBe(hash2);
14
- });
15
-
16
- it('should generate consistent hashes for the same input', () => {
17
- const input = 'consistencyTest';
18
- const hash1 = djb2Hash(input);
19
- const hash2 = djb2Hash(input);
20
- expect(hash1).toBe(hash2);
21
- });
22
-
23
- it('should handle empty strings', () => {
24
- const result = djb2Hash('');
25
- expect(typeof result).toBe('number');
26
- // The hash for an empty string should be the initial value right-shifted by 0
27
- expect(result).toBe(5381 >>> 0);
28
- });
29
-
30
- it('should handle special characters', () => {
31
- const result = djb2Hash('!@#$%^&*()');
32
- expect(typeof result).toBe('number');
33
- expect(Number.isInteger(result)).toBe(true);
34
- });
35
-
36
- it('should handle long strings', () => {
37
- const longString = 'a'.repeat(1000);
38
- const result = djb2Hash(longString);
39
- expect(typeof result).toBe('number');
40
- expect(Number.isInteger(result)).toBe(true);
41
- });
42
-
43
- it('should handle Unicode characters', () => {
44
- const unicodeString = '😀🌍🚀';
45
- const result = djb2Hash(unicodeString);
46
- expect(typeof result).toBe('number');
47
- expect(Number.isInteger(result)).toBe(true);
48
- });
49
-
50
- it('should produce 32-bit unsigned integer outputs', () => {
51
- const inputs = ['test', 'hello world', 'unicode 😀', 'a'.repeat(1000)];
52
-
53
- for (const input of inputs) {
54
- const result = djb2Hash(input);
55
- expect(result).toBeLessThanOrEqual(0xffffffff); // Max 32-bit unsigned int
56
- expect(result).toBeGreaterThanOrEqual(0);
57
- }
58
- });
59
-
60
- it('should produce deterministic results', () => {
61
- // Test with known hash values
62
- expect(djb2Hash('hello')).toBe(181380007);
63
- expect(djb2Hash('world')).toBe(164394279);
64
- expect(djb2Hash('hello world')).toBe(2616892229);
65
- expect(djb2Hash('')).toBe(5381);
66
- });
67
-
68
- it('should handle case sensitivity', () => {
69
- expect(djb2Hash('Hello')).not.toBe(djb2Hash('hello'));
70
- expect(djb2Hash('WORLD')).not.toBe(djb2Hash('world'));
71
- });
72
- });
File without changes