mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
utils: String.random with dict
This commit is contained in:
1 parent
387bd5eb38
commit
e2c5e57e53
3 files changed
+5
-4
No files matched your search
@@ -7,6 +7,7 @@ export interface LangConfig {
|
|||||||
highlight: string;
|
highlight: string;
|
||||||
monaco: string;
|
monaco: string;
|
||||||
time_limit_rate: number;
|
time_limit_rate: number;
|
||||||
|
domain: string[];
|
||||||
display: string;
|
display: string;
|
||||||
target?: string;
|
target?: string;
|
||||||
sub?: LangConfig[];
|
sub?: LangConfig[];
|
||||||
|
|||||||
@@ -31,11 +31,11 @@ declare global {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const dict = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890';
|
const defaultDict = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890';
|
||||||
|
|
||||||
String.random = function random(digit = 32) {
|
String.random = function random(digit = 32, dict = defaultDict) {
|
||||||
let str = '';
|
let str = '';
|
||||||
for (let i = 1; i <= digit; i++) str += dict[Math.floor(Math.random() * 62)];
|
for (let i = 1; i <= digit; i++) str += dict[Math.floor(Math.random() * dict.length)];
|
||||||
return str;
|
return str;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@hydrooj/utils",
|
"name": "@hydrooj/utils",
|
||||||
"version": "1.0.21",
|
"version": "1.0.22",
|
||||||
"description": "hydrooj utils",
|
"description": "hydrooj utils",
|
||||||
"main": "package.json",
|
"main": "package.json",
|
||||||
"repository": "https://github.com/hydro-dev/Hydro.git",
|
"repository": "https://github.com/hydro-dev/Hydro.git",
|
||||||
|
|||||||
Reference in new issue
Block a user