-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
35 lines (30 loc) · 842 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
const generateGuid = function (brackets) {
const sizes = [8, 4, 4, 4, 12]
const possible = 'ABCDEF0123456789'
let guid = ''
sizes.forEach((size, index) => {
if (index !== 0) {
guid += '-'
}
for (let i = 0; i < size; i++) {
guid += possible[Math.floor(Math.random() * 16)]
}
})
return brackets === true ? `{${guid}}` : guid
}
const generateMultipleGuids = function (numGuids, brackets) {
const guids = []
for (let i = 0; i < numGuids; i++) {
guids.push(generateGuid(brackets))
}
return guids
}
const emptyGuid = function (brackets) {
let emptyGuid = '00000000-0000-0000-0000-000000000000'
return brackets === true ? `{${emptyGuid}}` : emptyGuid
}
module.exports = {
generateGuid,
generateMultipleGuids,
emptyGuid
}