Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function formatAsUuid(uuid, filler = '0') {
const parts = padEnd(uuid, 32, filler).match(/\w{4}/g);
if (!parts || parts.length !== 8) throw new Error('Invalid UUID');
const [p1, p2, p3, p4, p5, p6, p7, p8] = parts;
return `${p1}${p2}-${p3}-${p4}-${p5}-${p6}${p7}${p8}`;
}