You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
vue-webtopo-svgeditor/src/utils/index.ts

20 lines
559 B
TypeScript

/**
*
* @param len
*/
export const randomString = (len?: number) => {
len = len || 10;
const str = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
const maxPos = str.length;
let random_str = '';
for (let i = 0; i < len; i++) {
random_str += str.charAt(Math.floor(Math.random() * maxPos));
}
return random_str;
};
// 通过泛型定义通用类型保护函数
export const isOfType = <T>(target: unknown, prop: keyof T): target is T => {
return (target as T)[prop] !== undefined;
};