-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcreate.js
More file actions
77 lines (70 loc) · 1.81 KB
/
create.js
File metadata and controls
77 lines (70 loc) · 1.81 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import Modes from './config';
import Transform from './tranform';
//create 26 letters
function createLetters () {
let lettersUpper = []
let lettersLower = []
for (let i = 0; i < 26; i++) {
lettersUpper.push(String.fromCharCode(65+i))
lettersLower.push(String.fromCharCode(97+i))
}
return [
...lettersLower,
...lettersUpper
];
}
//create verification code
function randomCode(mode, length) {
const code = [];
if (
mode === Modes[0]
) { //letter
const letters = createLetters();
for(let i = 0; i < length; i++) {
let index = Math.floor(Math.random() * letters.length);
code.push(letters[index]);
}
} else if (
mode === Modes[1]
) { //number
const _number = new Array(10).fill(1).map((v, k) => k);
for(let i = 0; i < length; i++) {
let index = Math.floor(Math.random() * _number.length);
code.push(_number[index]);
}
}
return code;
}
//random text color
function randomTextColor() {
const r = parseInt(Math.random() * 256);
const g = parseInt(Math.random() * 256);
const b = parseInt(Math.random() * 256);
return {
color: `rgb(${r},${g},${b})`
}
}
//create text style
function createTextStyle() {
let index = Math.floor(Math.random() * Transform.length);
let color = arguments[0] ? randomTextColor() : null;
return {
...color,
transform: [Transform[index]]
}
}
//create container style
function createContainerStyle() {
const bgColor = arguments[0] ?
new Array(
randomTextColor().color,
randomTextColor().color,
randomTextColor().color
) : ['#fff','#ddd','#000']
return bgColor;
}
export default {
randomCode,
createTextStyle,
createContainerStyle
}