mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-19 17:38:19 +08:00
replace String.random with randomstring
This commit is contained in:
22 files changed
+64
-48
No files matched your search
@@ -1,15 +1,9 @@
|
||||
declare global {
|
||||
interface StringConstructor {
|
||||
random: (digit?: number, dict?: string) => string;
|
||||
}
|
||||
interface String {
|
||||
format: (...args: Array<any>) => string;
|
||||
formatFromArray: (args: any[]) => string;
|
||||
rawformat: (object: any) => string;
|
||||
}
|
||||
interface ArrayConstructor {
|
||||
isDiff: (a: any[], b: any[]) => boolean;
|
||||
}
|
||||
interface Math {
|
||||
sum: (...args: Array<number[] | number>) => number;
|
||||
}
|
||||
@@ -28,6 +22,7 @@ export function randomstring(digit = 32, dict = defaultDict) {
|
||||
return str;
|
||||
}
|
||||
try {
|
||||
// @ts-ignore
|
||||
String.random = randomstring;
|
||||
} catch (e) { } // Cannot add property random, object is not extensible
|
||||
|
||||
@@ -63,7 +58,7 @@ String.prototype.rawformat = function rawFormat(object) {
|
||||
return [res[0], object, res[1]].join();
|
||||
};
|
||||
|
||||
Array.isDiff = function isDiff(a, b) {
|
||||
export function diffArray(a, b) {
|
||||
if (a.length !== b.length) return true;
|
||||
a.sort();
|
||||
b.sort();
|
||||
@@ -71,7 +66,12 @@ Array.isDiff = function isDiff(a, b) {
|
||||
if (a[i] !== b[i]) return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
}
|
||||
|
||||
try {
|
||||
// @ts-ignore
|
||||
Array.isDiff = diffArray;
|
||||
} catch (e) { } // Cannot add property isDiff, object is not extensible
|
||||
|
||||
// @ts-ignore
|
||||
Date.prototype.format = function formatDate(fmt = '%Y-%m-%d %H:%M:%S') {
|
||||
|
||||
Reference in new issue
Block a user