-
-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathutils.ts
32 lines (30 loc) · 961 Bytes
/
utils.ts
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
const getRandomInteger = (min: number, max: number) => {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
export const formattedOreoStr = (keyList: OreoKey[], translation: (key: string, count?: number) => string) => {
if (!keyList.length) {
return translation('input.placeholder')
}
const keyDict = {
o: 'basic.o',
r: 'basic.r',
'-': 'basic.and',
}
return keyList.map((item, index) => translation(keyDict[item], index + 1)).join('')
}
export const generateRandomOreoKey = () => {
let randomInputList: OreoKey[] = []
const typeCount = getRandomInteger(3, 5)
for (let i = 0; i < typeCount; i++) {
const random = Math.random() * 5
let str: OreoKey = i === 0 ? 'o' : '-'
if (random < 2) {
str = 'o'
} else if (random < 4) {
str = 'r'
}
const cliceCount = getRandomInteger(1, 4)
randomInputList = randomInputList.concat(Array(cliceCount).fill(str))
}
return randomInputList
}