(str: string)
| 206 | * https://github.com/google/closure-compiler/blob/master/src/com/google/javascript/jscomp/GoogleJsMessageIdGenerator.java |
| 207 | */ |
| 208 | export function fingerprint(str: string): bigint { |
| 209 | textEncoder ??= new TextEncoder(); |
| 210 | const utf8 = textEncoder.encode(str); |
| 211 | const view = new DataView(utf8.buffer, utf8.byteOffset, utf8.byteLength); |
| 212 | |
| 213 | let hi = hash32(view, utf8.length, 0); |
| 214 | let lo = hash32(view, utf8.length, 102072); |
| 215 | |
| 216 | if (hi == 0 && (lo == 0 || lo == 1)) { |
| 217 | hi = hi ^ 0x130f9bef; |
| 218 | lo = lo ^ -0x6b5f56d8; |
| 219 | } |
| 220 | |
| 221 | return (BigInt.asUintN(32, BigInt(hi)) << BigInt(32)) | BigInt.asUintN(32, BigInt(lo)); |
| 222 | } |
| 223 | |
| 224 | export function computeMsgId(msg: string, meaning: string = ''): string { |
| 225 | let msgFingerprint = fingerprint(msg); |
no test coverage detected
searching dependent graphs…