2026-02-20 11:07:42 +09:00
|
|
|
import { HASHLINE_DICT } from "./constants"
|
2026-02-16 15:59:12 +09:00
|
|
|
|
2026-02-19 18:19:16 +09:00
|
|
|
export function computeLineHash(lineNumber: number, content: string): string {
|
2026-02-20 11:07:42 +09:00
|
|
|
void lineNumber
|
2026-02-16 15:59:12 +09:00
|
|
|
const stripped = content.replace(/\s+/g, "")
|
2026-02-20 11:07:42 +09:00
|
|
|
const hash = Bun.hash.xxHash32(stripped)
|
2026-02-16 15:59:12 +09:00
|
|
|
const index = hash % 256
|
2026-02-20 11:07:42 +09:00
|
|
|
return HASHLINE_DICT[index]
|
2026-02-16 15:59:12 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function formatHashLine(lineNumber: number, content: string): string {
|
|
|
|
|
const hash = computeLineHash(lineNumber, content)
|
2026-02-20 11:07:42 +09:00
|
|
|
return `${lineNumber}#${hash}:${content}`
|
2026-02-16 15:59:12 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function formatHashLines(content: string): string {
|
|
|
|
|
if (!content) return ""
|
|
|
|
|
const lines = content.split("\n")
|
|
|
|
|
return lines.map((line, index) => formatHashLine(index + 1, line)).join("\n")
|
|
|
|
|
}
|