Skip to content

Commit 307a0c0

Browse files
committed
refactor: simplified that functionality
1 parent ec947ca commit 307a0c0

File tree

1 file changed

+1
-11
lines changed

1 file changed

+1
-11
lines changed

helpers/unique-id.js

+1-11
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,8 @@
11
/* eslint unicorn/prefer-module: 0, eqeqeq: 0 */
22
module.exports = function (Handlebars) {
33
Handlebars.registerHelper('unique-id', function () {
4-
// Adapted from https://www.codingdeft.com/posts/generate-uuid-javascript/
54
const crypto = require('node:crypto');
65

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)}`;
6+
return `id-${crypto.randomUUID()}`;
177
});
188
};

0 commit comments

Comments
 (0)