(text: string)
| 1 | // Lightweight content hashing suitable for change detection (not cryptographic) |
| 2 | export function computeContentHash(text: string): string { |
| 3 | // djb2 |
| 4 | let hash = 5381 |
| 5 | const len = text.length |
| 6 | for (let i = 0; i < len; i += 1) { |
| 7 | hash = (hash << 5) + hash + text.charCodeAt(i) |
| 8 | hash |= 0 // force 32-bit |
| 9 | } |
| 10 | // convert to unsigned hex |
| 11 | const u = hash >>> 0 |
| 12 | return u.toString(16).padStart(8, '0') |
| 13 | } |
| 14 | |
| 15 | export type FileHashes = Record<string, string> |
| 16 |
no test coverage detected