ruoyi-geek-App/src/utils/geek.ts

76 lines
1.7 KiB
TypeScript
Raw Normal View History

/**
*
* @param {*} str
* @param {*} pattern *?
* @returns
*/
export function wildcardCompare(str: string, pattern: string): boolean {
const regex = pattern.replace(/[*?]/g, (match) => {
if (match === '*') {
return '.*';
} else if (match === '?') {
return '.';
} else {
return match
}
});
const regexPattern = new RegExp('^' + regex + '$');
return regexPattern.test(str);
}
2023-08-27 11:38:56 +00:00
/**
*
* @param obj
* @returns
*/
export function deepClone(obj: any) {
if (obj == null || typeof obj !== 'object') {
return obj;
}
let result;
if (Array.isArray(obj)) {
result = [];
} else {
result = new Map();
}
for (let [key, value] of Object.entries(obj)) {
// @ts-ignore
result[key] = deepClone(value);
}
return result;
2023-08-28 10:21:55 +00:00
}
/**
*
* @param obj
* @param result
* @returns
*/
2023-08-28 15:36:12 +00:00
export function deepCloneTo<T>(obj: T, result: T) {
2023-08-28 10:21:55 +00:00
if (obj == null || typeof obj !== 'object') {
return obj;
}
for (let [key, value] of Object.entries(obj)) {
// @ts-ignore
result[key] = deepClone(value);
}
return result;
2023-09-12 17:32:10 +00:00
}
/**
* uuid
* @returns uuid字符串
*/
export function generateUUID(): string {
let uuid = '';
const chars = '0123456789abcdef';
for (let i = 0; i < 32; i++) {
if (i === 8 || i === 12 || i === 16 || i === 20) {
uuid += '-';
}
uuid += chars[Math.floor(Math.random() * chars.length)];
}
return uuid;
}