-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
24 lines (19 loc) · 1.11 KB
/
index.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
import string from '@/string';
/**
* 生成不连续的随机字符串,即连续两次生成的随机字符串100%不相同 (Generate random numbers that are not consecutive, that is, the random numbers generated twice are 100% different)
* @param {number} [length = 10] 随机字符串的长度 (Length of random string)
* @param {string} [typeString = '*'] 表示字符类型的字符串,默认为所有类型;*=所有 a=小写字母 A=大写字母 0=数字 !=特殊字符 `~!@#$%^&*()_+-={}[]|;:\`'",.<>?` (String representing character type, default is all types; *=all a=lower case A=upper case 0=numbers !=special`~!@#$%^&*()_+-={}[]|;:\`'",.<>?`)
* @returns {() => string} 生成不连续的随机字符串的函数 (Function that generates random numbers that are not consecutive)
*/
const nonConsecutiveFn = (length: number = 10, typeString: string = '*'): (() => string) => {
let previousValue: string;
return () => {
let str: string;
do {
str = string(length, typeString);
} while (str === previousValue);
previousValue = str;
return str;
};
};
export default nonConsecutiveFn;