Project Files
dist / utils / text.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.normalizeWhitespace = normalizeWhitespace;
exports.truncate = truncate;
exports.stableHash = stableHash;
function normalizeWhitespace(text) {
return text.replace(/\s+/g, " ").trim();
}
function truncate(text, maxChars) {
if (text.length <= maxChars)
return text;
return text.slice(0, Math.max(0, maxChars - 1)).trimEnd() + "…";
}
function stableHash(input) {
let hash = 2166136261;
for (let i = 0; i < input.length; i++) {
hash ^= input.charCodeAt(i);
hash = Math.imul(hash, 16777619);
}
return (hash >>> 0).toString(16);
}