mirror of
https://github.com/snapotter-hq/SnapOtter.git
synced 2026-08-03 07:46:42 +02:00
14 lines
427 B
JavaScript
14 lines
427 B
JavaScript
// scripts/i18n/lib/hash.mjs
|
|||
|
|
import { createHash } from "node:crypto";
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Stable 12-char hex hash of a source string.
|
||
|
|
* CRLF is normalized to LF so line-ending changes never trigger re-translation.
|
||
|
|
* @param {string} text
|
||
|
|
* @returns {string}
|
||
|
|
*/
|
||
|
|
export function hash(text) {
|
||
|
|
const normalized = String(text).replace(/\r\n/g, "\n");
|
||
|
|
return createHash("sha256").update(normalized, "utf8").digest("hex").slice(0, 12);
|
||
|
|
}
|