All files / src/utils hash.ts

100% Statements 20/20
83.33% Branches 5/6
100% Functions 3/3
100% Lines 20/20

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 211x 19x 19x 19x 288x 288x 19x 19x 1x 1x 14x 14x 14x 14x 1x 1x 5x 5x 5x 5x  
export function hashString(str: string): number {
  let hash = 5381;
  let i = str.length;
  while (i) {
    hash = (hash * 33) ^ str.charCodeAt(--i);
  }
  return hash >>> 0;
}
 
export function md5(str: string): string {
  // 使用 hashString 替代不安全的 md5
  // 用于非加密场景(ID生成、指纹计算)
  return hashString(str).toString(16);
}
 
export function computeFingerprint(type: string, message: string, frames: { filename: string; lineno?: number }[] = []): string {
  const keyFrames = frames.slice(0, 3).map(f => `${f.filename}:${f.lineno || 0}`).join('|');
  const normalizedMessage = message.replace(/['"]?\d+['"]?/g, '').replace(/\s+/g, ' ').trim();
  return md5(`${type}:${normalizedMessage}:${keyFrames}`);
}