We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent ec947ca commit 307a0c0Copy full SHA for 307a0c0
helpers/unique-id.js
@@ -1,18 +1,8 @@
1
/* eslint unicorn/prefer-module: 0, eqeqeq: 0 */
2
module.exports = function (Handlebars) {
3
Handlebars.registerHelper('unique-id', function () {
4
- // Adapted from https://www.codingdeft.com/posts/generate-uuid-javascript/
5
const crypto = require('node:crypto');
6
7
- const buf = crypto.randomBytes(16);
8
-
9
- // Convert the buffer to a hexadecimal string
10
- const hex = buf.toString('hex');
11
12
- // Return the hexadecimal string as a UUID
13
- return `id-${hex.slice(
14
- 0,
15
- 7
16
- )}-${hex.slice(8, 15)}-${hex.slice(16, 23)}-${hex.slice(24, 31)}`;
+ return `id-${crypto.randomUUID()}`;
17
});
18
};
0 commit comments