MCPcopy Index your code
hub / github.com/getsentry/sentry-javascript / stringToUUID

Function stringToUUID

packages/bundler-plugins/src/core/utils.ts:179–187  ·  view source on GitHub ↗
(str: string)

Source from the content-addressed store, hash-verified

177 * Deterministically hashes a string and turns the hash into a uuid.
178 */
179export function stringToUUID(str: string): string {
180 const sha256Hash = crypto.createHash('sha256').update(str).digest('hex');
181
182 // Position 16 is fixed to either 8, 9, a, or b in the uuid v4 spec (10xx in binary)
183 // RFC 4122 section 4.4
184 const v4variant = ['8', '9', 'a', 'b'][sha256Hash.substring(16, 17).charCodeAt(0) % 4] as string;
185
186 return `${sha256Hash.substring(0, 8)}-${sha256Hash.substring(8, 12)}-4${sha256Hash.substring(13, 16)}-${v4variant}${sha256Hash.substring(17, 20)}-${sha256Hash.substring(20, 32)}`.toLowerCase();
187}
188
189function gitRevision(): string | undefined {
190 let gitRevision: string | undefined;

Callers 3

utils.test.tsFile · 0.90
renderChunkFunction · 0.90
applyFunction · 0.85

Calls 2

digestMethod · 0.80
updateMethod · 0.45

Tested by

no test coverage detected