@alwatr/hash-string 5.2.17 โ 5.2.18
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/main.cjs +2 -2
- package/dist/main.mjs +2 -2
- package/package.json +7 -6
- package/src/main.test.js +0 -101
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.18](https://github.com/Alwatr/nanolib/compare/@alwatr/hash-string@5.2.17...@alwatr/hash-string@5.2.18) (2025-09-27)
|
|
7
|
+
|
|
8
|
+
### ๐งน Miscellaneous Chores
|
|
9
|
+
|
|
10
|
+
* exclude test files from package distribution ([86f4f2f](https://github.com/Alwatr/nanolib/commit/86f4f2f5985845c5cf3a3a9398de7b2f98ce53e7))
|
|
11
|
+
|
|
6
12
|
## [5.2.17](https://github.com/Alwatr/nanolib/compare/@alwatr/hash-string@5.2.16...@alwatr/hash-string@5.2.17) (2025-09-22)
|
|
7
13
|
|
|
8
14
|
**Note:** Version bump only for package @alwatr/hash-string
|
package/dist/main.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** ๐ฆ @alwatr/hash-string v5.2.
|
|
2
|
-
__dev_mode__: console.debug("๐ฆ @alwatr/hash-string v5.2.
|
|
1
|
+
/** ๐ฆ @alwatr/hash-string v5.2.18 */
|
|
2
|
+
__dev_mode__: console.debug("๐ฆ @alwatr/hash-string v5.2.18");
|
|
3
3
|
"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});
|
|
4
4
|
//# sourceMappingURL=main.cjs.map
|
package/dist/main.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** ๐ฆ @alwatr/hash-string v5.2.
|
|
2
|
-
__dev_mode__: console.debug("๐ฆ @alwatr/hash-string v5.2.
|
|
1
|
+
/** ๐ฆ @alwatr/hash-string v5.2.18 */
|
|
2
|
+
__dev_mode__: console.debug("๐ฆ @alwatr/hash-string v5.2.18");
|
|
3
3
|
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};
|
|
4
4
|
//# sourceMappingURL=main.mjs.map
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
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.18",
|
|
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.3.
|
|
9
|
-
"@alwatr/prettier-config": "5.0.
|
|
10
|
-
"@alwatr/tsconfig-base": "6.0.
|
|
8
|
+
"@alwatr/nano-build": "6.3.4",
|
|
9
|
+
"@alwatr/prettier-config": "5.0.5",
|
|
10
|
+
"@alwatr/tsconfig-base": "6.0.3",
|
|
11
11
|
"jest": "^30.1.3",
|
|
12
12
|
"typescript": "^5.9.2"
|
|
13
13
|
},
|
|
@@ -21,7 +21,8 @@
|
|
|
21
21
|
"files": [
|
|
22
22
|
"**/*.{js,mjs,cjs,map,d.ts,html,md,LEGAL.txt}",
|
|
23
23
|
"LICENSE",
|
|
24
|
-
"!demo/**/*"
|
|
24
|
+
"!demo/**/*",
|
|
25
|
+
"!**/*.test.js"
|
|
25
26
|
],
|
|
26
27
|
"homepage": "https://github.com/Alwatr/nanolib/tree/next/packages/hash-string#readme",
|
|
27
28
|
"keywords": [
|
|
@@ -73,5 +74,5 @@
|
|
|
73
74
|
"sideEffects": false,
|
|
74
75
|
"type": "module",
|
|
75
76
|
"types": "./dist/main.d.ts",
|
|
76
|
-
"gitHead": "
|
|
77
|
+
"gitHead": "c013ded43aff3937cf347de4e99125ab807d99e1"
|
|
77
78
|
}
|
package/src/main.test.js
DELETED
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
import {nanoHash} from '@alwatr/hash-string';
|
|
2
|
-
|
|
3
|
-
describe('hashString', () => {
|
|
4
|
-
it('should generate hash for string inputs', () => {
|
|
5
|
-
const result = nanoHash('test', 'prefix-');
|
|
6
|
-
expect(typeof result).toBe('string');
|
|
7
|
-
expect(result.startsWith('prefix-')).toBe(true);
|
|
8
|
-
expect(result).not.toBe('prefix-test');
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
it('should generate hash for numeric inputs', () => {
|
|
12
|
-
const result = nanoHash(12345, 'num-');
|
|
13
|
-
expect(typeof result).toBe('string');
|
|
14
|
-
expect(result.startsWith('num-')).toBe(true);
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
it('should return different hashes for different inputs', () => {
|
|
18
|
-
const hash1 = nanoHash('test1', 'p-');
|
|
19
|
-
const hash2 = nanoHash('test2', 'p-');
|
|
20
|
-
expect(hash1).not.toBe(hash2);
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
it('should use the provided prefix', () => {
|
|
24
|
-
const prefixes = ['a-', 'test-', 'hash_', '123-'];
|
|
25
|
-
|
|
26
|
-
prefixes.forEach((prefix) => {
|
|
27
|
-
const result = nanoHash('sameInput', prefix);
|
|
28
|
-
expect(result.startsWith(prefix)).toBe(true);
|
|
29
|
-
});
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
it('should generate different hashes with different repeat values', () => {
|
|
33
|
-
const input = 'repeatTest';
|
|
34
|
-
const prefix = 'r-';
|
|
35
|
-
|
|
36
|
-
const hash1 = nanoHash(input, prefix, 1);
|
|
37
|
-
const hash2 = nanoHash(input, prefix, 2);
|
|
38
|
-
const hash3 = nanoHash(input, prefix, 3);
|
|
39
|
-
|
|
40
|
-
expect(hash1).not.toBe(hash2);
|
|
41
|
-
expect(hash2).not.toBe(hash3);
|
|
42
|
-
expect(hash1).not.toBe(hash3);
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
it('should handle empty strings', () => {
|
|
46
|
-
const result = nanoHash('', 'empty-');
|
|
47
|
-
expect(typeof result).toBe('string');
|
|
48
|
-
expect(result.startsWith('empty-')).toBe(true);
|
|
49
|
-
expect(result.length).toBeGreaterThan('empty-'.length);
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
it('should handle special characters', () => {
|
|
53
|
-
const result = nanoHash('!@#$%^&*()', 'special-');
|
|
54
|
-
expect(typeof result).toBe('string');
|
|
55
|
-
expect(result.startsWith('special-')).toBe(true);
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
it('should generate consistent hashes for the same input', () => {
|
|
59
|
-
const input = 'consistencyTest';
|
|
60
|
-
const prefix = 'c-';
|
|
61
|
-
|
|
62
|
-
const hash1 = nanoHash(input, prefix);
|
|
63
|
-
const hash2 = nanoHash(input, prefix);
|
|
64
|
-
|
|
65
|
-
expect(hash1).toBe(hash2);
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
it('should handle long strings', () => {
|
|
69
|
-
const longString = 'a'.repeat(1000);
|
|
70
|
-
const result = nanoHash(longString, 'long-');
|
|
71
|
-
|
|
72
|
-
expect(typeof result).toBe('string');
|
|
73
|
-
expect(result.startsWith('long-')).toBe(true);
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
it('should handle Unicode characters', () => {
|
|
77
|
-
const unicodeString = '๐๐๐';
|
|
78
|
-
const result = nanoHash(unicodeString, 'unicode-');
|
|
79
|
-
|
|
80
|
-
expect(typeof result).toBe('string');
|
|
81
|
-
expect(result.startsWith('unicode-')).toBe(true);
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
it('should default to repeat value of 1 when not specified', () => {
|
|
85
|
-
const input = 'defaultRepeat';
|
|
86
|
-
const prefix = 'd-';
|
|
87
|
-
|
|
88
|
-
const defaultResult = nanoHash(input, prefix);
|
|
89
|
-
const explicitResult = nanoHash(input, prefix, 1);
|
|
90
|
-
|
|
91
|
-
expect(defaultResult).toBe(explicitResult);
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
it('should algorithm be deterministic', () => {
|
|
95
|
-
const input = 'Ali@MD_65';
|
|
96
|
-
const prefix = 'p-';
|
|
97
|
-
const expectedHash = 'p-dm3wzfp6jiud';
|
|
98
|
-
const hash = nanoHash(input, prefix, 3);
|
|
99
|
-
expect(hash).toBe(expectedHash);
|
|
100
|
-
});
|
|
101
|
-
});
|