@yoooloo42/bean 1.0.11 → 1.0.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/utils/random.js +24 -1
package/package.json
CHANGED
package/src/utils/random.js
CHANGED
|
@@ -81,9 +81,32 @@ function vercode6(length = 6) {
|
|
|
81
81
|
return result;
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
+
/**
|
|
85
|
+
* 随机生成一个固定 6 位长度、只包含数字的验证码字符串。
|
|
86
|
+
* @returns {string} - 随机生成的 6 位验证码字符串。
|
|
87
|
+
*/
|
|
88
|
+
function vercode6N(length = 6) {
|
|
89
|
+
// 定义所有允许的字符集 (数字 0-9, 小写字母 a-z, 大写字母 A-Z)
|
|
90
|
+
const characters = '0123456789';
|
|
91
|
+
const charactersLength = characters.length;
|
|
92
|
+
|
|
93
|
+
let result = '';
|
|
94
|
+
// 循环 6 次,每次随机从 characters 中选择一个字符
|
|
95
|
+
for (let i = 0; i < length; i++) {
|
|
96
|
+
// 随机选择字符的索引
|
|
97
|
+
const randomIndex = Math.floor(Math.random() * charactersLength);
|
|
98
|
+
|
|
99
|
+
// 将随机选中的字符添加到结果字符串中
|
|
100
|
+
result += characters.charAt(randomIndex);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return result;
|
|
104
|
+
}
|
|
105
|
+
|
|
84
106
|
const bean = {
|
|
85
107
|
random,
|
|
86
108
|
vercode,
|
|
87
|
-
vercode6
|
|
109
|
+
vercode6,
|
|
110
|
+
vercode6N
|
|
88
111
|
}
|
|
89
112
|
export default bean
|