moh-hasher 1.0.0 → 1.0.1

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.
Files changed (2) hide show
  1. package/index.js +11 -2
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -36,9 +36,18 @@ export function hash(secret) {
36
36
  // Unhasher (decode)
37
37
  export function unhash(encodedSecret) {
38
38
  let decoded = '';
39
+ let temp = ''; // Temporary storage for matching encoded sequence
39
40
  for (let i = 0; i < encodedSecret.length; i++) {
40
- const char = encodedSecret[i];
41
- decoded += decodeMap[char] || char; // Default to the char if not found in the map
41
+ temp += encodedSecret[i];
42
+ // Check if the temp sequence exists in the decodeMap
43
+ if (decodeMap[temp]) {
44
+ decoded += decodeMap[temp];
45
+ temp = ''; // Reset temp once a valid match is found
46
+ }
47
+ }
48
+ // If there's any leftover temp data that couldn't be decoded, append it
49
+ if (temp) {
50
+ decoded += temp;
42
51
  }
43
52
  return decoded;
44
53
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "moh-hasher",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "A simple encoding and decoding package with unique hashes",
5
5
  "main": "index.js",
6
6
  "type": "module",